cheatsheet

Scikit-learn Cheatsheet: Neural Networks

Scikit-learn provides basic neural network models (Multi-layer Perceptrons) and Restricted Boltzmann Machines.

What can be done?

Key Algorithms

  1. MLPClassifier / MLPRegressor:
    • Multi-layer Perceptron (Vanilla Feedforward NN).
    • Solvers:
      • 'adam': Default. Works well on large datasets.
      • 'lbfgs': Optimizer for small datasets (faster and more stable).
      • 'sgd': Standard stochastic gradient descent.
  2. BernoulliRBM:
    • Unsupervised generative model with binary hidden and visible units.
    • Typically used in a pipeline before a linear classifier.

Parameters to Tune

Computational Complexity

Code Snippet: MLP & RBM

from sklearn.neural_network import MLPClassifier, BernoulliRBM
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression

# 1. Multi-layer Perceptron
mlp = MLPClassifier(
    hidden_layer_sizes=(100, 50), 
    activation='relu', 
    solver='adam', 
    alpha=0.0001,
    max_iter=500,
    random_state=1
)
mlp.fit(X_train, y_train)

# 2. RBM Feature Extraction + Logistic Regression
rbm = BernoulliRBM(n_components=100, learning_rate=0.01, n_iter=20)
logistic = LogisticRegression(C=100)

pipe = Pipeline(steps=[('rbm', rbm), ('logistic', logistic)])
pipe.fit(X_train, y_train)

Credits: This cheatsheet is based on the scikit-learn documentation and examples, which are licensed under the BSD 3-Clause License. Copyright (c) 2007 - 2026 The scikit-learn developers. All rights reserved.