def regressionRF(_training, _trees, _depth, _file, _resultFolder, _discretization): csv = CSV(training) attributes = csv.findAttributes(0) R = ResultMatrix() for numTrees in range(1, _trees + 1): for depth in range(1, _depth + 1): rf = RandomForest() rf.config.trees = numTrees rf.config.depth = depth # perform a cross validation to generate the training/test files e = Experiment(_training, "example_rf_sweet_spot_disc", verbose=False) e.regression([rf], 10) # r, c = CodeEvaluator().crossValidation(rf, _training, attributes, e.tmp(), _discretization) result = np.hstack([r.data.mean(0), r.data.std(0)]) header = r.header + [x + "_std" for x in r.header] mem = computeMemorySize(_training, rf, _resultFolder, _discretization) header += ["arduino", "msp", "esp"] result = np.hstack([result, mem]) print([ "#trees=" + str(numTrees) + "/" + str(_trees) + " depth=" + str(depth) + "/" + str(_depth) + ' mem=', mem ], flush=True) R.add(header, result) R.save(_file)
from plot.ResultVisualizer import ResultVisualizer # define the training data set and set up the model training = "../examples/mnoA.csv" model = ANN() # perform a 10-fold cross validation e = Experiment(training, "example_ann_feature_importance") e.regression([model], 10) # M = ResultMatrix() csv = CSV(training) attributes = csv.findAttributes(0) for i in range(10): training = e.tmp() + "training_mnoA_" + str(i) + ".csv" data = "\n".join(FileHandler().read(e.tmp() + "raw0_" + str(i) + ".txt")) ANN_WEKA(model).initModel(data, csv, attributes, training) M.add(csv.header[1:], model.computeInputLayerRanking()) M.normalizeRows() M.sortByMean() M.save(e.path("ann_features.csv")) # ResultVisualizer().barchart(e.path("ann_features.csv"), xlabel="Feature", ylabel="Relative Feature Importance", savePNG=e.path(e.id + ".png"))
from code.CodeGenerator import CodeGenerator from code.CodeEvaluator import CodeEvaluator from data.FileHandler import FileHandler from data.ResultMatrix import ResultMatrix # define the training data set and set up the model training = "../examples/mnoA.csv" model = RandomForest() model.config.trees = 10 model.config.depth = 10 csv = CSV(training) attributes = csv.findAttributes(0) # perform a 10-fold cross validation e = Experiment(training, "example_model_reapplication") e.regression([model], 10) # ce = CodeEvaluator() R, C = ce.crossValidation(model, training, attributes, e.tmp()) R.printAggregated() # ResultVisualizer().scatter( [e.tmp() + "predictions_" + str(i) + ".csv" for i in range(10)], "prediction", "label", xlabel='Predicted Data Rate [MBit/s]', ylabel='Measured Data Rate [MBit/s', savePNG=e.path("example_model_reapplication.png"))
from data.CSV import CSV # define the training data set and set up the model training = "../examples/mnoA.csv" training = "../examples/vehicleClassification.csv" csv = CSV(training) attributes = csv.findAttributes(0) d = csv.discretizeData() model = RandomForest() model.config.trees = 10 model.config.depth = 5 # perform a 10-fold cross validation e = Experiment(training, "example_rf_disc") e.classification([model], 10) # export the C++ code CodeGenerator().export(training, model, e.path("rf.cpp"), d) # ce = CodeEvaluator() R, C = ce.crossValidation(model, training, attributes, e.tmp(), d) R.printAggregated() # all results are written to results/example_rf_disc/
# define the training data set and set up the model training = "../examples/mnoA.csv" model = SVM() # perform a 10-fold cross validation e = Experiment(training, "example_svm_feature_importance") e.regression([model], 10) csv = CSV(training) attributes = csv.findAttributes(0) features = csv.header[1:] # for i in range(10): training = e.tmp() + "training_mnoA_" + str(i) + ".csv" data = "\n".join(FileHandler().read(e.tmp() + "raw0_" + str(i) + ".txt")) SVM_WEKA(model).initModel(data, csv, attributes, training) model.exportWeights(csv.header[1:], e.tmp() + "svm_features_" + str(i) + ".csv") # M = ResultMatrix() for i in range(10): csv = CSV(e.tmp() + "svm_features_" + str(i) + ".csv") D = csv.data[0].split(",") M.add(csv.header, np.array([abs(float(x)) for x in D])) M.normalizeRows() M.sortByMean()
from models.randomforest.RandomForest import RandomForest from weka.models.RandomForest import RandomForest as RandomForest_WEKA from experiment.Experiment import Experiment from data.CSV import CSV from code.CodeGenerator import CodeGenerator from data.FileHandler import FileHandler # define the training data set and set up the model training = "../examples/vehicleClassification.csv" model = RandomForest() model.config.depth = 7 # perform a 10-fold cross validation e = Experiment(training, "example_rf") e.classification([model], 10) # csv = CSV() csv.load(training) attributes = csv.findAttributes(0) data = "\n".join(FileHandler().read(e.tmp() + "raw0_0.txt")) RandomForest_WEKA(model).initModel(data, attributes) model.exportEps(model.depth+1, 10, 10, len(attributes)-1)