Train all Classification or Regression models in one line of Python Code | by Satyam Kumar | Towards Data Science

Automated Machine Learning (Auto-ML) refers to automating the components of a data science model development pipeline. AutoML reduces the workload of a data scientist and speeds up the workflow. AutoML can be used to automate various pipeline components, including data understanding, EDA, data processing, model training, hyperparameter tuning, etc.
For an end-to-end machine learning project, the complexity of each of the pipeline components depends on the project. There are various AutoML open source libraries that speed up each of the pipeline components. Read this article to know 8 such AutoML libraries to automate the machine learning pipeline.
In this article, we will discuss how to automate the model training process using an open-source Python library LazyPredict.
LazyPredict is an open-source Python library that automates the model training pipeline and speeds up the workflow. LazyPredict trains around 30 classification models for a classification dataset and trains around 40 regression models for a regression dataset.
LazyPredict returns with the trained models along with its performance metric without writing much code. One can compare the performance metrics of each model and tune the best model to further improve the performance.
LazyPredict can be installed from the PyPl library using:
pip install lazypredict
Post-installation, one can import the library to perform auto-training of classification and regression models.
from lazypredict.Supervised import LazyRegressor, LazyClassifier
LazyPredict support both classification and regression problems, so I will discuss a demonstration of both tasks
Boston Housing (Regression) and Titanic (Classification) dataset are used for the demonstration of the LazyPredict library.
Usage of LazyPredict is very intuitive and similar to scikit-learn. First, create an instance of the estimator LazyClassifier for the classification task. One can pass custom metrics for evaluation, by default each of the models will be evaluated on Accuracy, ROC AUC score, F1 score.
Before proceeding to lazypredict model training, one must read the dataset and process it to make it fit for training.
After feature engineering and splitting the data into train test data, we can proceed with model training using LazyPredict.
# LazyClassifier Instance and fiting datacls= LazyClassifier(ignore_warnings=False, custom_metric=None)models, predictions = cls.fit(X_train, X_test, y_train, y_test)
Similar to classification model training, LazyPredict comes with automated model training for regression datasets. The implementation is similar to the classification task, with a change in the instance LazyRegressor.
reg = LazyRegressor(ignore_warnings=False, custom_metric=None)models, predictions = reg.fit(X_train, X_test, y_train, y_test)
Observing the above performance metrics, the AdaBoost classifier is the best performing model for classification tasks and the GradientBoostingRegressor model is the best performing model for regression tasks.
In this article, we have discussed the implementation of the LazyPredict library that can train around 70 classification and regression models in few lines of Python code. It is a very handy tool, as it gives an overall picture of how is the model performing, and one can compare the performance of each of the models.
Each model is trained with its default parameters, as it does not perform hyperparameter tuning. After choosing the best performing model, the developer can tune the model to improve the performance further.
Read the below-mentioned article to know 8 such AutoML libraries similar to LazyPredict.
medium.com
[1] LazyPredict Documentation: https://pypi.org/project/lazypredict/
Thank You for Reading