AutoML in nnetsauce (randomized and quasi-randomized nnetworks)

This article was first published on T. Moudiki's Webpage - Python , and kindly contributed to python-bloggers. (You can report issue about the content on this page here)
Want to share your content on python-bloggers? click here.

Content:

  1. Installing nnetsauce for Python
  2. Classification
  3. Regression

Disclaimer: I have no affiliation with the lazypredict project.

A few days ago, I stumbled accross a cool Python package called lazypredict. Pretty well-designed, working, and relying on scikit-learn’s design.

With lazypredict, you can rapidly have an idea of which scikit-learn model (can also work with xgboost’s and lightgbm’s scikit-learn-like interfaces) performs best on a given data set, with a little preprocessing, and without hyperparameters’ tuning (this is important to note).

I thought something similar could be beneficial to nnetsauce’s classes CustomClassifier, CustomRegressor (see detailed examples below, and interact with the graphs) and MTS. For now.

So far, in nnetsauce (Python version), I adapted the lazy prediction feature to regression (CustomRegressor) and classification (CustomClassifier). Not for univariate and multivariate time series forecasting (MTS) yet. You can try it from a GitHub branch.

2 – Installation

!pip install git+https://github.com/Techtonique/nnetsauce.git@lazy-predict

2 – Classification

2 – 1 Loading the Dataset

import nnetsauce as ns
from sklearn.datasets import load_breast_cancer

data = load_breast_cancer()
X = data.data
y= data.target

2 – 2 Building the classification model using LazyPredict

from sklearn.model_selection import train_test_split

# split the data
X_train, X_test, y_train, y_test = train_test_split(X, y,
                                                    test_size=0.2,
                                                    random_state=123)

# build the lazyclassifier
clf = ns.LazyClassifier(verbose=0, ignore_warnings=True,
                        custom_metric=None,
                        n_hidden_features=10,
                        col_sample=0.9)

# fit it
models, predictions = clf.fit(X_train, X_test, y_train, y_test)
100%|██████████| 27/27 [00:09<00:00,  2.71it/s]
# print the best models
display(models)
AccuracyBalanced AccuracyROC AUCF1 ScoreTime Taken
Model
LogisticRegression0.990.990.990.990.69
LinearSVC0.980.980.980.980.33
SGDClassifier0.980.980.980.980.19
Perceptron0.980.980.980.980.15
LabelPropagation0.980.980.980.980.33
LabelSpreading0.980.980.980.980.43
SVC0.980.980.980.980.16
RandomForestClassifier0.980.980.980.980.66
ExtraTreesClassifier0.980.980.980.980.40
KNeighborsClassifier0.980.980.980.980.34
DecisionTreeClassifier0.970.970.970.970.53
PassiveAggressiveClassifier0.970.970.970.970.21
LinearDiscriminantAnalysis0.970.960.960.970.19
CalibratedClassifierCV0.970.960.960.970.24
AdaBoostClassifier0.960.960.960.961.31
BaggingClassifier0.950.950.950.950.63
RidgeClassifier0.960.940.940.960.27
RidgeClassifierCV0.960.940.940.960.18
QuadraticDiscriminantAnalysis0.950.940.940.950.81
ExtraTreeClassifier0.940.930.930.940.12
NuSVC0.940.910.910.940.29
GaussianNB0.930.910.910.930.17
BernoulliNB0.920.900.900.920.31
NearestCentroid0.920.890.890.920.24
DummyClassifier0.640.500.500.500.27

model_dictionary = clf.provide_models(X_train, X_test, y_train, y_test)
model_dictionary['LogisticRegression']
Pipeline(steps=[('preprocessor',
                 ColumnTransformer(transformers=[('numeric',
                                                  Pipeline(steps=[('imputer',
                                                                   SimpleImputer()),
                                                                  ('scaler',
                                                                   StandardScaler())]),
                                                  Int64Index([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
            17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
           dtype='int64')),
                                                 ('categorical_low',
                                                  Pipeline(steps=[('imputer',
                                                                   SimpleImputer(fill_value='missing',
                                                                                 strategy='c...
                                                                   OneHotEncoder(handle_unknown='ignore',
                                                                                 sparse=False))]),
                                                  Int64Index([], dtype='int64')),
                                                 ('categorical_high',
                                                  Pipeline(steps=[('imputer',
                                                                   SimpleImputer(fill_value='missing',
                                                                                 strategy='constant')),
                                                                  ('encoding',
                                                                   OrdinalEncoder())]),
                                                  Int64Index([], dtype='int64'))])),
                ('classifier',
                 CustomClassifier(col_sample=0.9, n_hidden_features=10,
                                  obj=LogisticRegression(random_state=42)))])

In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.