Skip to content

Fixes #11128 : Default n_estimator value should be 100 #11172

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

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b6117a3
Changed RandomForest and ExtraTreesClassifier default n_estimators to…
Olamyy May 30, 2018
7253a7c
Changed RandomForest and ExtraTreesClassifier default n_estimators to…
Olamyy May 30, 2018
ec68bf2
Updated depracation logic to follow the development guideline
Olamyy Jun 5, 2018
1ec2b4d
Updated depracation logic to follow the development guideline
Olamyy Jun 5, 2018
ac2041b
Moved logic to fit and updated documentation to API Changes
Olamyy Jun 6, 2018
939ced3
Added test function to test depreaction warning
Olamyy Jun 6, 2018
a4fcc2e
Removed redundant test function and included test for correct values …
Olamyy Jun 7, 2018
e584e55
Changed DeprecationWarning to Future Warning. Updated version from 0.…
Olamyy Jun 7, 2018
8b5cb95
Changed DeprecationWarning to Future Warning. Updated version from 0.…
Olamyy Jun 7, 2018
3654c3e
Changed assert_warns to assert_no_wars
Olamyy Jun 7, 2018
22dc7bd
Removed poldata.
Olamyy Jun 9, 2018
f90d675
Fixed assert_no_warnings call in test function
Olamyy Jun 21, 2018
8d96f42
Made requested changes: Reduced warning line to meet 80 char requirem…
Olamyy Jun 26, 2018
e8147fc
Merge branch 'master' into n_estimator_should_be_100
Olamyy Jun 26, 2018
bdb2a3b
Reverted unintended commit back to original state
Olamyy Jun 26, 2018
476baeb
Removing unused imports
Olamyy Jun 26, 2018
6c3bac7
Implementing warn and use 10
Olamyy Jul 5, 2018
4b63cb1
Implementing warn and use 10
Olamyy Jul 5, 2018
ce2e20a
Implementing warn and use 10
Olamyy Jul 5, 2018
92e3489
Implementing warn and use 10
Olamyy Jul 5, 2018
d616b33
Rename test function to show intent
Olamyy Jul 5, 2018
f52c170
Reduced line numbers to meet required 79 characters
Olamyy Jul 5, 2018
a2b0d2d
Cleaning trailing spaces.
Olamyy Jul 5, 2018
cd10b03
Switching to `is None` from `if not`
Olamyy Jul 13, 2018
5953a72
Update function name to show correct intent
Olamyy Jul 13, 2018
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
4 changes: 4 additions & 0 deletions doc/whats_new/v0.20.rst
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,10 @@ Linear, kernelized and related models
:class:`linear_model.LogisticRegression` when ``verbose`` is set to 0.
:issue:`10881` by :user:`Alexandre Sevin <AlexandreSev>`.

- In both :class:`ensemble.RandomForestClassifier` and `ensemble.ExtraTreesClassifier`,
Copy link
Member

Choose a reason for hiding this comment

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

missing :class: for the extra trees. Also, the message should read something like " n_estimators will be changed to 100 in version 0.22. A FutureWarning is raised when the default value is used." or similar. n_estimators=10doesn't raise a warning (as is tested).

the default `n_estimators` parameter value has been changed to 100. A deprecation warning
is now raised when `n_estimators=10`. :issue:`11128` by :user:`Olamilekan Wahab <olamyy>`

Preprocessing

- Deprecate ``n_values`` and ``categorical_features`` parameters and
Expand Down
118 changes: 118 additions & 0 deletions poldata.README.2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@

=======
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't belong here...


Introduction

This README v2.0 (June, 2004) for the v2.0 polarity dataset comes from
the URL http://www.cs.cornell.edu/people/pabo/movie-review-data .

=======

What's New -- June, 2004

This dataset represents an enhancement of the review corpus v1.0
described in README v1.1: it contains more reviews, and labels were
created with an improved rating-extraction system.

=======

Citation Info

This data was first used in Bo Pang and Lillian Lee,
``A Sentimental Education: Sentiment Analysis Using Subjectivity Summarization
Based on Minimum Cuts'', Proceedings of the ACL, 2004.

@InProceedings{Pang+Lee:04a,
author = {Bo Pang and Lillian Lee},
title = {A Sentimental Education: Sentiment Analysis Using Subjectivity Summarization Based on Minimum Cuts},
booktitle = "Proceedings of the ACL",
year = 2004
}

=======

Data Format Summary

- review_polarity.tar.gz: contains this readme and data used in
the experiments described in Pang/Lee ACL 2004.

Specifically:

Within the folder "txt_sentoken" are the 2000 processed down-cased
text files used in Pang/Lee ACL 2004; the names of the two
subdirectories in that folder, "pos" and "neg", indicate the true
classification (sentiment) of the component files according to our
automatic rating classifier (see section "Rating Decision" below).

File names consist of a cross-validation tag plus the name of the
original html file. The ten folds used in the Pang/Lee ACL 2004 paper's
experiments were:

fold 1: files tagged cv000 through cv099, in numerical order
fold 2: files tagged cv100 through cv199, in numerical order
...
fold 10: files tagged cv900 through cv999, in numerical order

Hence, the file neg/cv114_19501.txt, for example, was labeled as
negative, served as a member of fold 2, and was extracted from the
file 19501.html in polarity_html.zip (see below).

Each line in each text file corresponds to a single sentence, as
determined by Adwait Ratnaparkhi's sentence boundary detector
MXTERMINATOR.

Preliminary steps were taken to remove rating information from the
text files, but only the rating information upon which the rating
decision was based is guaranteed to have been removed. Thus, if the
original review contains several instances of rating information,
potentially given in different forms, those not recognized as valid
ratings remain part of the review text.

- polarity_html.zip: The original source files from which the
processed, labeled, and (randomly) selected data in
review_polarity.tar.gz was derived.

Specifically:

This data consists of unprocessed, unlabeled html files from the
IMDb archive of the rec.arts.movies.reviews newsgroup,
http://reviews.imdb.com/Reviews. The files in review_polarity.tar.gz
represent a processed subset of these files.

=======

Rating Decision (Appendix A)

This section describes how we determined whether a review was positive
or negative.

The original html files do not have consistent formats -- a review may
not have the author's rating with it, and when it does, the rating can
appear at different places in the file in different forms. We only
recognize some of the more explicit ratings, which are extracted via a
set of ad-hoc rules. In essence, a file's classification is determined
based on the first rating we were able to identify.


- In order to obtain more accurate rating decisions, the maximum
rating must be specified explicitly, both for numerical ratings
and star ratings. ("8/10", "four out of five", and "OUT OF
****: ***" are examples of rating indications we recognize.)

- With a five-star system (or compatible number systems):
three-and-a-half stars and up are considered positive,
two stars and below are considered negative.
- With a four-star system (or compatible number system):
three stars and up are considered positive,
one-and-a-half stars and below are considered negative.
- With a letter grade system:
B or above is considered positive,
C- or below is considered negative.

We attempted to recognize half stars, but they are specified in an
especially free way, which makes them difficult to recognize. Hence,
we may lose a half star very occasionally; but this only results in 2.5
stars in five star system being categorized as negative, which is
still reasonable.


6 changes: 6 additions & 0 deletions sklearn/ensemble/forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ def fit(self, X, y, sample_weight=None):
-------
self : object
"""
# Validate hyperparameters
if self.n_estimators is None:
warnings.warn("'n_estimators' default value will be changed to 100"
"in version 0.22.", FutureWarning)
self.n_estimators = 10

# Validate or convert input data
X = check_array(X, accept_sparse="csc", dtype=DTYPE)
y = check_array(y, accept_sparse='csc', ensure_2d=False, dtype=None)
Expand Down
26 changes: 25 additions & 1 deletion sklearn/ensemble/tests/test_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import pytest

from sklearn.utils.testing import assert_almost_equal
from sklearn.utils.testing import assert_almost_equal, assert_no_warnings
from sklearn.utils.testing import assert_array_almost_equal
from sklearn.utils.testing import assert_array_equal
from sklearn.utils.testing import assert_equal
Expand Down Expand Up @@ -204,6 +204,30 @@ def check_probability(name):
np.exp(clf.predict_log_proba(iris.data)))


@pytest.mark.parametrize('name', FOREST_CLASSIFIERS)
def test_no_warning_raised_with_deprecated_n_estimator(name):
ForestClassifier = FOREST_CLASSIFIERS[name]
clf = ForestClassifier(n_estimators=10, random_state=1, max_features=1,
max_depth=1)
assert_no_warnings(func=clf.fit, X=iris.data, y=iris.target)


@pytest.mark.parametrize('name', FOREST_CLASSIFIERS)
def test_no_warning_raised_with_correct_n_estimator(name):
ForestClassifier = FOREST_CLASSIFIERS[name]
clf = ForestClassifier(n_estimators=100, random_state=1, max_features=1,
max_depth=1)
assert_no_warnings(func=clf.fit, X=iris.data, y=iris.target)


@pytest.mark.parametrize('name', FOREST_CLASSIFIERS)
def test_raised_warning_with_n_estimator_as_none(name):
ForestClassifier = FOREST_CLASSIFIERS[name]
clf = ForestClassifier(n_estimators=None, random_state=1, max_features=1,
max_depth=1)
assert_warns(FutureWarning, func=clf.fit, X=iris.data, y=iris.target)


@pytest.mark.parametrize('name', FOREST_CLASSIFIERS)
def test_probability(name):
check_probability(name)
Expand Down