使用交叉验证评估性能时的拟合模型
fitting model when using cross validation to evaluate performance
我目前正在尝试比较多个模型。
我制作了一个脚本,使用 10 折交叉验证来评估性能以获得最真实的性能。
我的问题是,它适合什么样的训练和测试数据重要吗?例如我是否应该在
之后找到性能最好的训练集和测试集并再次拟合模型?
CV = model_selection.KFold(n_splits=K, shuffle=True)
# Split data
for train_index, test_index in CV.split(X, y):
for model in models:
# splitting up data set
X_train = X.iloc[train_index]
y_train = y.iloc[train_index]
X_test = X.iloc[test_index]
y_test = y.iloc[test_index]
model.fit(X_train, y_train)
print(model.score(X_test, y_test) * 100)
在我看来,这个问题对 Cross Validated Stack Exchange community to answer (and there are plenty of posts on cross validation) 来说要好得多。
但是,既然你在 Stack Overflow 上问过...
正如用户 9769953 评论的那样:它确实很重要。
在我看来 cross-validation 有两个主要用途:
- 检查数据是否有显着差异以扭曲模型的训练。
- 验证未见数据的性能(left-out 倍)。
预期的结果是您将得到不同的结果(每次折叠的相同结果应该让您对数据或模型训练过程产生怀疑)。
交叉验证的性能仅作为所有折叠结果的平均值才有意义。与“1 倍验证”(即 运行 正在学习的数据模型)相比,这是一个更现实的性能值,因为通常您将成为 运行 数据模型那个模型没见过。
我目前正在尝试比较多个模型。 我制作了一个脚本,使用 10 折交叉验证来评估性能以获得最真实的性能。 我的问题是,它适合什么样的训练和测试数据重要吗?例如我是否应该在
之后找到性能最好的训练集和测试集并再次拟合模型?CV = model_selection.KFold(n_splits=K, shuffle=True)
# Split data
for train_index, test_index in CV.split(X, y):
for model in models:
# splitting up data set
X_train = X.iloc[train_index]
y_train = y.iloc[train_index]
X_test = X.iloc[test_index]
y_test = y.iloc[test_index]
model.fit(X_train, y_train)
print(model.score(X_test, y_test) * 100)
在我看来,这个问题对 Cross Validated Stack Exchange community to answer (and there are plenty of posts on cross validation) 来说要好得多。
但是,既然你在 Stack Overflow 上问过... 正如用户 9769953 评论的那样:它确实很重要。
在我看来 cross-validation 有两个主要用途:
- 检查数据是否有显着差异以扭曲模型的训练。
- 验证未见数据的性能(left-out 倍)。
预期的结果是您将得到不同的结果(每次折叠的相同结果应该让您对数据或模型训练过程产生怀疑)。
交叉验证的性能仅作为所有折叠结果的平均值才有意义。与“1 倍验证”(即 运行 正在学习的数据模型)相比,这是一个更现实的性能值,因为通常您将成为 运行 数据模型那个模型没见过。