Run All Machine Learning models in Once

Share this post

This library offers you the possibility to evaluate many machine learning models at the same time,
using sk-learn and saving a lot of time and coding.

In this blog, we will see how we can use multiple models at once for prediction using Lazy Predict library.

  1. CLASSIFICATION MODELS
  2. CLASSIFICATION MODELS

CLASSIFICATION MODELS

First, you need to install the library

# Installation
pip install lazypredict
# Imports
from lazypredict.Supervised import LazyClassifier
from sklearn.model_selection import train_test_split
import pandas as pd
from sklearn import datasets
# Load our toy dataset
df = datasets.load_breast_cancer()
type(df)
# Transform to Pandas dataframe if you want to explore the data
df2 = pd.DataFrame( df.data , columns=df.feature_names)
df2['target'] = df.target
df2.head()
# X and Y
X, y = df.data, df.target
# Train Test Split
X_train, X_test, y_train, y_test = train_test_split(X, y,test_size=0.2,random_state=12)

Here is where the magic happens:

# Fit all models
clf = LazyClassifier(predictions=True)
models, predictions = clf.fit(X_train, X_test, y_train, y_test)
models

REGRESSION MODELS

from lazypredict.Supervised import LazyRegressor
# Load toy dataset
boston = datasets.load_boston()
# X and y split
X, y = boston.data, boston.target
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=.2,random_state=12)
# Fit all regression models
reg = LazyRegressor(predictions=True)
models, predictions = reg.fit(X_train, X_test, y_train, y_test)
models

Share this post

5 thoughts on “Run All Machine Learning models in Once”

Leave a Comment

Your email address will not be published. Required fields are marked *