上周,我可以用python3.7.2运行程序。在
今天早上我进来,运行同一个程序,结果出错了
AttributeError: module 'numpy' has no attribute 'testing'
我重新卸载并安装了python3.7.2
然后我做了pip3 install -U scikit-learn scipy matplotlib
,运行了相同的程序,仍然得到这个错误。在
整个上午都在搜索,尝试不同的东西(当然,重启机器,检查路径)
请帮忙!!!!!!在
# Assigning features and label variables
# First Feature
weather=['Sunny','Sunny','Overcast','Rainy','Rainy','Rainy','Overcast','Sunny','Sunny',
'Rainy','Sunny','Overcast','Overcast','Rainy']
# Second Feature
temp=['Hot','Hot','Hot','Mild','Cool','Cool','Cool','Mild','Cool','Mild','Mild','Mild','Hot','Mild']
# Label or target varible
play=['No','No','Yes','Yes','Yes','No','Yes','No','Yes','Yes','Yes','Yes','Yes','No']
# Import LabelEncoder
from sklearn import preprocessing
# creating labelEncoder
le = preprocessing.LabelEncoder()
# converting string labels into numbers
weather_encoded = le.fit_transform(weather)
print(weather_encoded)
# converting string labels into numbers
temp_encoded = le.fit_transform(temp)
label = le.fit_transform(play)
# combining weather and temp into a single list of tuples
features = list(zip(weather_encoded,temp_encoded))
from sklearn.neighbors import KNeighborsClassifier
model = KNeighborsClassifier(n_neighbors=3)
# Train the model using the training sets
model.fit(features, label)
# Predict Output
predicted = model.predict([[0,2]]) #0:Overcast, 2:Mild
print(predicted)
目前没有回答
相关问题 更多 >
编程相关推荐