Ejemplo n.º 1
0
	def export(self, _training, _model, _out, _discretize=False):
		FileHandler().createFolder("tmp")
		tmpId = "_" + str(uuid.uuid1())
		tmpFolder = "tmp/"
		tmpTraining = "train" + tmpId + ".arff"

		csv = CSV(_training)
		csv.convertToARFF(tmpFolder + tmpTraining, False)		
		d = None
		if _discretize:
			d = csv.discretizeData()

		attributes = csv.findAttributes(0)


		weka = WEKA()
		weka.folder = tmpFolder
		weka.train(_model, tmpFolder + tmpTraining, tmpId)
		data = "\n".join(FileHandler().read(tmpFolder + "raw" + tmpId + ".txt"))

		FileHandler().checkFolder(_out)
		weka.modelInterface.exportCode(data, csv, attributes, _out, _training, discretization=d)

		FileHandler().deleteFiles([tmpFolder + tmpTraining, tmpFolder + "raw" + tmpId + ".txt"])
Ejemplo n.º 2
0
from models.randomforest.RandomForest import RandomForest
from experiment.Experiment import Experiment
from code.CodeGenerator import CodeGenerator
from code.CodeEvaluator import CodeEvaluator
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()