Skip to content

Added MLPRegressor and MLPClassifier examples #15228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

FollonSaxBass
Copy link
Contributor

Reference Issues/PRs

Issue #3846

What does this implement/fix?

Simple examples have been added for both neural_network.MLPRegressor and neural_network.MLPClassifier

Copy link
Member

@rth rth left a comment

Choose a reason for hiding this comment

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

@@ -875,6 +875,28 @@ class MLPClassifier(ClassifierMixin, BaseMultilayerPerceptron):
out_activation_ : string
Name of the output activation function.


Examples
----------
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
----------
--------

the length should match the section above it.

>>> print(clf.predict([[0.1,0.69,0.54,0.1,0.27]]))
[0]

>>> # Calculate accuracy
Copy link
Member

Choose a reason for hiding this comment

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

Remove this comment

>>> print(clf.predict_proba([[0.1,0.4,0.54,0.1,0.27]]))
[[0.64113804 0.35886196]]

>>> # Predict class
Copy link
Member

Choose a reason for hiding this comment

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

Remove this comment

... n_informative=2, n_redundant=3, random_state=1, shuffle=True)

>>> clf = MLPClassifier(random_state=1).fit(X, y)
>>> # Predict probabilities
Copy link
Member

Choose a reason for hiding this comment

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

Remove this comment



>>> # Calculate coefficient of determination R^2
>>> cross_val_score(clf, X, y, cv=5)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just clf.score(X, y) I'm not sure that doing cross validation with 20 samples is ideal anyway.

@rth
Copy link
Member

rth commented Oct 13, 2019

In general, please remove all more obvious comments in thee added examples. e.g. when running classifier.predict there is no need to explain that we are predicting the class.

@FollonSaxBass
Copy link
Contributor Author

Thanks for your comments @rth, going to commit changes.

@PyExtreme
Copy link
Contributor

PyExtreme commented Oct 14, 2019

Hi @rth @FollonSaxBass , I have mentioned one week before at #3846 that I will be working on it and I have already started working on it.

@FollonSaxBass
Copy link
Contributor Author

Hi @PyExtreme, I didn't wanted to "stole" your pr. It's my first contribution and I saw that your message was like 5 days ago without any pr. Therefore, I started working on the issue watching carefully if you were submitting a PR. It takes like 20 mins to add these comments so I thought you were not working on it anymore. Hope this does not create any problem to you.

@PyExtreme
Copy link
Contributor

Hi @PyExtreme, I didn't wanted to "stole" your pr. It's my first contribution and I saw that your message was like 5 days ago without any pr. Therefore, I started working on the issue watching carefully if you were submitting a PR. It takes like 20 mins to add these comments so I thought you were not working on it anymore. Hope this does not create any problem to you.

@FollonSaxBass , I had got occupied after doing inital work. But since, it's your first PR, Please go ahead. Also, Please do mention on the issue, the classes you will be picking so as to avoid any conflict.

Cheers

@FollonSaxBass
Copy link
Contributor Author

@PyExtreme ok, thanks, I'm sorry for bothering you, I sincerely didn't think you were working on it :) Now the PR is visible on the thread and i think none will work on it anymore.

Regards

@FollonSaxBass
Copy link
Contributor Author

@rth do you have any further suggestion?

@FollonSaxBass
Copy link
Contributor Author

@rth after a bit of time I'm back to ask, Is there any problem with this pr? :)

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

Thank you for the PR @FollonSaxBass !

>>> from sklearn.neural_network import MLPClassifier
>>> from sklearn.datasets import make_classification

>>> X, y = make_classification(n_samples=1000, n_features=5,
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer less keywords here to focus on the MLP part of the example:

X, y = make_classification(random_state=1)
clf = MLPClassifier(random_state=1, max_iter=300).fit(X, y)
clf.predict_proba(X[:2, :])
...

>>> from sklearn.neural_network import MLPRegressor
>>> from sklearn.datasets import make_regression

>>> X, y = make_regression(n_samples=20, n_features=5, random_state=1)
Copy link
Member

Choose a reason for hiding this comment

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

Same for here.

Copy link
Contributor

Choose a reason for hiding this comment

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

@adrinjalali this one is still open

@FollonSaxBass
Did the last suggestions you got make sense to you? Will you be be able to work on them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh wow, sorry for the delay (i didn't notice the suggestions), I'll push the fix as soon as possible (during the weekend).

@FollonSaxBass
Copy link
Contributor Author

@thomasjpfan I cannot understand why circleci fails. Any suggestion? (DOC should be fixed as you suggested)

Copy link
Member

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @FollonSaxBass

@adrinjalali adrinjalali merged commit 76ef4e1 into scikit-learn:master Mar 2, 2020
gio8tisu pushed a commit to gio8tisu/scikit-learn that referenced this pull request May 15, 2020
* Added MLPRegressor and MLPClassifier examples

* shortened line due to test failure

* changed way to calculate score due to approximation error in tests

* removed comments, used predict instead of cross validation

* DOC Simplified make_regression and make_classification arguments

* DOC fix for linting

* DOC Update

* DOC Less precision

Co-authored-by: Thomas J Fan <thomasjpfan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants