Skip to content

feat(nn): [#230] Add MLPClassifier and MLPRegressor models#240

Open
vaishnavidesai09 wants to merge 2 commits into
pyfenn:mainfrom
vaishnavidesai09:feat/230-mlp-models
Open

feat(nn): [#230] Add MLPClassifier and MLPRegressor models#240
vaishnavidesai09 wants to merge 2 commits into
pyfenn:mainfrom
vaishnavidesai09:feat/230-mlp-models

Conversation

@vaishnavidesai09

Copy link
Copy Markdown

Summary

Adds MLPClassifier and MLPRegressor under fenn.nn.models.mlp, giving
users a scikit-learn-style API to train basic MLPs without writing Torch
code. Both estimators build a torch.nn.Sequential internally and delegate
all training to the existing ClassificationTrainer / RegressionTrainer
no training-loop code added.

API

  • MLPClassifier(hidden_layer_sizes, activation, solver, learning_rate_init, batch_size, max_iter, early_stopping, n_iter_no_change, validation_fraction, device).fit(X, y), .predict(X),
    .predict_proba(X), .score(X, y). Handles binary and multi-class;
    labels don't need pre-encoding.
  • MLPRegressor — same constructor, .fit, .predict, .score (R²).
  • Both exported from fenn.nn.models and fenn.nn.

Known issue found while testing

ClassificationTrainer.fit()'s validation branch doesn't reshape labels to
(-1, 1) for binary classification the way the training branch does, so
BCEWithLogitsLoss breaks as soon as a val_loader is passed with
num_classes == 2. I didn't fix it here since this module shouldn't contain
training-loop code — flagged as a test marked xfail in
test_early_stopping_runs (TestMLPClassifierBinary) with a full explanation.
Happy to open a separate issue/PR for it if that's preferred.

Testing

20 new unit tests in tests/unit/nn/test_mlp.py, covering binary/multiclass
classification, regression, string labels, predict_proba, error handling,
and early stopping. ruff check, ruff format --check, and typos all pass.

Fixes #230

@vaishnavidesai09

Copy link
Copy Markdown
Author

Hi @blkdmr pls review this pr let me know if changes required

@ApusBerliozi

Copy link
Copy Markdown
Contributor

Hey @vaishnavidesai09 !

Thx 4 your effort! Kindly check why ty is failing in pre-commit

@vaishnavidesai09

Copy link
Copy Markdown
Author

@ApusBerliozi review it pls

@ApusBerliozi ApusBerliozi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks fine by me

@blkdmr, gotta wait for your response, because I can't really check by now whether ML side was done correctly

@ApusBerliozi

Copy link
Copy Markdown
Contributor

@vaishnavidesai09, meanwhile, you can correct one small issue with ruff that shows in pre-commit

@vaishnavidesai09

Copy link
Copy Markdown
Author

@blkdmr pls review this

@ApusBerliozi

Copy link
Copy Markdown
Contributor

@blkdmr pls review this

Alessio is currently finishing his mater's degree, so I guess he will respond to you at monday or smth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Basic MultiLayerPerceptron class

2 participants