A classifier that’s very accurate (and deep)

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.

Version v0.15.0 of nnetsauce is now available on your favorite platforms: PyPI, conda and GitHub for Python; R universe and GitHub for R.

The changes in this version are mostly related to Automated Machine learning (AutoML):

  • lazy prediction for classification and regression: see this post for more details on the subject (and remember to use pip install nnetsauce directly, instead of installing from a GitHub branch named lazy-predict)
  • lazy prediction for multivariate time series (MTS): see this post for more details on the subject (and remember to use pip install nnetsauce directly, instead of installing from a GitHub branch named lazy-predict)
  • lazy prediction with deep quasi-randomized nnetworks will be described in this post

Note that in the example below, for the offically released version (v0.15.0), Gradient boosting classifiers are available. This doesn’t change the best model chosen by the algorithm (which is never Gradient boosting, because the deep model is already doing “too much”). Not sure if Gradient boosting will be kept as a default model here because, in this context, it’s relatively slow.

To finish, for Windows users, if you run into issues when trying to install nnetsauce (but you shouldn’t): remember that you can use the Windows Subsystem for Linux (WSL).

Contents

Here is a jupyter notebook allowing you to reproduce these results. Do not hesitate
to modify these examples by choosing – in LazyDeepClassifier – a different number of layers n_layers, or the number of
engineered features per layer, n_hidden_features.

0 – Install and import packages

top

!pip install nnetsauce --upgrade
import os
import nnetsauce as ns
import matplotlib.pyplot as plt
from sklearn.datasets import load_breast_cancer, load_iris, load_wine, load_digits
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report, ConfusionMatrixDisplay
from time import time

1 – breast cancer data

top

data = load_breast_cancer()
X = data.data
y= data.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = .2, random_state = 123)

clf = ns.LazyDeepClassifier(n_layers=3, verbose=0, ignore_warnings=True)
start = time()
models, predictions = clf.fit(X_train, X_test, y_train, y_test)
print(f"\n\n Elapsed: {time()-start} seconds \n")
model_dictionary = clf.provide_models(X_train, X_test, y_train, y_test)

display(models)
100%|██████████| 27/27 [00:44<00:00,  1.65s/it]



 Elapsed: 44.49836850166321 seconds 
AccuracyBalanced AccuracyROC AUCF1 ScoreTime Taken
Model
Perceptron0.990.990.990.992.15
SGDClassifier0.980.980.980.981.99
RandomForestClassifier0.980.980.980.982.76
PassiveAggressiveClassifier0.980.980.980.981.89
LogisticRegression0.980.980.980.981.14
ExtraTreesClassifier0.980.980.980.983.13
BaggingClassifier0.970.970.970.971.62
LabelPropagation0.970.970.970.971.69
LabelSpreading0.970.970.970.971.08
AdaBoostClassifier0.970.970.970.973.42
LinearSVC0.970.970.970.971.65
KNeighborsClassifier0.970.970.970.971.07
SVC0.970.960.960.971.07
CalibratedClassifierCV0.970.960.960.971.82
DecisionTreeClassifier0.960.960.960.961.50
QuadraticDiscriminantAnalysis0.960.950.950.961.16
LinearDiscriminantAnalysis0.960.950.950.961.39
ExtraTreeClassifier0.960.940.940.960.83
RidgeClassifier0.960.940.940.963.15
RidgeClassifierCV0.960.940.940.961.51
GaussianNB0.930.900.900.931.50
NearestCentroid0.930.900.900.933.00
NuSVC0.930.900.900.931.27
BernoulliNB0.910.890.890.911.15
DummyClassifier0.640.500.500.500.96

model_dictionary["Perceptron"]
CustomClassifier(obj=CustomClassifier(obj=CustomClassifier(obj=Perceptron(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.