当前位置: 首页>>代码示例>>Python>>正文


Python Filter.alpha方法代码示例

本文整理汇总了Python中filter.Filter.alpha方法的典型用法代码示例。如果您正苦于以下问题:Python Filter.alpha方法的具体用法?Python Filter.alpha怎么用?Python Filter.alpha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在filter.Filter的用法示例。


在下文中一共展示了Filter.alpha方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: param_optimization

# 需要导入模块: from filter import Filter [as 别名]
# 或者: from filter.Filter import alpha [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)
开发者ID:Geonovum,项目名称:smartemission,代码行数:63,代码来源:pipeline.py


注:本文中的filter.Filter.alpha方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。