def save(): data = get_data() model = KNN() model.fit(data) pickle.dump(model, open('model.pkl', 'wb'))
import numpy as np import matplotlib.pyplot as plt import pydotplus from io import StringIO from sklearn.model_selection import cross_val_score from sklearn.ensemble import RandomForestClassifier from data_preprocessor import get_data def run_random_forest(x_train, x_test, y_train, y_test): clf = RandomForestClassifier(n_estimators=10) clf.fit(x_train, y_train) scores = cross_val_score(clf, x_test, y_test, cv=5) print("random_forest: %.15f" % scores.mean()) if __name__ == '__main__': x_train, x_test, y_train, y_test = get_data() run_random_forest(x_train, x_test, y_train, y_test)
import pickle import os.path import sys import json from data_preprocessor import get_data from sklearn.model_selection import train_test_split import save_model data = get_data() if os.path.isfile("model.pkl"): model = pickle.load(open('model.pkl', 'rb')) else: save_model.save() model = pickle.load(open('model.pkl', 'rb')) if len(sys.argv) > 1: ID = int(sys.argv[1]) - 1 X_test = data.loc[ID].to_frame().T preds = model.predict(X_test) values = [[i + 1 for i in row] for row in preds] feedback = json.dumps(values) print(feedback)
from decision_tree import run_decision_tree from k_nearest_neighbour import run_k_nearest_neighbour from logistic_regression import run_logistic_regression from naive_bayes import run_naive_bayes from neural_network import run_neural_network from perceptron import run_perceptron from random_forest import run_random_forest from svm import run_svm from xg_boost import run_xg_boost from pca import run_pca from voting import run_voting from data_preprocessor import get_data if __name__ == '__main__': x_train, x_test, y_train, y_test = get_data(True) print( "\n-------------------------------------\nAccuracies with top 5 features:\n-------------------------------------" ) run_decision_tree(x_train, x_test, y_train, y_test) run_k_nearest_neighbour(x_train, x_test, y_train, y_test) run_logistic_regression(x_train, x_test, y_train, y_test) run_naive_bayes(x_train, x_test, y_train, y_test) run_neural_network(x_train, x_test, y_train, y_test) run_perceptron(x_train, x_test, y_train, y_test) run_random_forest(x_train, x_test, y_train, y_test) run_svm(x_train, x_test, y_train, y_test) run_xg_boost(x_train, x_test, y_train, y_test) print(