【发布时间】:2020-07-11 07:15:01
【问题描述】:
这似乎很基本,但我看不出以下两种方式之间的区别和优缺点:
第一种方式:
kf = KFold(n_splits=2)
for train_index, test_index in kf.split(X):
X_train, X_test = X.iloc[train_index], X.iloc[test_index]
y_train, y_test = y.iloc[train_index], y.iloc[test_index]
clf.fit(X_train, y_train)
clf.score(X_test, y_test)
第二种方式:
cross_val_score(clf, X, y, cv=2)
看来这2种方式做的一样,第二个更短(一行)。
我错过了什么?
每种方式有什么区别和优缺点?
【问题讨论】:
标签: python scikit-learn cross-validation