我一直在尝试在决策树的情况下进行网格搜索 CV。我收到以下错误。
ValueError:估计器 RecursiveTabularRegressionForecaster 的参数 min_samples_split 无效(estimator=DecisionTreeRegressor())。使用 来检查可用参数列表estimator.get_params().keys()
。
from sktime.forecasting.model_selection import ForecastingRandomizedSearchCV
from sktime.forecasting.model_selection import SlidingWindowSplitter
from sktime.forecasting.model_selection import temporal_train_test_split
from sktime.forecasting.compose import make_reduction
y = univ['GHI']
y_train, y_test = temporal_train_test_split(y, test_size=30)
regressor = DecisionTreeRegressor()
forecaster = make_reduction(regressor)
params = {'max_leaf_nodes': list(range(2, 100)), 'min_samples_split': [2, 3, 4]}
cv = SlidingWindowSplitter(initial_window=60, window_length=30)
nrcv = ForecastingRandomizedSearchCV(forecaster, strategy="refit", cv=cv,
param_distributions=params,
n_iter=5, random_state=42)
nrcv.fit(y_train)
y_pred = nrcv.predict(np.arange(1, y_test.size+1))
print(nrcv.best_params_)
print(nrcv.best_score_)
我也试过 'estimator.get_params().keys()' 这个函数。我认为它与参数匹配。
dict_keys(['ccp_alpha','criterion','max_depth','max_features','max_leaf_nodes','min_impurity_decrease','min_impurity_split','min_samples_leaf','min_samples_split','min_weight_fraction_leaf','random_state','splitter' ])