2016-04-25 172 views
1

我正在使用下面的python程序來實現一個基本的決策樹分類器。Python機器學習警告

from sklearn import tree 
from sklearn.tree import DecisionTreeClassifier 
import numpy as np 

features = [[140,1],[130,1],[150,0],[170,0]] 
labels = [0,0,1,1] 

clf = DecisionTreeClassifier() 
model = clf.fit(features, labels) 
a = model.predict ([160,0]) 
print (a) 

它打印出的預測值,但給出警告,

DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and 
willraise ValueError in 0.19. Reshape your data either using X.reshape(-1,  
1) if your data has a single feature or X.reshape(1, -1) if it contains a 
single sample. 

我試圖以此來解決它,

features = np.array(features).reshape(-1, 2) 
labels = np.array(labels).reshape(-1, 1) 

但是這顯示了同樣的警告。有什麼建議麼?

+0

當您進行這些更改時,您是否得到相同的警告或不同的問題? –

+0

同樣的警告顯示。 – user2251234

回答

3

問題出在model.predict。此作品: a = model.predict ([[160,0]])