def sklearnNaiveBayes(test, train, structFile): model=GaussianNB() le=preprocessing.LabelEncoder() target_train=train['class'] inputs_train=train.drop('class',axis='columns') target_test=test['class'] inputs_test=test.drop('class',axis='columns') inputs_train=fit_transforms(inputs_train) model.fit(inputs_train,target_train) # save model to file filename = 'NaiveBayesSKlearn_model.sav' joblib.dump(model, filename) inputs_test=fit_transforms(inputs_test) print("sklearnNaiveBayes accuracy:",model.score(inputs_test,target_test),"%")
def TestTrainFitPlot(train, test): # Setup arrays to store train and test accuracies # Split into training and test set target_train = train['class'] inputs_train = train.drop('class', axis='columns') target_test = test['class'] inputs_test = test.drop('class', axis='columns') inputs_train = fit_transforms(inputs_train) inputs_test = fit_transforms(inputs_test) knn = KNeighborsClassifier() knn.fit(inputs_train, target_train) # save model to file filename = 'KNN_model.sav' joblib.dump(knn, open(filename, 'wb')) # Check Accuracy Score print('KNN Accuracy: {}'.format( round(knn.score(inputs_test, target_test), 3))) # Enum Loop, accuracy results using range on 'n' values for KNN Classifier '''
def ID3SKlearn_algorithm(test,train,structFile): train=fit_transforms(train) train_target= train['class'] train_feature=train.drop('class', axis='columns') test=fit_transforms(test) test_target= test['class'] test_feature=test.drop('class', axis='columns') tree=DecisionTreeClassifier(criterion='entropy',max_depth=100).fit(train_feature,train_target) # save model to file filename = 'ID3SKlearn_model.sav' joblib.dump(tree, filename) prediction = tree.predict(test_feature) print("ID3SKlearn_algorithm accuracy is: ",tree.score(test_feature,test_target)*100,"%")
def KNNClassifier(test, train, structFile): encode = fit_transforms(train) encode_ = fit_transforms(test) x = feature("class", encode) y = feature("class", encode_) TestTrainFitPlot(train, test)