python-3.x ValueError:max_features必须在随机森林的(0,n_features]中

rpppsulh  于 2023-04-13  发布在  Python
关注(0)|答案(2)|浏览(280)

未出现代码或错误:ValueError:max_features必须在(0,n_features]中。我已经尝试了堆栈解决方案,但没有得到解决方案。有人可以帮助吗?

def predict_RF(x_test_sel, k_vetor, y_train):
    model = RandomForestRegressor()
    model.fit(k_vetor, y_train)
    y_predict = model.predict(x_test_sel)

    kf = KFold(n_splits=3)

    n_estimators = [25, 50, 75, 100] 
    max_features = [0.2, 0,7, 0.5, 1.0]
    min_samples_leaf = [1, 2, 5, 10] 

    hyperF = dict (n_estimators = n_estimators, max_features=max_features, min_samples_leaf = min_samples_leaf) 

    gridF = GridSearchCV(model, hyperF, cv = kf, verbose = 1, n_jobs = -1)

    grid_fit = gridF.fit(k_vetor, y_train) #Fit the gridsearch object with X_train, (k_vetor, y_train) -> dar nome x_train para k_vetor 
    
    print(grid_fit.best_params_)
    
    return (y_predict)
8zzbczxx

8zzbczxx1#

我在使用max_features作为float时遇到了同样的问题。我建议max_features列表应该只包含整数。例如:max_features = [2,5,7,10]

0x6upsns

0x6upsns2#

请将0.7替换为0.7

max_features = [0.2, 0,7, 0.5, 1.0]

相关问题