A neural network is built from layers of simple computational units ("neurons") connected together — individually simple, but capable of learning remarkably complex patterns when stacked in sufficient depth and width.
from sklearn.neural_network import MLPClassifier
model = MLPClassifier(
hidden_layer_sizes=(64, 32), # two hidden layers: 64 neurons, then 32 neurons
activation="relu", # non-linear activation function
max_iter=500,
random_state=42,
)
model.fit(X_train_scaled, y_train) # neural networks are especially sensitive to unscaled features
predictions = model.predict(X_test_scaled)
A basic neural network consists of an input layer (one neuron per feature), one or more hidden layers, and an output layer (predicting the target). Each neuron computes a weighted sum of its inputs, adds a bias term, and passes the result through a non-linear activation function (like ReLU) — this non-linearity is essential, since stacking purely linear operations, no matter how many layers, would mathematically collapse back into a single linear transformation, unable to represent the kind of complex, non-linear patterns neural networks are actually good at.
Training a neural network means finding the weights that minimize prediction error, done through an algorithm called backpropagation: the network makes a prediction, measures how wrong it was, then propagates that error backward through the layers, adjusting each weight slightly in the direction that would have reduced the error — repeated over many iterations across the training data until the weights converge. MLPClassifier (Multi-Layer Perceptron) is scikit-learn's basic neural network implementation, sufficient for learning the core concepts and small problems, but real deep learning work — many layers, image/text/audio data, GPU acceleration — uses dedicated frameworks (TensorFlow, PyTorch) covered in the next lesson, which this notebook only introduces at a conceptual level.