机器学习:模型调参

一、网格调参

from sklearn.model_selection import GridSearchCV
parameters = [{'a1':['a','b'],'a2':['a','b']}]
clf = GridSearchCV(model,param_distributions,scoring = ['accuracy','f1'],cv) #评分函数
clf.fit(X_train,y_train)

二、随机搜索

from sklearn.model_selection import RandomizedSearchCV
import scipy
parameters = {'C':scipy.stats.expon(scale=100),  # 分布类
              'multi_class':['ovr','multinomial']}
clf = RandomizedSearchCV(model,param_distributions=parameters,cv,
                         scoring="accuracy",n_iter=100)
#n_iter是每个参数采样的数量,值越大,参数优化效果越好

你可能感兴趣的:(机器学习)