独赢算独赢包括加时赛吗吗;如何对其模型进行参数调优?

039-JVM虚拟机内存模型与参数调优和虚拟机监控―王树大_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
039-JVM虚拟机内存模型与参数调优和虚拟机监控―王树大
阅读已结束,下载文档到电脑
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,方便使用
还剩4页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢使用Grid Search进行模型参数调优 - 推酷
使用Grid Search进行模型参数调优
在机器学习中,参数调整是提高模型准确率的方法之一。本篇文章介绍如何使用Grid Search对随机森林模型参数进行调整。
开始前的准备工作
首先,导入所需库文件。除了常用的numpy,pandas库以外,还有进行参数调整的grid_search库文件。
#导入所需库文件
import numpy as np
import pandas as pd
from sklearn import grid_search
from sklearn.feature_extraction import DictVectorizer
from sklearn.ensemble import RandomForestClassifier
from sklearn import cross_validation
导入所需的数据表文件,用于训练模型并评估模型表现。
#导入数据表
test=pd.DataFrame(pd.read_csv('TEST_ML_v2.csv',header=0,encoding='GBK'))
第二步,对特征进行处理。从原数据表中提取一部分字段作为我们的特征X,对特征X进行OneHot编码。
X_df=test[['City', 'Item category', 'Period', 'Gender', 'Age', 'Market channels', 'Self-agent', 'Category', 'Loan channels']]
X_list=X_df.to_dict(orient=&records&)
vec = DictVectorizer()
X=vec.fit_transform(X_list)
Y=np.array(test['Status'])
使用随机方式划分训练集和测试集数据,其中训练集60%,测试集数据40%。
#划分训练集和测试集
X_train,X_test,y_train,y_test=cross_validation.train_test_split(X.toarray(),Y,test_size=0.4,random_state=0)
训练Random Forest模型
使用训练集数据对模型进行训练,模型在测试集上的准确率为0.8486。下面使用Grid Search对模型参数进行调优。
clf = RandomForestClassifier()
clf.fit(X_train,y_train)
clf.score(X_test, y_test)
模型参数调优
设置随机森林参数值,并使用grid_search对参数值进行搜索,找出其中的最优值。
parameters = [{'n_estimators':[10,100,1000],
'criterion':['entropy','gini'],
'max_depth':[10,50,100,200],
'min_samples_split':[2,5,10],
'min_weight_fraction_leaf':[0.0,0.1,0.2,0.3,0.4,0.5]
clf = grid_search.GridSearchCV(RandomForestClassifier(), parameters)
clf.fit(X_train,y_train)
GridSearchCV(cv=None, error_score='raise',
estimator=RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
max_depth=None, max_features='auto', max_leaf_nodes=None,
min_impurity_split=1e-07, min_samples_leaf=1,
min_samples_split=2, min_weight_fraction_leaf=0.0,
n_estimators=10, n_jobs=1, oob_score=False, random_state=None,
verbose=0, warm_start=False),
fit_params={}, iid=True, n_jobs=1,
param_grid=[{'n_estimators': [10, 100, 1000], 'criterion': ['entropy', 'gini'], 'max_depth': [10, 50, 100, 200], 'min_samples_split': [2, 5, 10], 'min_weight_fraction_leaf': [0.0, 0.1, 0.2, 0.3, 0.4, 0.5]}],
pre_dispatch='2*n_jobs', refit=True, scoring=None, verbose=0)
#查看完整调参结果
clf.grid_scores_
调参后查看准确率得分:0.8579
#调参后的score
clf.best_score_
参数的最优值是多少呢?我们使用best_params_获得最优参数值。
#获得最优参数值
clf.best_params_
{'criterion': 'entropy',
'max_depth': 10,
'min_samples_split': 2,
'min_weight_fraction_leaf': 0.0,
'n_estimators': 10}
在随机森林模型中设置最优参数,并使用测试集数据对模型进行评估。模型准确率为0.8675。
#设置随机森林参数
clf = RandomForestClassifier(n_estimators=10, criterion='entropy', max_depth=10, min_samples_split=2, min_weight_fraction_leaf=0.0)
clf.fit(X_train,y_train).score(X_test, y_test)
—【所有文章及图片版权归 蓝鲸(王彦平)所有。欢迎转载,但请注明转自“蓝鲸网站分析博客”。】—
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致

我要回帖

更多关于 独赢盘是什么意思 的文章

 

随机推荐