2017-06-28 55 views
3

我有一个名为X的数据框和一组名为Y的目标值。TPOT:使用TPOTRegressor时酸洗错误

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

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玩得好吗?

谢谢!

+0

什么约CLF = TPOTClassifier(代= 5,population_size = 20,CV = 5, random_state = 42,冗长度= 2),而不是使用使用regression.then clf.score(X_test,y_test) –

+0

@ Mr_U4913我应该使用TPOTRegressor,我相信,因为它是一个回归问题 – bclayman

回答

1

如果您正在使用Python 2, 尝试:

import dill 

使lambda函数可以腌制....为我工作...

在Python 3

,您可能需要:

import dill as pickle 
+0

这不适用于我:仍然说:PicklingError:不能pickle :它没有被找到作为tpot.operator_utils.GradientBoostingRegressor__alpha –

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])