4

我有一个称为 DataFrameX和一组称为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 发挥出色吗?

谢谢!

4

2 回答 2

1

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

import dill  

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

在 Python 3 中,您可能需要:

import dill as pickle
于 2017-07-10T10:31:59.393 回答
0

尝试使用: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])
于 2017-07-25T10:58:03.737 回答