您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要介绍“怎么用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预测鸢尾花品种”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。