在PHP上使用sklearn训练数据

时间:2019-05-26 14:00:56

标签: php mysql python-3.x scikit-learn

我尝试建立能够训练数据并输出训练模型的网站。我在python上使用sklearn并在php上执行

我尝试在jupyter上执行python,一切似乎都很好。

下面是一些代码:

from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC, LinearSVC
from sklearn.ensemble import RandomForestClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.linear_model import Perceptron
from sklearn.linear_model import SGDClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split

predictors = train1.drop(['lulus'], axis=1)
target = train1["lulus"]
x_train, x_val, y_train, y_val = train_test_split(predictors, target, test_size = 0.22, random_state = 0)

from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import accuracy_score

gaussian = GaussianNB()
gaussian.fit(x_train, y_train)
hnb = gaussian.predict(x_val)
acc_gaussian = round(accuracy_score(hnb, y_val) * 100, 2)
print(acc_gaussian)

from sklearn.tree import DecisionTreeClassifier

decisiontree = DecisionTreeClassifier()
decisiontree.fit(x_train, y_train)
hc45 = decisiontree.predict(x_val)
acc_decisiontree = round(accuracy_score(hc45, y_val) * 100, 2)
print(acc_decisiontree)

from sklearn.externals import joblib

joblib.dump(gaussian, 'modelgaus.pkl', compress=9)
joblib.dump(decisiontree,'modeltree.pkl', compress=9)

模型应输出为modelgaus.pkl和modeltree.pkl

反正有火车模型输出吗?

0 个答案:

没有答案