【问题标题】:TPOT: Pickling Error When Using TPOTRegressorTPOT:使用 TPOTRegressor 时出现酸洗错误
【发布时间】:2017-12-02 11:00:57
【问题描述】:

我有一个名为 X 的 DataFrame 和一组名为 Y 的目标值。

对于我的大多数模型,我会做这样的事情(只是一个例子):

from sklearn.linear_model import LassoCV
clf = LassoCV()
score = cross_val_score(estimator = clf, X = X, y = Y, cv = KFold(n_splits = 3, random_state = 100), n_jobs = -1, \
                        scoring = "neg_mean_squared_error")
np.mean([np.sqrt(-x) for x in score])

我正在尝试以类似的方式使用TPOT,如下:

from tpot import TPOTRegressor
tpot = TPOTRegressor(generations=20, population_size=100, verbosity=2)

score = cross_val_score(estimator = tpot, X = X, y = Y, cv = KFold(n_splits = 3, random_state = 100), n_jobs = -1, \
                        scoring = "neg_mean_squared_error")
np.mean([np.sqrt(-x) for x in score])

TPOT 启动但随后出现如下酸洗错误:

PicklingError: Can't pickle <type 'instancemethod'>: it's not found as __builtin__.instancemethod

知道为什么会发生这种情况/如何让 TPOT 发挥出色?

谢谢!

【问题讨论】:

  • clf =TPOTClassifier(generations=5, population_size=20, cv=5, random_state=42, verbosity=2) 怎么样而不是使用回归。然后使用 clf.score(X_test, y_test)
  • @Mr_U4913 我相信我应该使用 TPOTRegressor,因为这是一个回归问题

标签: python pandas machine-learning scikit-learn tpot


【解决方案1】:

尝试使用:tpot.fitted_pipeline_

from tpot import TPOTRegressor
tpot = TPOTRegressor(generations=20, population_size=100, verbosity=2)

score = cross_val_score(estimator = tpot.fitted_pipeline_, X = X, y = Y, cv = KFold(n_splits = 3, random_state = 100), n_jobs = -1, \
                        scoring = "neg_mean_squared_error")
np.mean([np.sqrt(-x) for x in score])

【讨论】:

    【解决方案2】:

    如果您使用的是 Python 2, 试试:

    import dill  
    

    这样 lambda 函数可以被腌制......为我工作......

    在 Python 3 中,您可能需要:

    import dill as pickle
    

    【讨论】:

    • 这对我没用:仍然说:PicklingError: Can't pickle :找不到 tpot.operator_utils.GradientBoostingRegressor__alpha
    猜你喜欢
    • 1970-01-01
    • 2014-09-15
    • 2021-06-24
    • 1970-01-01
    • 2018-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-01
    相关资源
    最近更新 更多