|
| 1 | +--- |
| 2 | +description: How MLJAR AutoML saves trained models, what is stored in results_path, how to load a trained run, and what files like learner_fold_0.catboost mean. |
| 3 | +social: |
| 4 | + cards_layout: default/variant |
| 5 | +--- |
| 6 | + |
| 7 | +# Save and Load models |
| 8 | + |
| 9 | +`mljar-supervised` saves trained models automatically during `AutoML.fit()`. |
| 10 | + |
| 11 | +In normal usage, you do **not** save or load individual learner files yourself. The main artifact is the whole AutoML directory stored in `results_path`. |
| 12 | + |
| 13 | +## The normal workflow |
| 14 | + |
| 15 | +Train a model: |
| 16 | + |
| 17 | +```python |
| 18 | +from supervised import AutoML |
| 19 | + |
| 20 | +automl = AutoML(results_path="AutoML_1") |
| 21 | +automl.fit(X, y) |
| 22 | +``` |
| 23 | + |
| 24 | +Later, load it again: |
| 25 | + |
| 26 | +```python |
| 27 | +from supervised import AutoML |
| 28 | + |
| 29 | +automl = AutoML(results_path="AutoML_1") |
| 30 | +``` |
| 31 | + |
| 32 | +If `results_path` already contains a trained AutoML run, it is loaded automatically. |
| 33 | + |
| 34 | +Then you can use it normally: |
| 35 | + |
| 36 | +```python |
| 37 | +predictions = automl.predict(X_test) |
| 38 | +``` |
| 39 | + |
| 40 | +## What is saved |
| 41 | + |
| 42 | +The full AutoML run is saved in the directory given by `results_path`. |
| 43 | + |
| 44 | +That directory contains items such as: |
| 45 | + |
| 46 | +- `params.json` |
| 47 | +- `leaderboard.csv` |
| 48 | +- top-level `README.md` |
| 49 | +- model subdirectories |
| 50 | +- preprocessing information |
| 51 | +- validation artifacts |
| 52 | +- algorithm-specific model files |
| 53 | + |
| 54 | +Think of `results_path` as the saved AutoML project directory. |
| 55 | + |
| 56 | +## Important file: `params.json` |
| 57 | + |
| 58 | +The key file used to recognize a trained AutoML directory is: |
| 59 | + |
| 60 | +```text |
| 61 | +params.json |
| 62 | +``` |
| 63 | + |
| 64 | +This is why `AutoML(results_path="AutoML_1")` can load a trained run automatically. The directory is the public loading entrypoint, not a single learner file. |
| 65 | + |
| 66 | +## What are files like `learner_fold_0.catboost`? |
| 67 | + |
| 68 | +Files such as: |
| 69 | + |
| 70 | +```text |
| 71 | +learner_fold_0.catboost |
| 72 | +``` |
| 73 | + |
| 74 | +are backend model files created by a specific algorithm. |
| 75 | + |
| 76 | +For example: |
| 77 | + |
| 78 | +- CatBoost models are stored in CatBoost-native format |
| 79 | +- scikit-learn based models use their own saved format |
| 80 | +- other learners can have their own native artifacts |
| 81 | + |
| 82 | +These files are **not** the main public interface of `mljar-supervised`. |
| 83 | + |
| 84 | +## Can I load `learner_fold_0.catboost` as JSON? |
| 85 | + |
| 86 | +No. |
| 87 | + |
| 88 | +A file like `learner_fold_0.catboost` is not a JSON file. It is a CatBoost model file in CatBoost’s native format. |
| 89 | + |
| 90 | +If you try to read it as JSON, it will not work. |
| 91 | + |
| 92 | +## Which object should I load in normal usage? |
| 93 | + |
| 94 | +In normal usage, load the full AutoML run by pointing `AutoML` at the saved directory: |
| 95 | + |
| 96 | +```python |
| 97 | +automl = AutoML(results_path="AutoML_1") |
| 98 | +``` |
| 99 | + |
| 100 | +This is the recommended way because it restores: |
| 101 | + |
| 102 | +- the best model selection |
| 103 | +- model orchestration |
| 104 | +- preprocessing pipeline |
| 105 | +- prediction interface |
| 106 | +- reports and metadata |
| 107 | + |
| 108 | +## Why not load learner files directly? |
| 109 | + |
| 110 | +You usually should not start from an individual learner file because `mljar-supervised` adds important context around the raw backend model: |
| 111 | + |
| 112 | +- preprocessing |
| 113 | +- target transformations |
| 114 | +- class label handling |
| 115 | +- model selection |
| 116 | +- ensemble or stacked-model logic |
| 117 | + |
| 118 | +Loading only the backend learner can bypass that context. |
| 119 | + |
| 120 | +## When direct loading can make sense |
| 121 | + |
| 122 | +Direct loading is advanced usage. |
| 123 | + |
| 124 | +You might do it if you want to inspect a backend model with the original library, for example CatBoost. But in that case, you are working at the backend-model level, not the full AutoML level. |
| 125 | + |
| 126 | +For standard prediction and reuse, load `results_path` with `AutoML`. |
| 127 | + |
| 128 | +## Where to inspect model details |
| 129 | + |
| 130 | +If your goal is to understand the trained model, start here: |
| 131 | + |
| 132 | +- the main `README.md` in `results_path` |
| 133 | +- the `README.md` inside each model subdirectory |
| 134 | +- feature importance plots |
| 135 | +- SHAP explanations, if enabled |
| 136 | +- leaderboard and structured reports |
| 137 | + |
| 138 | +This is usually more useful than reading backend model files directly. |
| 139 | + |
| 140 | +## FAQ |
| 141 | + |
| 142 | +### Do I need to call `save()` manually? |
| 143 | + |
| 144 | +No. Models are saved automatically during training. |
| 145 | + |
| 146 | +### How do I reload a trained AutoML run? |
| 147 | + |
| 148 | +Use: |
| 149 | + |
| 150 | +```python |
| 151 | +automl = AutoML(results_path="AutoML_1") |
| 152 | +``` |
| 153 | + |
| 154 | +### Can I import `.catboost` as JSON? |
| 155 | + |
| 156 | +No. It is not JSON. |
| 157 | + |
| 158 | +### What is the main saved artifact? |
| 159 | + |
| 160 | +The whole `results_path` directory. |
| 161 | + |
| 162 | +### What should I share or archive? |
| 163 | + |
| 164 | +Share or archive the full AutoML directory, not just a single learner file. |
| 165 | + |
| 166 | +## Related pages |
| 167 | + |
| 168 | +- [Preprocessing](preprocessing.md) |
| 169 | +- [Apps](apps.md) |
| 170 | +- [AutoML API](../api.md) |
0 commit comments