原Warning如下:
C:\Python27\lib\site-packages\sklearn\utils\validation.py:395: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise 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.
之前输入的测试代码如下:
from sklearn.externals import joblib
from array import array
from sklearn.linear_model import LogisticRegression
import numpy as np
x = [24, 0, 251, 38, 20, 52, 168, 1]
print type(x)
classifier =(joblib.load('classifier.model'))
result = classifier.predict(x)
print result[0]
改正输入x
x = [[24, 0, 251, 38, 20, 52, 168, 1]]
这样就没有DeprecationWarning了。 分析:主要问题在
classifier.predict(x)
对于我的情况,虽然是一个sample ,但是也要规范输入x = [ [sample1 features] , [sample2 features] ... [samplen features] ].