2016-04-09 3 views
1

を持っていない:Pythonのエラー 'INT' オブジェクトは、Python 3.5で<code>sklearn</code>、以下の例を使用して何の属性 '形状'

from sklearn import tree 
features = [[140,1], [130,1], [150,0], [155,0]] 
labels = [0,0,1,1] 

clf = tree.DecisionTreeClassifier() 
clf.fit(features, labels) 
print(clf.predict(155,0)) 

私はエラー次のエラーを取得します。私はなぜこのエラーを受け取ったのか理解できません。

Traceback (most recent call last): 
    File "ml.py", line 7, in <module> 
    print(clf.predict(155,0)) 
    File "/Users/user/Documents/hello/env/lib/python3.5/site-packages/sklearn/tree/tree.py", line 404, in predict 
    X = self._validate_X_predict(X, check_input) 
    File "/Users/user/Documents/hello/env/lib/python3.5/site-packages/sklearn/tree/tree.py", line 371, in _validate_X_predict 
    n_features = X.shape[1] 
AttributeError: 'int' object has no attribute 'shape' 

答えて

2

あなたがDecisionTreeClassifier.predictのためのドキュメントを読めば、あなたは間違ったデータを渡している見ることができます:

は(X、check_input =真)

を予測するには、クラスまたは回帰値を予測しますXの場合 分類モデルの場合、Xの各サンプルの予測クラスが返されます。回帰モデルの場合、Xに基づく予測値が返されます。 パラメータ:

X : array-like or sparse matrix of shape = [n_samples, n_features] 
+1

申し訳ありません、はいそれを再度確認した後、私は今ていることがわかります。ご協力ありがとうございました。 – Prometheus

関連する問題