def KNN(trainning_X, train_Y, predict_X, task_name, origin_data, stock_id): clf = KNeighborsClassifier(5) clf.fit(trainning_X, train_Y) res = clf.predict(predict_X) res_ = [] for i in range(len(res)): if res[i] == 1: res_.append(origin_data[stock_id][i]) tsk = training_result(taskName=task_name, clf_name="KNN(5)", result=res_) tsk.save()
def SVC(trainning_X, train_Y, predict_X, task_name, origin_data, stock_id): clf = svm.SVC(gamma=2, C=1) clf.fit(trainning_X, train_Y) res = clf.predict(predict_X) res_ = [] for i in range(len(res)): if res[i] == 1: res_.append(origin_data[stock_id][i]) tsk = training_result(taskName=task_name, clf_name="RBF SVM", result=res_) tsk.save()
def adaboost(trainning_X, train_Y, predict_X, task_name, origin_data, stock_id): clf = AdaBoostClassifier() clf.fit(trainning_X, train_Y) res = clf.predict(predict_X) res_ = [] for i in range(len(res)): if res[i] == 1: res_.append(origin_data[stock_id][i]) tsk = training_result(taskName=task_name, clf_name="adaboost", result=res_) tsk.save()
def RandomForest(trainning_X, train_Y, predict_X, task_name, origin_data, stock_id): clf = RandomForestClassifier(max_depth=5, n_estimators=10, max_features=1) clf.fit(trainning_X, train_Y) res = clf.predict(predict_X) res_ = [] for i in range(len(res)): if res[i] == 1: res_.append(origin_data[stock_id][i]) tsk = training_result(taskName=task_name, clf_name="Random Forest", result=res_) tsk.save()
def DecisionTree(trainning_X, train_Y, predict_X, task_name, origin_data, stock_id): clf = DecisionTreeClassifier(max_depth=5) clf.fit(trainning_X, train_Y) res = clf.predict(predict_X) res_ = [] for i in range(len(res)): if res[i] == 1: res_.append(origin_data[stock_id][i]) tsk = training_result(taskName=task_name, clf_name="Decision Tree", result=res_) tsk.save()
def LinearDiscriminant(trainning_X, train_Y, predict_X, task_name, origin_data, stock_id): clf = LinearDiscriminantAnalysis() clf.fit(trainning_X, train_Y) res = clf.predict(predict_X) res_ = [] for i in range(len(res)): if res[i] == 1: res_.append(origin_data[stock_id][i]) tsk = training_result(taskName=task_name, clf_name="Linear Discriminant Analysis", result=res_) tsk.save()
def Gaussian(trainning_X, train_Y, predict_X, task_name, origin_data, stock_id): clf = GaussianNB() clf.fit(trainning_X, train_Y) res = clf.predict(predict_X) res_ = [] for i in range(len(res)): if res[i] == 1: res_.append(origin_data[stock_id][i]) tsk = training_result(taskName=task_name, clf_name="GaussianNB", result=res_) tsk.save()