2017-06-28 80 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])