Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions machine_learning/mlp_activation_comparison.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import matplotlib.pyplot as plt
from sklearn.neural_network import MLPClassifier
from sklearn.datasets import make_moons
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

Check failure on line 5 in machine_learning/mlp_activation_comparison.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

machine_learning/mlp_activation_comparison.py:1:1: I001 Import block is un-sorted or un-formatted

Check failure on line 5 in machine_learning/mlp_activation_comparison.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

machine_learning/mlp_activation_comparison.py:1:1: I001 Import block is un-sorted or un-formatted

X, y = make_moons(n_samples=500, noise=0.2, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: X_train

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: X_test

X, y, test_size=0.3, random_state=42
)

activations = ["logistic", "tanh", "relu"]
results = {}

for act in activations:
clf = MLPClassifier(
hidden_layer_sizes=(10, 5),
activation=act,
solver="adam",
max_iter=1000,
random_state=42,
)
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
acc = accuracy_score(y_test, y_pred)
results[act] = acc

plt.bar(results.keys(), results.values())
plt.title("Activation Function Comparison")
plt.ylabel("Accuracy")
plt.show()
Loading