喜欢程度预测

喜欢程度预测,第1张

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neighbors import KNeighborsClassifier
df=pd.read_csv("datatest.csv",names=["出行","游戏时间","冰淇淋","配对结果"])
print(df)
feature=df.iloc[:,0:3]
print(feature)
target=df.iloc[:,-1]
print(target)
x_train,x_test,y_train,y_test=train_test_split(feature,target,test_size=0.2,random_state=2000)
print(x_train.shape,x_test.shape)
from sklearn.preprocessing import StandardScaler
ss=StandardScaler()
x_train=ss.fit_transform(x_train)
print(x_train)
knn=KNeighborsClassifier(n_neighbors=4)
knn.fit(x_train,y_train)
x_test=ss.transform(x_test)
score=knn.score(x_test,y_test)
print(f"模型评分{score}")

x_test1=[[34621,4.122344,0.345678],[1,0,0]]
x_test1=ss.transform(x_test1)
y_predict=knn.predict(x_test1)
print(y_predict)

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/718000.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-25
下一篇 2022-04-25

发表评论

登录后才能评论

评论列表(0条)

保存