【问题标题】:how can I use estimators not in sklearn for model pipeline我如何使用不在 sklearn 中的估计器进行模型管道
【发布时间】:2017-05-15 04:52:21
【问题描述】:

我尝试在gridSearchCV函数中使用arima模型,但它返回了

"TypeError: Cannot clone object '' (type ): 它似乎不是 scikit-learn 估计器,因为它没有实现 'get_params' 方法。 "

import numpy as np
import pandas as pd
from sklearn.grid_search import GridSearchCV
from statsmodels.tsa.arima_model import ARIMA
df_original = pd.DataFrame({"date_col": ['2016-08-01', '2016-08-02', '2016-08-03', '2016-08-04', '2016-08-05',
                                             '2016-08-06', '2016-08-07', '2016-08-08', '2016-08-09', '2016-08-10',
                                             '2016-08-11'],
                                'sum_base_revenue_cip': [1, 2, 7, 5, 1, 2, 5, 10, 9, 0, 1]})
    df_original["sum_base_revenue_cip"] = np.log(df_original["sum_base_revenue_cip"] + 1e-6)
    df_original_ts = df_original.copy(deep=True)
    df_original_ts['date_col'] = pd.to_datetime(df_original['date_col'])
    df_original_ts = df_original_ts.set_index('date_col')
    print df_original_ts

    estimator = ARIMA(df_original_ts,order=(1,1,0))
    params = {
        'order': ((2, 1, 0), (0, 2, 1), (1, 0, 0))
    }
    grid_search = GridSearchCV(estimator,
                               params,
                               n_jobs=-1,
                               verbose=True)
    grid_search.fit(df_original_ts)

【问题讨论】:

标签: python-2.7 scikit-learn time-series pipeline grid-search


【解决方案1】:
  1. 你可以为它找到一个 sklearn 包装器
  2. 您可以编写自己的继承自 BaseEstimator 并满足 sklearn 估计器的所有要求,例如所有参数都必须在 init 的签名中明确提及。
  3. 您可以滚动您自己的网格搜索,只需循环遍历参数。

【讨论】:

    猜你喜欢
    • 2021-03-09
    • 2017-06-13
    • 2020-12-26
    • 2018-06-24
    • 2017-08-18
    • 2017-07-01
    • 2018-12-01
    • 2019-12-20
    • 2020-02-20
    相关资源
    最近更新 更多