随机森林调参

随机搜索:
首先,为随机森林回归器定义超参数的随机网格。
然后,您可以使用基于指定的随机网格搜索最佳超参数。RandomizedSearchCV
从随机搜索中提取最佳估计量 ()。best_random

随机搜索模型的评估:
在测试集上评估基本随机森林回归器 () 的性能。base_model
接下来,通过测试集上的随机搜索 () 评估最佳估计器的性能。best_random
网格搜索(第一轮):

您可以定义一个新的、更具体的参数网格 () 以进行进一步的超参数优化。param_grid
用于对指定的参数网格执行详尽搜索。GridSearchCV
从此网格搜索中提取最佳估计器 ()。best_grid
第一网格搜索模型的评估:

从测试集上的第一个网格搜索 () 中评估最佳估计器的性能。best_grid
网格搜索(第二轮):

为第二轮超参数优化定义另一个参数网格 ()。param_grid
您可以再次使用,以根据新参数网格搜索最佳超参数。GridSearchCV
从第二个网格搜索中提取最佳估计器 ()。best_grid_2
第二网格搜索模型的评估:

您可以在测试集上通过第二个网格搜索() 评估最佳估计器的性能。best_grid_2

其他网格搜索:

最后,使用其他超参数执行另一个网格搜索 ()。grid_search_ad
从此附加网格搜索中提取最佳估计器 ()。best_grid_ad
您可以在测试集上通过此附加网格搜索来评估最佳估计器的性能。
打印最终模型参数:

使用 打印最佳模型 () 的最后一组超参数。

import pandas as pd
features= pd.read_csv('data/temps_extended.csv')

独热处理处理数据

features = pd.get_dummies(features)

labels = features['actual']
features = features.drop('actual', axis = 1)

feature_list = list(features.columns)

import numpy as np

features = np.array(features)
labels = np.array(labels)

from sklearn.model_selection import train_test_split

train_features, test_features, train_labels, test_labels = train_test_split(features, labels,
                                                                            test_size = 0.25, random_state = 42)
# print('Training Features Shape:', train_features.shape)
# print('Training Labels Shape:', train_labels.shape)
# print('Testing Features Shape:', test_features.shape)
# print('Testing Labels Shape:', test_labels.shape)
#
# print('{:0.1f} years of data in the training set'.format(train_features.shape[0] / 365.))
# print('{:0.1f} years of data in the test set'.format(test_features.shape[0] / 365.))

选择那6个重要性比较高的特征

important_feature_names = ['temp_1', 'average', 'ws_1', 'temp_2', 'friend', 'year']

important_indices = [feature_list.index(feature) for feature in important_feature_names
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值