Skip to main content
MahiDev — Learn. Build. Become AI-ready.

Lesson 37

Artificial Neural Network

Stack weighted layers and nonlinearities so a classifier can learn a boundary that is not a single straight cut. One example is on this page.

Intermediate12 min
Artificial Neural Network MahiDev

What You Will Learn

  • Idea
  • Example
  • When to use it

Idea

A small neural network multiplies inputs by weights, adds a bias, and applies a nonlinearity such as ReLU. A second layer mixes those hidden units into class scores. Training nudges the weights so the scores match the labels. This page is the classical multilayer perceptron, not a deep network.

Example

python
import numpy as np
from sklearn.neural_network import MLPClassifier

X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]], dtype=float)
y = np.array([0, 1, 1, 0])
model = MLPClassifier(hidden_layer_sizes=(4,), max_iter=400, learning_rate_init=0.1, random_state=0)
label = model.fit(X, y).predict([[0, 1]])[0]
print(f"label: {int(label)}")

Output:

text
label: 1

When to use it

  • Use a small network when interactions are real and a linear model underfits.
  • Standardize inputs. Unscaled columns make the first weight update uneven.
  • Deeper image and text models belong on the deep-learning path, not in this classical page.

Loading playground…