Skip to content

How can I get/export a production model from a trained model (after refit) with autosklearn? #1467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
seraus opened this issue May 10, 2022 · 3 comments
Labels
enhancement A new improvement or feature question
Milestone

Comments

@seraus
Copy link

seraus commented May 10, 2022

Hello team,
I'm doing some tests with autosklearn and I would like to know I can get/export a trained autosklearn model for production use.
Could you please explain which is the process I have to follow?
Currently I am doing this:

automl = autosklearn.classification.AutoSklearnClassifier(
    time_left_for_this_task=3600,
    per_run_time_limit=1800,
    n_jobs=2,
    tmp_folder='/workspace/automl/unito/tmp',
    delete_tmp_folder_after_terminate=False,
    memory_limit=15240,
    resampling_strategy='cv',
    resampling_strategy_arguments={'folds':10},
    metric=autosklearn.metrics.f1_macro,
    scoring_functions=[
        autosklearn.metrics.accuracy,
        autosklearn.metrics.precision,
        autosklearn.metrics.recall,
        autosklearn.metrics.f1_macro
    ]
    include={'classifier': ['random_forestt']},
)
(...)

automl.fit(X_train, y_train, X_test, y_test, dataset_name='mydataset')

y_hat = automl.predict(X_test)
print("Accuracy score", sklearn.metrics.accuracy_score(y_test, y_hat))
print("F1 score", sklearn.metrics.f1_score(y_test, y_hat, average='macro'))
    

automl.refit(X, Y)
y_hat=automl.predict(X_test)
print("F1 score", sklearn.metrics.f1_score(y_test, y_hat, average='macro'))
print("Accuracy score", sklearn.metrics.accuracy_score(y_test, y_hat))

And then I'm using "automl "as a sklearn model and I'm logging it on mlflow but It is rather big (>1 GB).
Is this the right way or there are better ways?

For now I don't need an automatic way, a manual process is sufficient for my tests

Thanks a lot
Sergio

Short Question Description

A clear single sentence question we can try to help with?

With some extra context to follow it up. This way the question is clear for both you and us without it being lost in the paragraph.
Some useful information to help us with your question:

  • How did this question come about?
  • Would a small code snippet help?
  • What have you already looked at?

Before you ask, please have a look at the

  • Documentation
    • If it's related but not clear, please include it in your question with a link, we'll try to make it better!
  • Examples
    • Likewise, an example can answer many questions! However we can't cover all question with examples but if you think your question would benefit from an example, let us know!
  • Issues
    • We try to label all questions with the label Question, maybe someone has already asked. If the question is about a feature, try searching more of the issues. If you find something related but doesn't directly answer your question, please link to it with #(issue number)!

System Details (if relevant)

  • Which version of auto-sklearn are you using?

  • Are you running this on Linux / Mac / ... ?

  • auto-sklearn==0.14.6

  • linux centos 7

@seraus
Copy link
Author

seraus commented Jul 7, 2022

Hello, is there any news on this issue? Let me know if the question is unclear...
Thanks
Sergio

@eddiebergman eddiebergman added this to the v0.16 milestone Jul 8, 2022
@eddiebergman
Copy link
Contributor

Hi @seraus,

Many apologies, this slipped under the radar.

So currently we do not have any nice sklearn only export, i.e. there will always be a little auto-sklearn in there. It is something we want to get done eventually but we are currently quite busy with quite a few non-autosklearn things. I hope to be able to return to it in August when the conference period is over.

In the meantime, I recommend checking out automl.show_models() to get access to the models but a more comprehensive answer can be found here. It's not pretty and it's on v0.16 list of things to do.

We are always happy to receive contributions as well :)

Best,
Eddie

@eddiebergman eddiebergman added the enhancement A new improvement or feature label Jul 8, 2022
@seraus
Copy link
Author

seraus commented Aug 9, 2022

Thanks for the answers, @eddiebergman
I'll check the code you suggested
Regards
Sergio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new improvement or feature question
Projects
None yet
Development

No branches or pull requests

2 participants