我有一个名为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好好玩?
谢谢!
答案 0 :(得分:1)
如果您使用的是Python 2, 尝试:
import dill
所以lambda函数可以被腌制....为我工作......
在Python 3中,您可能需要:
import dill as pickle
答案 1 :(得分: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])