python svm超参数,通过GridSearchCV()探索的svm.SVC()超参数的合适值范围是多少?...

I am running into the problem that the hyperparameters of my svm.SVC() are too wide such that the GridSearchCV() never gets completed! One idea is to use RandomizedSearchCV() instead. But again, my dataset is relative big such that 500 iterations take about 1 hour!

My question is, what is a good set-up (in terms of the range of values for each hyperparameter) in GridSearchCV ( or RandomizedSearchCV ) in order to stop wasting resources?

In other words, how to decide whether or not e.g. C values above 100 make sense and/or step of 1 is neither big not small? Any help is very much appreciated. This is the set-up am currently using:

parameters = {

'C': np.arange( 1, 100+1, 1 ).tolist(),

'kernel': ['linear', 'rbf'], # precomputed,'poly', 'sigmoid'

'degree': np.arange( 0, 100+0, 1 ).tolist(),

'gamma': np.arange( 0.0, 10.0+0.0, 0.1 ).tolist(),

'coef0': np.arange( 0.0, 10.0+0.0, 0.1 ).tolist(),

'shrinking': [True],

'probability': [False],

'tol': np.arange( 0.001, 0.01+0.001, 0.001 ).tolist(),

'cache_size': [2000],

'class_weight': [None],

'verbose': [False],

'max_iter': [-1],

'random_state': [None],

}

model = grid_search.RandomizedSearchCV( n_iter = 500,

estimator = svm.SVC(),

param_distributions = parameters,

n_jobs = 4,

iid = True,

refit = True,

cv = 5,

verbose = 1,

pre_dispatch = '2*n_jobs'

) # scoring = 'accuracy'

model.fit( train_X, train_Y )

print( model.best_estimator_ )

print( model.best_score_ )

print( model.best_params_ )

解决方案

Which kernel works best depends a lot on your data. What is the number of samples and dimensions and what kind of data do you have?

For the ranges to be comparable, you need to normalize your data, often StandardScaler, which does zero mean and unit variance, is a good idea.

If your data is non-negative, you might try MinMaxScaler.

For kernel="gamma", I usually do

{'C': np.logspace(-3, 2, 6), 'gamma': np.logspace(-3, 2, 6)}

which is based on nothing but served me well the last couple of years.

I would strongly advice against non-logarithmic grids, and even more though against randomized search using discrete parameters. One of the main advantages of randomized search is that you can actually search continuous parameters using continuous distributions [see the docs].

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值