您好,登錄后才能下訂單哦!
這篇文章主要介紹“怎么用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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。