This repository contains the necessary code and tools to upgrade DecisionTreeClassifier
models from scikit-learn==1.3.x
or lower to the newer versions of scikit-learn
.
- Model Converter: Extracts and upgrades components of a Scikit-learn model for compatibility with newer versions than
1.3.x
. - Model Upgrader: Reconstructs and updates the model using the modified components.
- Open-source and easy-to-use CLI commands.
Clone this repository:
git clone https://github.com/Infinitode/repo-name.git
cd repo-name
You can modify the Python script files to convert and upgrade your models. These files are located in new_environment
and old_environment
respectively.
1. Set up old_environment
- Start with the
old_environment
. - You'll need to install the older versions of both
scikit-learn
andnumpy
in this environment. - Make sure to use the same Python version your model was saved in.
Note
It needs to be similar to your original
environment in which you saved your model.
2. Modify the script under old_environment
and run
Modify the script file, and run it, it will convert your model and store the files that we need for later.
3. Set up new_environment
- Create a new environment for
new_environment
. - Install the latest/target versions of
scikit-learn
andnumpy
. - Use the latest/target Python version.
4. Modify the script under new_environment
and run
Modify the script file and run it. It will use the files created in step 2
to create a new model, that is compatible with your chosen version.
You can use the CLI tools to quickly convert your model files.
model_converter.py
- Initial conversion. Extracts and upgrades components of the model for compatibility with newer versions than1.3.x
. Works inoriginal environment
(olderscikit-learn
, etc.).model_upgrader.py
- Final conversion. Reconstructs and updates the model using the modified components. Works innew environment
(updatedscikit-learn
, etc.)
python model_converter.py \
--model_path path/to/original_model.pkl \
--shell_path path/to/classifier_shell.pkl \
--tree_state_path path/to/tree_state.pkl \
--upgraded_tree_state_path path/to/upgraded/tree_state.pkl \
--model_txt_path path/to/model.txt
Explanation of arguments:
--model_path
: Path to your saved model.--shell_path
: Output path for the classifier shell (e.g. shell.pkl).--tree_state_path
: Output path for the tree state (e.g. tree_state.pkl).--upgraded_tree_state_path
: Output path for the upgraded tree state (e.g. upgraded_tree_state.pkl).--model_txt_path
: Output path for the model's inputs and outputs (e.g. model.txt).
python model_upgrader.py \
--shell_path path/to/classifier_shell.pkl \
--upgraded_tree_state_path path/to/upgraded/tree_state.pkl \
--model_txt_path path/to/model.txt \
--output_path path/to/updated_classifier.pkl
Explanation of arguments:
--shell_path
: Path to the classifier shell (e.g. shell.pkl).--upgraded_tree_state_path
: Path to the upgraded tree state (e.g. upgraded_tree_state.pkl).--model_txt_path
: Path to the model's inputs and outputs (e.g. model.txt).--output_path
: Output path for the final model (e.g. upgraded_model.pkl).
Tip
You can use --help
in the commandline for usage instructions.
python model_upgrader.py --help
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request with your changes.
This project was inspired by the need to adapt Scikit-learn models to newer versions and ensure compatibility in various environments.