单个样本的Sklearn火车模型引发了DeprecationWarning

时间:2016-04-10 23:46:40

标签: python-2.7 numpy machine-learning scikit-learn

所以这是我的代码:

我有一个features数组和一个labels数组,用于训练model.pkl

但是当我想在模型中添加single sample时,我会看到warning

from sklearn import tree
from sklearn.externals import joblib

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

# Here I train the model with the above arrays
clf = tree.DecisionTreeClassifier()
clf = clf.fit(features, labels)
joblib.dump(clf, 'model.pkl') 

# Now I want to train the model with a new single sample
clf = joblib.load('model.pkl')
clf = clf.fit([130, 1], 0) # WARNING MESSAGE HERE!!

这是warning

        /usr/local/lib/python2.7/dist-packages/sklearn/utils/validation.py:386:
 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.  DeprecationWarning)

我已经阅读了this。 但似乎我的例子不同。

我如何每次只训练一个样本的模型?

谢谢

0 个答案:

没有答案