Skip to content

Commit 4792359

Browse files
committed
machine_learning\multilayer_perceptron_classifier.py
1 parent 9db1312 commit 4792359

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

machine_learning/multilayer_perceptron_classifier.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22
Multilayer Perceptron (MLP) Classifier Example
33
44
A Multilayer Perceptron (MLP) is a type of feedforward artificial neural network
5-
that consists of at least three layers of nodes: an input layer, one or more hidden layers,
6-
and an output layer. Each node (except for the input nodes) is a neuron that uses a nonlinear
7-
activation function.
5+
that consists of at least three layers of nodes: an input layer, one or more hidden
6+
layers, and an output layer. Each node (except for the input nodes) is a neuron
7+
that uses a nonlinear activation function.
88
99
Mathematical Concept:
1010
---------------------
11-
MLPs learn a function f(·): R^m → R^o by training on a dataset, where m is the number of input features
12-
and o is the number of output classes. The network adjusts its weights using backpropagation to minimize
13-
the difference between predicted and actual outputs.
11+
MLPs learn a function f(·): R^m → R^o by training on a dataset, where m is the
12+
number of input features and o is the number of output classes. The network
13+
adjusts its weights using backpropagation to minimize the difference between
14+
predicted and actual outputs.
1415
1516
Practical Use Cases:
1617
--------------------
1718
- Handwritten digit recognition (e.g., MNIST dataset)
1819
- Binary and multiclass classification tasks
19-
- Predicting outcomes based on multiple features (e.g., medical diagnosis, spam detection)
20+
- Predicting outcomes based on multiple features
21+
(e.g., medical diagnosis, spam detection)
2022
2123
References:
2224
-----------
@@ -32,14 +34,16 @@
3234
[0, 1]
3335
"""
3436

35-
from typing import List, Sequence
37+
from collections.abc import Sequence
38+
3639
from sklearn.neural_network import MLPClassifier
3740

41+
3842
def multilayer_perceptron_classifier(
3943
train_features: Sequence[Sequence[float]],
4044
train_labels: Sequence[int],
4145
test_features: Sequence[Sequence[float]],
42-
) -> List[int]:
46+
) -> list[int]:
4347
"""
4448
Train a Multilayer Perceptron classifier and predict labels for test data.
4549
@@ -70,6 +74,8 @@ def multilayer_perceptron_classifier(
7074
predictions = clf.predict(test_features)
7175
return list(predictions)
7276

77+
7378
if __name__ == "__main__":
7479
import doctest
75-
doctest.testmod()
80+
81+
doctest.testmod()

0 commit comments

Comments
 (0)