2016-06-01 10 views
1

私はPythonとSklearnの初心者です。私がここで何かを紛失しているかどうか疑問に思う。Python Sklearn - Deprecation警告

DeprecationWarning:データは0.17 で非推奨と0.19でとValueErrorをwillraiseされるよう1D配列を渡す私は、次の警告メッセージを取得しています。ここで

コードは次のとおりです。ご静聴ため再び

import numpy as np 
import matplotlib.pyplot as plt 
from sklearn.linear_model import SGDClassifier 
from sklearn.datasets.samples_generator import make_blobs 

def plot_sgd_separator(): 
    # we create 50 separable points 
    X, Y = make_blobs(n_samples=50, centers=2,random_state=0, cluster_std=0.60) 
    X = np.array(X).reshape((1, -1)) 


    # fit the model 
    clf = SGDClassifier(loss="hinge", alpha=0.01, 
         n_iter=200, fit_intercept=True) 
    clf.fit(X, Y) 

    # plot the line, the points, and the nearest vectors to the plane 
    xx = np.linspace(-1, 5, 10) 
    yy = np.linspace(-1, 5, 10) 

    X1, X2 = np.meshgrid(xx, yy) 
    Z = np.empty(X1.shape) 
    for (i, j), val in np.ndenumerate(X1): 
     x1 = val 
     x2 = X2[i, j] 
     p = clf.decision_function([x1, x2]) 
     Z[i, j] = p[0] 
    levels = [-1.0, 0.0, 1.0] 
    linestyles = ['dashed', 'solid', 'dashed'] 
    colors = 'k' 

    ax = plt.axes() 
    ax.contour(X1, X2, Z, levels, colors=colors, linestyles=linestyles) 
    ax.scatter(X[:, 0], X[:, 1], c=Y, cmap=plt.cm.Paired) 

    ax.axis('tight') 


if __name__ == '__main__': 
    plot_sgd_separator() 
    plt.show() 

感謝。ちなみに、私はPython 3.5.1を使用しています。

答えて

0

警告メッセージを読み、デバッグを少し行うと、モデルへの入力が一次元的であるため警告が発生することがわかります。このリンクを参照することができますSklearn train model with single sample raises a DeprecationWarningこれを修正する。

あなたのコードに他の問題があると思います。私が走ったとき、XとYのデータポイントの数は同じではないことがわかりました。 Xは100、Yは50ですが、これはもっと深刻な問題です。これを最初に修正する必要があると感じています。

1

あなたの質問はhereと回答していると思いますが、これはおそらくの重複です。