Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Implementation of LazyPredict library in Python and training of all classification or regression models

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Python in the implementation of the LazyPredict library and training all the classification or regression models, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

Automated machine learning (automatic ML) refers to the components of the automated data scientific model development pipeline. Automl reduces the workload of data scientists and speeds up the workflow. Automl can be used to automate a variety of pipeline components, including data understanding, EDA, data processing, model training, Quand parameter tuning and so on.

For an end-to-end machine learning project, the complexity of each pipeline component depends on the project. There are various source libraries that are automatically enabled to speed up each pipe component. Read this article to learn about 8 automatic list libraries to automate machine learning channels.

In this article, we will discuss how to use the open source Python library LazyPredict to automate the model training process.

What is lazypredict?

LazyPredict is an open source Python library that automates the model training pipeline and speeds up the workflow. LazyPredict has about 30 classification models in the classified data set, and lists 40 regression models in the regression data set.

LazyPredict returns to its performance metrics with well-trained models without having to write too much code. People can compare the performance indicators of each model and adjust the best model to further improve performance.

Installation:

Leazepredict can be installed using the pypl library:

Pip install lazypredict

After installation, you can import the library for automatic training of classification and regression models.

Usage of from lazypredict.Supervised import LazyRegressor, LazyClassifier:

LazyPredict supports classification and regression problems, so I will discuss the demonstration of two tasks

Boston Housing (regression) and Titanic (classified) DataSet are used to demonstrate the LazyPredict library.

Classification tasks:

The use of LazyPredict is very intuitive, similar to Scikit-learn. First, create an instance of the estimator LazyClassifier for the classification task. One can be evaluated by custom metrics, and by default, each model will be evaluated in terms of accuracy, ROC AUC scores, and F1 scores.

Before continuing with LazyPredict model training, you must read the dataset and process it to make it suitable for training.

Import pandas as pd from sklearn.model_selection import train_test_split # Read the titanic dataset df_cls = pd.read_csv ("titanic.csv") df_clsdf_cls = df_cls.drop (['PassengerId','Name','Ticket',' Cabin'], axis=1) # Drop instances with null records df_clsdf_cls = df_cls.dropna () # feature processing df_cls ['Sex'] = df_cls [' Sex'] .replace ({'male':1] 'female':0}) df_cls [' Embarked'] = df_cls ['Embarked'] .replace ({' Survived' Embarked' 0, 'Cruise Embarked' 1,' Qothers Embarked' 2}) # Creating train test split y = df_cls ['Survived'] X = df_cls.drop (columns= [' Survived'], axis=1) # Call train test split on the data and capture the results X_train, X_test, y_train, y_test = train_test_split (X, y, random_state=42, test_size=0.2)

After feature engineering and dividing the data into training test data, we can use LazyPredict for model training.

# LazyClassifier Instance and fiting data cls= LazyClassifier (ignore_warnings=False, custom_metric=None) models, predictions = cls.fit (X_train, X_test, y_train, y_test)

Return task:

Similar to classification model training, LazyPredict comes with automatic model training for regression data sets. Implement changes similar to the classification task in the instance LazyRegressor.

Import pandas as pd from sklearn.model_selection import train_test_split # read the data column_names = ['CRIM',' ZN', 'INDUS',' CHAS', 'NOX',' RM', 'AGE',' DIS', 'RAD',' TAX', 'PTRATIO',' Bamboo, 'LSTAT',' MEDV'] df_reg = pd.read_csv ("housing.csv", header=None, delimiter=r "\ s +" Names=column_names) # Creating train test split y = df_reg ['MEDV'] X = df_reg.drop (columns= [' MEDV'], axis=1) # Call train_test_split on the data and capture the results X_train, X_test, y_train, y_test = train_test_split (X, y, random_state=42, test_size=0.2) reg = LazyRegressor (ignore_warnings=False, custom_metric=None) models, predictions = reg.fit (X_train, X_test, y_train, y_test)

> (Image by Author), Performance metrics of 42 regression models for the Boston Housing dataset

Observing the above performance indicators, the Adaboost classifier is the best performance model for classification tasks, and the gradually enhanced replacement machine strategy model is the best performance model for regression tasks.

In this article, we have discussed the implementation of LazyPredict libraries that can train about 70 classification and regression models in a few lines of Python code. It is a very convenient tool because it gives the overall performance of the model and can compare the performance of each model.

Each model is trained as the default parameter because it does not perform HyperParameter adjustments. After selecting the best execution model, developers can adjust the model to further improve performance.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report