for循环搜索参数python

list_1=[1,2,3,4,5,6,7,8,9,10]
list_2=[0.01,0.75,0.8,0.85,0.9,0.95,1]
list_3=[0,1,2,3,4,5,6,7,8,9,10]
for a in list_1:
    for b in list_2:
        for c in list_3:
                model_GBR=GradientBoostingRegressor(max_depth=a,learning_rate=b,random_state=c)
                model_GBR.fit(X_train_std,y_train)
                print(a,b,c,model_GBR.score(X_train_std, y_train),model_GBR.score(X_test_std, y_test))

方法2:

best_score =0
list_1=np.arange(0,51,1)
list_2=np.arange(11,25,1)
for a in list_1:
    for b in list_2:
        tree = DecisionTreeRegressor(random_state=a,max_depth=b)
        tree.fit(X_train_std,y_train)
        y_train_pred_tree = tree.predict(X_train_std)
        y_test_pred_tree = tree.predict(X_test_std)
        score=r2_score(y_test,y_test_pred_tree)
        if score > best_score:
            best_score = score
            best_parameters = {'random_state': a, 'max_depth': b}
print("Best score: {:.5f}".format(best_score))
print("Best parameters: {}".format(best_parameters))   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值