-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding mlp classifier code and tests, updating pre-commit file, and f…
…ixing pylint issues
- Loading branch information
1 parent
210cc86
commit 02c816f
Showing
14 changed files
with
952 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +0,0 @@ | ||
from .scratchml import * | ||
from .tests import * | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from scratchml.models.multilayer_perceptron import MLPClassifier | ||
from scratchml.utils import KFold | ||
from sklearn.datasets import make_classification | ||
|
||
|
||
def example_mlp_classifier() -> None: | ||
""" | ||
Practical example of how to use the Multilayer Perceptron (MLP) Classifier model. | ||
""" | ||
# generating a dataset for the classfication set | ||
X, y = make_classification( | ||
n_samples=1000, | ||
n_features=5, | ||
n_classes=2, | ||
n_clusters_per_class=1, | ||
n_informative=2, | ||
n_redundant=1, | ||
n_repeated=0, | ||
shuffle=True, | ||
) | ||
|
||
# splitting the data into training and testing using KFold | ||
folds = KFold(X, y, stratify=True, shuffle=True, n_splits=5) | ||
|
||
for fold, (train_indexes, test_indexes) in enumerate(folds): | ||
# getting the training and test sets | ||
X_train = X[train_indexes] | ||
y_train = y[train_indexes] | ||
|
||
X_test = X[test_indexes] | ||
y_test = y[test_indexes] | ||
|
||
# creating a MLP model instance | ||
mlp = MLPClassifier( | ||
loss_function="cross_entropy", | ||
hidden_layer_sizes=( | ||
32, | ||
64, | ||
), | ||
max_iter=100, | ||
batch_size=64, | ||
verbose=0, | ||
) | ||
|
||
# fitting the model | ||
mlp.fit(X=X_train, y=y_train) | ||
|
||
# assessing the model's performance | ||
score = mlp.score(X=X_test, y=y_test, metric="accuracy") | ||
|
||
print(f"The model achieved an accuracy score of {score} on the fold {fold}.\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
example_mlp_classifier() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.