这里我有一段Python代码,取自SoloLearn,
scores = []
kf = KFold(n_splits=5, shuffle=True)
for train_index, test_index in kf.split(X):
X_train, X_test = X[train_index], X[test_index]
y_train, y_test = y[train_index], y[test_index]
model = LogisticRegression()
model.fit(X_train, y_train)
scores.append(model.score(X_test, y_test))
print(scores)
print(np.mean(scores))
那么我的问题是,我需要在每次拆分中创建一个新模型吗?为什么我们不在 for 之前创建一个 LogisticRegression 呢?
我会把它放在前面以节省计算时间,但既然它是以这种方式呈现的,我认为这是有原因的。
小唯快跑啊
莫回无
墨色风雨
相关分类