user2251234 user2251234 - 1 year ago 71
Python Question

Python Machine Learning Warning

I am using the following python program to implement a basic decision tree classifier.

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 =, labels)
a = model.predict ([160,0])
print (a)

It prints out the predicted value but gives a warning,

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.

I have tried to fix it using this,

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

But this showed the same warning. Any suggestions?


The problem is with model.predict. This works: a = model.predict ([[160,0]])