Exemplo n.º 1
0
def initExperiment(_args):
	FileHandler().createFolder("results")

	resultFolder = "results/" + args.name + "/"
	FileHandler().createFolder(resultFolder)
	resultFile = resultFolder + "result.csv"	

	if _args.classification:
		e = Experiment(args.classification, args.name)
		models = initModels(_args, Type.CLASSIFICATION)
		e.classification(models, 10)

		if _args.gen_code:
			exportCode(_args, resultFolder, _args.classification, models)

		if _args.visualize:
			files = [e.path("cv_" + str(i) + ".csv") for i in range(len(models))] 
			xTicks = [model.modelName for model in models]
			ResultVisualizer().boxplots(files, _args.visualize, xTicks,  ylabel=_args.visualize)

	elif _args.correlation:
		csv = CSV()
		csv.load(args.correlation)
		csv.computeCorrelationMatrix(resultFile)

		if _args.visualize:
			ResultVisualizer().colorMap(resultFile)

	elif _args.regression:
		e = Experiment(args.regression, args.name)
		models = initModels(_args, Type.REGRESSION)
		e.regression(models, 10)

		if _args.gen_code:
			exportCode(_args, resultFolder, _args.regression, models)

		if _args.visualize:
			files = [e.path("cv_" + str(i) + ".csv") for i in range(len(models))] 
			xTicks = [model.modelName for model in models]
			ResultVisualizer().boxplots(files, _args.visualize, xTicks,  ylabel=_args.visualize)

	print("[LIMITS]: results written to src/" + resultFolder)
Exemplo n.º 2
0
def classificationANN(_training, _layers, _nodes, _file):
    e = Experiment(_training, verbose=False)

    R = ResultMatrix()
    for numLayers in range(1, _layers + 1):
        for numNodes in range(1, _nodes + 1):
            ann = ANN()
            ann.config.hiddenLayers = []
            for i in range(numLayers):
                ann.config.hiddenLayers.append(numNodes)

            header, result = e.classification([ann], 10)
            mem = computeMemorySize(_training, ann, False)
            header += ["arduino", "msp", "esp"]
            result = np.hstack([result, mem])

            print([
                "#layers=" + str(numLayers) + "/" + str(_layers) + " nodes=" +
                str(numNodes) + "/" + str(_nodes) + ' mem=', mem
            ],
                  flush=True)

            R.add(header, result)
    R.save(_file)
Exemplo n.º 3
0
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/