我在sci-kit learn文档中找不到此信息。但根据我得到的数字,分数看起来不像是均方误差。
cross_val_score
调用您传入的估算器的.score()
方法,该方法返回的内容因估算器而异。您必须查看每个估算器的文档,以找出相应的.score()
方法返回的内容。您可以使用 scoring
参数覆盖此默认行为。此处对此进行了记录。
我首先使用 cross_val_predict 计算预测值,然后使用带有 y_test 的预测值来获得metrics.accuracy_score分数,从而避免了这个问题。
# Function that runs the requested algorithm and returns the accuracy metrics
def fit_ml_algo(algo, X_train, y_train, cv):
# One Pass
model = algo.fit(X_train, y_train)
acc = round(model.score(X_train, y_train) * 100, 2)
# Cross Validation
train_pred = model_selection.cross_val_predict(algo,
X_train,
y_train,
cv=cv,
n_jobs = -1)
# Cross-validation accuracy metric
acc_cv = round(metrics.accuracy_score(y_train, train_pred) * 100, 2)
return train_pred, acc, acc_cv