我试着对一个分类模型实施“不让一个组参与”交叉验证。到目前为止,我用这个代码做了简历。你知道吗
from sklearn.model_selection import LeaveOneGroupOut
X = X
y = np.array(df.loc[:, df.columns == 'label'])
scores=[]
groups = df["cow_id"].values
logo = LeaveOneGroupOut()
logo.get_n_splits(X, y, groups)
cv=logo.split(X, y, groups)
for train_index, test_index in cv:
print("Train Index: ", train_index, "\n")
print("Test Index: ", test_index)
X_train, X_test, y_train, y_test = X[train_index], X[test_index], y[train_index], y[test_index]
model.fit(X_train, y_train.ravel())
scores.append(model.score(X_test, y_test.ravel()))
从这个代码中我得到了每一次折叠的准确度分数。例如,如果我有35组,我会得到35分的准确率。我的问题是:如何获得每一次的敏感度得分?你知道吗
您只需要从
sklearn.metrics
导入recall_score
,并使用它,如下所示:希望这有帮助!你知道吗
相关问题 更多 >
编程相关推荐