我正在尝试编写一个函数Cv(X,y,model,folds)该函数获取X,y我想要使用的模型(SVM,logistic.linear.perspetron等。)并返回平均训练误差经过k折和验证错误。我可以通过函数cross_val_score获得验证错误,但我不知道如何获得训练错误,我考虑过使用Kfold函数,但不知道如何实现。
我的代码:
import numpy as np
import pandas as pd
import requests
from sklearn.svm import SVC
from sklearn.datasets import fetch_mldata
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import KFold
##then I wrote a function that load data into DF and return labal_df and Data_df (didn't write it in here because it working)
def cv(X,y,model,folds):
Cv= cross_val_score(model, X,y, cv=folds,scoring='accuracy')
Cv=Cv.mean() ##Now I have the validation error for the model I selected after K folds.
But how can I calculate the mean of the train error?
曾想过使用Kfold函数在每个折叠上运行并测试火车错误,但找不到如何执行此操作。
如果有人可以解释,我将不胜感激