Skip to content

Added MLPRegressor and MLPClassifier examples#15228

Merged
adrinjalali merged 10 commits intoscikit-learn:masterfrom
FollonSaxBass:mlpclassif-documenation
Mar 2, 2020
Merged

Added MLPRegressor and MLPClassifier examples#15228
adrinjalali merged 10 commits intoscikit-learn:masterfrom
FollonSaxBass:mlpclassif-documenation

Conversation

@FollonSaxBass
Copy link
Copy Markdown
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
Copy Markdown
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.



Examples
----------
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

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

@PyExtreme
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

@rth do you have any further suggestion?

@FollonSaxBass
Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
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