mljar / mljar-supervised

Python package for AutoML on Tabular Data with Feature Engineering, Hyper-Parameters Tuning, Explanations and Automatic Documentation
https://mljar.com
MIT License
3.05k stars 409 forks source link

Easy to change classifier #424

Closed elcolie closed 3 years ago

elcolie commented 3 years ago
automl = AutoML()
automl.fit(X_train, y_train)

predictions = automl.predict(X_test)

It comes with best classifier. Then I have to change best_model in params.json to use another classifier.

Is it possible to do like automl.dtree.predict(X_test)?

pplonski commented 3 years ago

the steps to change the model for predictions:

  1. train model
    automl = AutoML(results_path="my_automl")
    automl.fit(X_train, y_train)
  2. Edit params.json file and change the best_model
  3. Reload AutoML and compute predictions:
    utoml = AutoML(results_path="my_automl")
    automl.predict(X)
elcolie commented 3 years ago

Not quite easy, but it is okay 😓

elcolie commented 3 years ago

@pplonski It does not work. It warns

2021-06-25 16:08:08,223 supervised.exceptions ERROR This model has not been fitted yet. Please call `fit()` first.
---------------------------------------------------------------------------
AutoMLException                           Traceback (most recent call last)
<ipython-input-47-4b2ef145420a> in <module>
----> 1 sixth_prediciton = sixth_ml.predict_all(X_test)

/i/pyenv/versions/py-default/lib/python3.8/site-packages/supervised/automl.py in predict_all(self, X)
    394 
    395         """
--> 396         return self._predict_all(X)
    397 
    398     def score(self, X, y=None, sample_weight=None):

/i/pyenv/versions/py-default/lib/python3.8/site-packages/supervised/base_automl.py in _predict_all(self, X)
   1328     def _predict_all(self, X):
   1329         # Make and return predictions
-> 1330         return self._base_predict(X)
   1331 
   1332     def _score(self, X, y=None, sample_weight=None):

/i/pyenv/versions/py-default/lib/python3.8/site-packages/supervised/base_automl.py in _base_predict(self, X, model)
   1240 
   1241         if model is None:
-> 1242             raise AutoMLException(
   1243                 "This model has not been fitted yet. Please call `fit()` first."
   1244             )

AutoMLException: This model has not been fitted yet. Please call `fit()` first.

And show error

pplonski commented 3 years ago

It will be added in https://github.com/mljar/mljar-supervised/issues/423 - closing as a duplicate.