About CV-Assistant GRIDSEARCHCV

Source: Internet
Author: User
Tags svm

The first tool to be introduced is the Sklearn model selection API (GRIDSEARCHCV)

Website Link: http://scikit-learn.org/stable/modules/generated/sklearn.grid_search.GridSearchCV.html section I: Usage of GRIDSEARCHCV function

Sklearn.grid_search. GRIDSEARCHCV (
	estimator, # is the model you want to train booster
	Param_grid, # The params of the dictionary type needs to select the parameter
	scoring=none, # The standard for judging performance such as auc:scoring= ' Roc_auc '
	fit_params=none, 
	N_jobs=1, # Number of jobs running in parallel
	iid=true, Refit=true, Cv=none, 
	# Ratio of training set to validation set, equivalent to nfold=5
	verbose=0, 
	pre_dispatch= ' 2*n_jobs ', 
	error_score= ' raise '
)
A simple example is as follows:

#-*-coding:utf-8-*-
Import pandas as PD from
sklearn import SVM, datasets from
sklearn.model_selection impo RT GRIDSEARCHCV
from sklearn.metrics import classification_report

iris = Datasets.load_iris ()
# Super parameter to be adjusted
parameters = {
	' kernel ':(' linear ', ' RBF '), 
	' C ': [1, 2, 4], 
	' gamma ': [0.125, 0.25, 0.5, 1, 2, 4]
}< C11/>svr = SVM. SVC () # model
CLF = GRIDSEARCHCV (SVR, parameters, n_jobs=4)
clf.fit (Iris.data, Iris.target) #你和模型
# clf.cv_ Results_ is the log information for the Select parameter
cv_result = PD. Dataframe.from_dict (CLF.CV_RESULTS_)
with open ('./data/cv_result.csv ', ' WB ') as F:cv_result.to_csv (f)
print ' The parameters of the best model was: '
print  clf.best_params_  # prints out the most appropriate model parameters
Y_pred_array = cl F.predict (iris.data) # prediction Results
Print classification_report (Y_true=iris.target, Y_pred=y_pred_array)
Where print Clf.best_params_ prints the following information, which is the optimal parameter

{' Kernel ': ' linear ', ' C ': 2, ' gamma ': 0.125}

Print Classification_report (y_true=iris.target, Y_pred=y_pred_array) prints the following results

             Precision    Recall  f1-score   support

          0       1.00      1.00      1.00
          1       1.00      0.94      0.97
          2       0.94      1.00      0.97      , avg/total 0.98 0.98      0.98       150

section II: LIGHTGBM using GRIDSEARCHCV AssistantThe parameters that lgbmregressor can invoke are configured as follows
Lightgbm.sklearn.LGBMRegressor ( 
    boosting_type= ' GBDT ', 
    num_leaves=31, 
    max_depth=-1, 
    learning_ rate=0.1, 
    n_estimators=10, 
    max_bin=255, 
    subsample_for_bin=50000, 
    objective= ' regression ', 
    Min_split_gain=0, 
    min_child_weight=5, 
    min_child_samples=10, 
    subsample=1, 
    subsample_freq=1, 
    colsample_bytree=1, 
    reg_alpha=0, 
    reg_lambda=0, 
    seed=0, 
    nthread=-1, 
    silent=true, 
    huber_delta=1.0, 
    gaussian_eta=1.0, 
    fair_c=1.0, 
    poisson_max_delta_step=0.7, 
    drop_rate =0.1, 
    skip_drop=0.5, 
    max_drop=50, 
    uniform_drop=false, 
    xgboost_dart_mode=false
)










Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.