我已经在链接中运行示例代码:https : //github.com/casperbh96/Nested-Cross-Validation/blob/master/Example%20Notebook%20-%20NestedCV.ipynb,但是出现了一个错误:init()有一个意外的关键字参数'outer_cv',我检查了源代码,'outer_cv'包含在int()中,如何解决?示例代码还粘贴如下:
from nested_cv import NestedCV
import pandas as pd
import numpy as np
from sklearn.datasets import load_boston, load_iris, load_breast_cancer
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
from sklearn.model_selection import KFold
# When using Random Search, we get a user warning with this little number of hyperparameters
# Suppress it
import warnings
warnings.simplefilter(action='ignore', category=UserWarning)
warnings.simplefilter(action='ignore', category=FutureWarning)
boston = load_boston()
X = boston.data
y = boston.target
# Define a parameters grid
param_grid = {
'max_depth': [3, 7, 10, None],
'n_estimators': [100,200],
'min_samples_split':[2,3,5,7,10]
}
# Either specify a strategy or number
# Here we choose a strategy
outer_cv = KFold(n_splits=5,
shuffle=True,
random_state=123)
inner_cv = KFold(n_splits=5,
shuffle=True,
random_state=123)
NCV = NestedCV(model=RandomForestRegressor(), params_grid=param_grid,
outer_cv=outer_cv, inner_cv=inner_cv, n_jobs = -1,
cv_options={'sqrt_of_score':True,
'recursive_feature_elimination':False,
'rfe_n_features':2})
NCV.fit(X=X,y=y)
NCV.outer_scores
尽管我无法在任何合理的时间内完成NCV.fit,但这应该使您更接近:
from nested_cv import NestedCV
import pandas as pd
import numpy as np
from sklearn.datasets import load_boston, load_iris, load_breast_cancer
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
from sklearn.model_selection import KFold
# When using Random Search, we get a user warning with this little number of hyperparameters
# Suppress it
import warnings
warnings.simplefilter(action='ignore', category=UserWarning)
warnings.simplefilter(action='ignore', category=FutureWarning)
boston = load_boston()
X = boston.data
y = boston.target
# Define a parameters grid
param_grid = {
'max_depth': [3, 7, 10, None],
'n_estimators': [100,200],
'min_samples_split':[2,3,5,7,10]
}
# Either specify a strategy or number
# Here we choose a strategy
outer_cv = KFold(n_splits=5,
shuffle=True,
random_state=123)
inner_cv = KFold(n_splits=5,
shuffle=True,
random_state=123)
NCV = NestedCV(model=RandomForestRegressor(), params_grid=param_grid,
outer_kfolds=outer_cv.n_splits, inner_kfolds=inner_cv.n_splits, n_jobs = -1,
cv_options={'sqrt_of_score':True,
'recursive_feature_elimination':False,
'rfe_n_features':2})
#NCV.fit(X=X,y=y)
NCV.outer_scores
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句