这篇文章主要介绍“怎么用JavaScript预测鸢尾花品种”,在日常操作中,相信很多人在怎么用JavaScript预测鸢尾花品种问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么用JavaScript预测鸢尾花品种”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
创新互联公司的客户来自各行各业,为了共同目标,我们在工作上密切配合,从创业型小企业到企事业单位,感谢他们对我们的要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。专业领域包括网站设计制作、成都网站制作、电商网站开发、微信营销、系统平台开发。
import pandas as pd
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
df = pd.read_csv(r"iris\YT-Django-Iris-App-3xj9B0qqps-master\iris.csv")
x = ['sepal_length','sepal_width','petal_length','petal_width']
X = df[x]
y = df['classification']
X_train, X_test, Y_train, Y_test = train_test_split(X,y,test_size=0.2,random_state=1)
训练数据集合测试数据集的比例是8:2
model = SVC(gamma='auto')
model.fit(X_train,Y_train)
predictions = model.predict(X_test)
输入数据预测
iris = [1,1,1,1]
results = model.predict([iris])
print(results)
结果results是一个列表
print(accuracy_score(Y_test,predictions))
运行代码得到结果为 0.966666666667
pd.to_pickle(model,r"new_model.pickle")
如果需要用这个模型可以直接读入
model = pd.read_pickle(r"new_model.pickle")
完整代码
import pandas as pd
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
df = pd.read_csv(r"iris\YT-Django-Iris-App-3xj9B0qqps-master\iris.csv")
print(df.head())
x = ['sepal_length','sepal_width','petal_length','petal_width']
X = df[x]
y = df['classification']
X_train, X_test, Y_train, Y_test = train_test_split(X,y,test_size=0.2,random_state=1)
model = SVC(gamma='auto')
model.fit(X_train,Y_train)
predictions = model.predict(X_test)
print(accuracy_score(Y_test,predictions))
pd.to_pickle(model,r"new_model.pickle")
model = pd.read_pickle(r"new_model.pickle")
iris = [1,1,1,1]
results = model.predict([iris])
print(results)
到此,关于“怎么用JavaScript预测鸢尾花品种”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!