我想使用留下一個交叉驗證。但我得到以下錯誤:問題與交叉驗證
AttributeError Traceback (most recent call last)
<ipython-input-19-f15f1e522706> in <module>()
3 loo = LeaveOneOut(num_of_examples)
4 #loo.get_n_splits(X_train_std)
----> 5 for train, test in loo.split(X_train_std):
6 print("%s %s" % (train, test))
AttributeError的:「LeaveOneOut」對象有沒有屬性「分裂」
具體代碼如下:
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test =
train_test_split(X, y, test_size=0.3, random_state=0)
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
sc.fit(X_train)
X_train_std = sc.transform(X_train)
X_test_std = sc.transform(X_test)
from sklearn.cross_validation import LeaveOneOut
num_of_examples = len(X_train_std)
loo = LeaveOneOut(num_of_examples)
for train, test in loo.split(X_train_std):
print("%s %s" % (train, test))
從DOC(http://scikit-learn.org/stable/modules/generated/sklearn.model_selec tion.LeaveOneOut.html)它看起來像你需要首先使用'loo.get_n_splits(X_train)'分割你的設置' – Julien
請包括完整的錯誤信息。 – DyZ
這是不可讀的。請編輯您的原始問題並在其中包含完整的錯誤消息。 – DyZ