Run Weka classifiers: NaiveBayes, MLP, SMO, RandomForest,etc
Code: "weka_run_classifires.py". Programming language: Python DMelt Version 2.29. Last modified: 03/03/2021. License: Pro
https://datamelt.org/code/cache/weka_run_classifires_7823.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.


import java.io.FileReader as FileReader
import weka.core.Instances as Instances
import weka.classifiers.Evaluation as Evaluation
import weka.classifiers.bayes.NaiveBayes as NaiveBayes
import weka.classifiers.bayes.BayesNet as BayesNet
import weka.classifiers.functions.MultilayerPerceptron as MLP
import weka.classifiers.functions.SMO as SMO
import weka.classifiers.trees.J48 as J48
import weka.classifiers.trees.RandomForest as RandomForest
import weka.classifiers.rules.JRip as JRip
import weka.classifiers.lazy.KStar as KStar

from jhplot import Web
xf="iris.arff"
url="https://datamelt.org/examples/data/weka/"+xf 
print "Loading ",xf
print Web.get(url)

ifile = FileReader(xf)
data = Instances(ifile)
data.setClassIndex(data.numAttributes() - 1)

# define classifies
algo_list = [(NaiveBayes(), 'NaiveBayes'), (BayesNet(),'BayesNet'), (J48(),'J48'), (JRip(), 'JRip'),
            (KStar(), 'KStar'), (RandomForest(), 'RandomForest'), (SMO(),'SMO'), (MLP(),'MLP')]

algo_dict = dict([(x[1], x[0]) for x in algo_list])
all_algo_keys = ['NaiveBayes', 'J48', 'BayesNet', 'JRip', 'RandomForest', 'KStar', 'SMO', 'MLP']

print "Run all WEKA classifiers.." 
for key in all_algo_keys:
      print "####  Running "+key
      algo = algo_dict[key]
      algo.buildClassifier(data)
      print(algo)



You see the box below because you did not login.