def knn_maker_algoritm(trainfolderpath): dataModel = get_data_from_folder(trainfolderpath) knnModel = classify(dataModel.trainFeat, dataModel.trainLabels) accKnnModel = getAccuracy(knnModel, dataModel.testFeat, dataModel.testLabels) print("KNNClassifier accuracy: {:.2f}%".format(accKnnModel * 100)) saveModel(knnModel)
def mlp_maker_algoritm(trainfolderpath): dataModel = get_data_from_folder(trainfolderpath) mlpModel = classify(dataModel.trainFeat, dataModel.trainLabels) accmlpModel = getAccuracy(mlpModel, dataModel.testFeat, dataModel.testLabels) print("MLP Classifier accuracy: {:.2f}%".format(accmlpModel * 100)) saveModel(mlpModel)
def random_forest_maker_algoritm(trainfolderpath): dataModel = get_data_from_folder(trainfolderpath) random_forestModel = classify(dataModel.trainFeat, dataModel.trainLabels) accModel = getAccuracy(random_forestModel, dataModel.testFeat, dataModel.testLabels) print("Random Forest Classifier accuracy: {:.2f}%".format(accModel * 100)) saveModel(random_forestModel)
def decision_tree_maker_algoritm(trainfolderpath): dataModel = get_data_from_folder(trainfolderpath) decisionTreeModel = classify(dataModel.trainFeat, dataModel.trainLabels) accDecitionTree = getAccuracy(decisionTreeModel, dataModel.testFeat, dataModel.testLabels) print("DecisionTreeClassifier accuracy: {:.2f}%".format(accDecitionTree * 100)) saveModel(decisionTreeModel)
def chooseClassifier(trainfolderpath): dataModel = get_data_from_folder(trainfolderpath) decisionTreeModel = dtc(dataModel.trainFeat, dataModel.trainLabels) knnModel = kc(dataModel.trainFeat, dataModel.trainLabels) accDecitionTree = getAccuracy(decisionTreeModel, dataModel.testFeat, dataModel.testLabels) accKnnModel = getAccuracy(knnModel, dataModel.testFeat, dataModel.testLabels) print("DecisionTreeClassifier accuracy: {:.2f}%".format(accDecitionTree * 100)) print("KNNClassifier accuracy: {:.2f}%".format(accKnnModel * 100)) acc = accDecitionTree if accKnnModel > acc: acc = accKnnModel print("Knn is saved") saveModel(knnModel) else: print("Decition tree is saved") saveModel(decisionTreeModel) return acc
def logistic_regression_maker_algoritm(trainfolderpath): dataModel = get_data_from_folder(trainfolderpath) model = classify(dataModel.trainFeat, dataModel.trainLabels) acc = getAccuracy(model, dataModel.testFeat, dataModel.testLabels) print("Logistic Regression accuracy: {:.2f}%".format(acc * 100)) saveModel(model)
def svm_maker_algoritm(trainfolderpath): dataModel = get_data_from_folder(trainfolderpath) svmModel = classify(dataModel.trainFeat, dataModel.trainLabels) accSVMModel = getAccuracy(svmModel, dataModel.testFeat, dataModel.testLabels) print("SVMClassifier accuracy: {:.2f}%".format(accSVMModel * 100)) saveModel(svmModel)
loadedUp = False while not loadedUp: try: trainImages = helper.loadData(trainNP+"XtrainImages") trainVecs = helper.loadData(trainNP+"XtrainVecs") trainTargets = helper.loadData(trainNP+"ytrain") loadedUp = True except Exception as e: err = e print err, " \r", time.sleep(2) print "" subprocess.call("rm "+trainNP+"XtrainImages.h5",shell=True) subprocess.call("rm "+trainNP+"XtrainVecs.h5",shell=True) subprocess.call("rm "+trainNP+"ytrain.h5",shell=True) #train the model on it print trainImages.shape, trainVecs.shape model.fit([trainImages,trainVecs], trainTargets, batch_size=batch_size, nb_epoch=1) del trainImages, trainTargets helper.saveModel(model,folder+"wholeModel")