Skip to content

Commit 1e16b6b

Browse files
committed
machine_learning\multilayer_parceptron
1 parent afac255 commit 1e16b6b

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

machine_learning/multilayer_perceptron_classifier.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Multilayer Perceptron (MLP) Classifier Example
2+
Multilayer Perceptron (MLP) Classifier
33
44
A Multilayer Perceptron (MLP) is a type of feedforward artificial neural network
55
that consists of at least three layers of nodes: an input layer, one or more hidden
@@ -20,6 +20,21 @@
2020
- Predicting outcomes based on multiple features
2121
(e.g., medical diagnosis, spam detection)
2222
23+
Advantages:
24+
-----------
25+
- Can learn non-linear decision boundaries
26+
- Works well with complex pattern recognition
27+
- Flexible architecture for various problem types
28+
29+
Limitations:
30+
------------
31+
- Requires careful tuning of hyperparameters
32+
- Sensitive to feature scaling
33+
- Can overfit on small datasets
34+
35+
Time Complexity: O(n_samples * n_features * n_layers * n_epochs)
36+
Space Complexity: O(n_features * n_hidden_units + n_hidden_units * n_classes)
37+
2338
References:
2439
-----------
2540
- https://en.wikipedia.org/wiki/Multilayer_perceptron
@@ -62,13 +77,17 @@ def multilayer_perceptron_classifier(
6277
>>> X = [[0.0, 0.0], [1.0, 1.0], [1.0, 0.0], [0.0, 1.0]]
6378
>>> y = [0, 1, 0, 0]
6479
>>> multilayer_perceptron_classifier(X, y, [[0.0, 0.0], [1.0, 1.0]])
65-
# Multiple possible outputs True
80+
[0, 1]
6681
"""
6782
if len(train_features) != len(train_labels):
6883
raise ValueError("Number of training samples and labels must match.")
6984

7085
clf = MLPClassifier(
71-
solver="lbfgs", alpha=1e-5, hidden_layer_sizes=(5, 2), random_state=1
86+
solver="lbfgs",
87+
alpha=1e-5,
88+
hidden_layer_sizes=(5, 2),
89+
random_state=42, # Fixed for deterministic results
90+
max_iter=1000, # Ensure convergence
7291
)
7392
clf.fit(train_features, train_labels)
7493
predictions = clf.predict(test_features)

0 commit comments

Comments
 (0)