Extend AutoML SDK with Python classifiers
You can extend AutoML SDK with a set of Python classifiers based on Scikit-learn, MXNet, and so on. The extension allows using ML algorithms implemented in Python with AutoML pipelines.
Here's a list of supported Python classifiers:
- GenericPythonClassifier
- DpLogisticRegressionClassifier
- DpSvmClassifier
- AdaBoostClassifier
- BaggingClassifier
- DecisionTreeClassifier
- ExtraTreeClassifier
- ExtraTreesClassifier
- GradientBoostingClassifier
- KNeighborsClassifier
- LinearSupportVectorClassifier
- LogisticRegression
- LogisticRegressionCV
- RandomForestClassifier
- StochasticGradientDescentClassifier
- MultinomialNaiveBayesClassifier
Set up development environment
This section contains instructions on setting up a local 3.7.9+ or 3.10.10+ Python development environment for proper building and running a custom model with Python support.
Install system packages
Choose a proper instruction to install required system packages (Python, libraries, compiler, and so on), depending on your operating system.
- Windows
- macOS
- Linux
On a Windows machine, follow the steps:
Install Visual Studio 2022 Community Edition.
Download and execute the following installer package:
On a Mac, follow the steps:
Download and execute the following installer package:
Install the Compiler (GNU Compiler Collection).
brew install gcc
On a Linux machine, choose one of the following options, depending on the Linux distribution you use.
Fedora
To install Python 3.10.10+, execute the following:
dnf install gcc python3.10.10 python3.10.10-devel libstdc++
Ubuntu
To install Python 3.10.10+, execute the following:
apt-get install gcc python3.10.10 python3.10.10-dev
As the final step, add the path to the installed Python directory to the PATH environment variable (if there is none yet):
Python 3.10.10 <python_installed_dir>
Install Python packages
Before installing Python packages, quit all instances of the terminal and start a new one or launch your IDE with an integrated terminal.
When you use the classifiers during model training, you may get a warning saying that there is no module named cv2 and torch. If you don't want to see the warning, install opencv-python and torch.
python3 -m pip install opencv-python==4.7.0.72
If you're planning to use a virtual environment, activate it before implementing Python classifiers.
To install all required Python packages, follow one of the instructions below, depending on your operating system:
- Windows
- Linux or macOS
To install the required Python package on Windows, run the following command:
python -m pip install --user --use-deprecated=legacy-resolver datasets==2.12.0 numpy==1.24.3 pandas==2.0.2 Pillow==9.5.0 pyarrow==12.0.0 pydantic==1.10.8 scikit-image==0.20.0 scikit-learn==1.2.2 scipy==1.10.1 six==1.16.0 torchvision==0.15.2 transformers==4.29.2 vowpalwabbit==9.8.0
You cannot run DP (dynamic programming) algorithms on Windows as they require the mxnet package that has compatibility issues with the numpy package.
To install the required Python package on Linux or MacOS, run the following command
python3 -m pip install --user --use-deprecated=legacy-resolver datasets==2.12.0 numpy==1.24.3 pandas==2.0.2 Pillow==9.5.0 pyarrow==12.0.0 pydantic==1.10.8 scikit-image==0.20.0 scikit-learn==1.2.2 scipy==1.10.1 six==1.16.0 torchvision==0.15.2 transformers==4.29.2 vowpalwabbit==9.8.0 mxnet==1.9.1
If you use a virtual environment, remove the --user flag from the above commands.
Use virtual environment
If you want to use a virtual environment, set the environment variable:
AUTOML_PYTHON_BIN=<path_to_python_binary_file>
To set the variable, follow the steps below, depending on your operating system:
- MacOS:
~/.bash_profile→export <VARIABLE>=<VALUE> - Linux:
~/.bashrc→export <VARIABLE>=<VALUE> - Windows: My Computer > Properties / Environment variables →
<VARIABLE>=<VALUE>
After that, quit and restart the terminal or your IDE.
If you use Nvidia GPU with configured CUDA, or Intel CPU with the mkl driver, or both, you can install mxnet-cu92, or mxnet-mkl, or mxnet-cu92mkl instead of the mxnet package.
Implement Python Classifiers
To implement a Python classifier, use the mlConfig Named Entity in your AutoML SDK configuration.
Here's an example of implementing RandomForestClassifier with default parameters:
@Named("mlConfig")
public Classifier mlConfig() {
return RandomForestClassifier.builder()
.build();
}
Here's an example of implementing RandomForestClassifier with custom parameters:
@Named("mlConfig")
public Classifier mlConfig() {
return RandomForestClassifier.builder()
.maxDepth(10)
.estimators(100)
.maxFeatures(MaxFeaturesType.LOG2)
.build();
}
Here's an example of GenericPythonClassifier—a generic customizable classifier. It can be used to set up any classifier manually by configuring the parameters and Python model name directly.
@Named("mlConfig")
public Classifier mlConfig() {
return GenericPythonClassifier.builder()
.modelName("sklearn.RandomForestClassifier")
.parameter("max_depth", 10)
.parameter("n_estimators", 100)
.parameter("random_state", 123)
.parameter("verbose", true)
.build()
}