本文整理汇总了Python中sklearn.model_selection.RandomizedSearchCV.get_params方法的典型用法代码示例。如果您正苦于以下问题:Python RandomizedSearchCV.get_params方法的具体用法?Python RandomizedSearchCV.get_params怎么用?Python RandomizedSearchCV.get_params使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.model_selection.RandomizedSearchCV
的用法示例。
在下文中一共展示了RandomizedSearchCV.get_params方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fit
# 需要导入模块: from sklearn.model_selection import RandomizedSearchCV [as 别名]
# 或者: from sklearn.model_selection.RandomizedSearchCV import get_params [as 别名]
def fit(x, y, estimator, dataframe, params):
vectorizer = CountVectorizer(stop_words=['go', '', ' '], binary=False, lowercase=True)
vectorizer.fit(dataframe[x].values)
fresh_estimator = clone(estimator)
x_np, y_np, feature_names, selector = \
select_features(
df = dataframe,
vectorizer=vectorizer,
feature_col=x,
label_col=y,
select_method=None,
continuous_col=None
)
estimator = RandomizedSearchCV(estimator, params, n_iter=60, cv=3, n_jobs=3, refit=True)
estimator.fit(x_np, y_np)
best_params = estimator.best_params_
if method not in ['lr', 'svm']:
print("Calibrating...")
estimator = CalibratedClassifierCV(fresh_estimator.set_params(**best_params), 'isotonic', 3)
estimator.fit(x_np, y_np)
from sklearn.base import _pprint
_pprint(estimator.get_params(deep=True), offset=2)
return estimator, selector, vectorizer
示例2: param_optimization
# 需要导入模块: from sklearn.model_selection import RandomizedSearchCV [as 别名]
# 或者: from sklearn.model_selection.RandomizedSearchCV import get_params [as 别名]
def param_optimization(grid, col_predict, cv_k=5, n_part=.1,
train_file='train.csv', verbose=1, n_jobs=-1, n_iter=10,
save=True):
# Load data
x_all, y_all, x, y = get_data(FOLDER_DATA, train_file, col_predict, n_part)
if verbose > 0: print('Using %d data points from now on' % x.shape[0])
# Create pipeline elements
mlp = nn.MLPRegressor()
ss = StandardScaler()
fil = Filter(x_all.to_records(), 1,
('s.co2', 's.no2resistance', 's.o3resistance'), 'secs')
# measure_rmse = make_scorer(rmse, greater_is_better=False)
# Do randomized grid search
gs_steps = [('filter', fil), ('scale', ss), ('mlp', mlp)]
gs_pipe = Pipeline(gs_steps)
gs = RandomizedSearchCV(gs_pipe, grid, n_iter, n_jobs=n_jobs,
cv=cv_k, verbose=verbose, error_score=np.NaN)
gs.fit(x, y)
print("Best parameters are:\n%s" % gs.best_params_)
print("Best score is:\n%f" % gs.best_score_)
# Filter data
fil.alpha = gs.best_params_['filter__alpha']
x2 = fil.transform(x)
x2 = x2.drop('secs', axis=1)
# Learn online estimator
steps2 = [('scale', ss), ('mlp', mlp)]
pipe2 = Pipeline(steps2)
del gs.best_params_['filter__alpha']
pipe2.set_params(**gs.best_params_)
pipe2.fit(x2, y)
pred2 = cross_val_predict(pipe2, x, y, cv = cv_k)
if save:
# Save gridsearch results
save_pickle(gs, col_predict + '_grid_search', FOLDER_SAVE)
save_csv(gs.cv_results_, col_predict + '_grid_search_scores',
FOLDER_PERF)
save_txt(str(gs.get_params(True)),
col_predict + '_grid_search_parameters', FOLDER_SAVE)
# Save best estimator
save_pickle(gs.best_estimator_, col_predict + '_best_estimator',
FOLDER_SAVE)
save_fit_plot(x, y, gs.best_estimator_,
col_predict + '_best_estimator_scatter', FOLDER_PERF)
save_txt(str(gs.best_estimator_.get_params(True)),
col_predict + '_best_estimator_parameters', FOLDER_SAVE)
# Save actual estimator
save_pickle(pipe2, col_predict + '_actual_estimator', FOLDER_SAVE)
save_fit_plot(x2, y, pipe2, col_predict + '_actual_estimator_scatter',
FOLDER_PERF)
save_txt(str(pipe2.get_params(True)),
col_predict + '_actual_estimator_parameters', FOLDER_SAVE)
# Save target - prediction pairs
save_target_pred(y, pred2, col_predict + '_target_pred', FOLDER_PERF)