EpistasisLab / tpot

A Python Automated Machine Learning tool that optimizes machine learning pipelines using genetic programming.
http://epistasislab.github.io/tpot/
GNU Lesser General Public License v3.0
9.72k stars 1.57k forks source link

AttributeError: 'TPOTRegressor' object has no attribute '_set_param_recursive' #955

Closed lmsanch closed 4 years ago

lmsanch commented 4 years ago

I am running version 0.11.0 of TPOT and had developed a function that leveraged some of the properties of tpot after training.

deap_pipeline = creator.Individual.from_string(pipeline_string, tpot_obj._pset)
sklearn_pipeline = tpot_obj._toolbox.compile(expr=deap_pipeline)
sklearn_pipeline_str = generate_pipeline_code(expr_to_tree(deap_pipeline, tpot_obj._pset), tpot_obj.operators)
tpot_obj._set_param_recursive(sklearn_pipeline.steps, 'random_state', 42)
pipe_list.append(sklearn_pipeline_str)

I was using `tpot_obj._set_param_recursive(sklearn_pipeline.steps, 'random_state', 42) similar to the solution that @weixuanfu posted a while ago.

tpot_obj = TPOTRegessror(cv=5, scoring='r2')
tpot_obj.fit(X, y)
sklearn_pipeline = tpot_obj.fitted_pipeline_
# reset random state of all operators in the pipeline 
tpot_obj._set_param_recursive(sklearn_pipeline.steps, 'random_state', 42)
cv_scores = cross_val_score(sklearn_pipeline, X, y, cv=5, scoring='r2', verbose=0)
mean_cv_scores = np.mean(cv_scores)

Originally posted by @weixuanfu in https://github.com/EpistasisLab/tpot/issues/886#issuecomment-510461961

he issue I have now is that my code does not work because it seems that ._set_param_recursive was removed. Is there any other attribute that performs the same task? How can I replicate the functionality of the line above with whatever replaced _set_param_recursive? If there isn't anything, how can I downgrade tpot to the last version that had ._set_param_recursive? Thanks

weixuanfu commented 4 years ago

@lmsanch there are some related updates in version 0.11 (please see the release log here).

The set_param_recursive function has been moved to tpot.export_utils. You may import it via from tpot.export_utils import set_param_recursive. About random_state, TPOT v0.11 does not use fixed random seed 42 for evaluating pipelines but use the random seed set by random_state parameter instead. If random_state=None, then the results may not be reproduced.

lmsanch commented 4 years ago

Thanks