8000 [MRG] Remove duplicate import of warnings & unused variables by rebekahkim · Pull Request #12203 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG] Remove duplicate import of warnings & unused variables #12203

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
merged 4 commits into from
Sep 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion sklearn/ensemble/bagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,6 @@ def _validate_estimator(self):
def _set_oob_score(self, X, y):
n_samples = y.shape[0]
n_classes_ = self.n_classes_
classes_ = self.classes_

predictions = np.zeros((n_samples, n_classes_))

Expand Down
11 changes: 5 additions & 6 deletions sklearn/ensemble/forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class calls the ``fit`` method of each sub-estimator on random samples

from __future__ import division

import warnings
from warnings import warn
from warnings import catch_warnings, simplefilter, warn
import threading

from abc import ABCMeta, abstractmethod
Expand Down Expand Up @@ -112,8 +111,8 @@ def _parallel_build_trees(tree, forest, X, y, sample_weight, tree_idx, n_trees,
curr_sample_weight *= sample_counts

if class_weight == 'subsample':
with warnings.catch_warnings():
warnings.simplefilter('ignore', DeprecationWarning)
with catch_warnings():
simplefilter('ignore', DeprecationWarning)
curr_sample_weight *= compute_sample_weight('auto', y, indices)
elif class_weight == 'balanced_subsample':
curr_sample_weight *= compute_sample_weight('balanced', y, indices)
Expand Down Expand Up @@ -244,7 +243,7 @@ def fit(self, X, y, sample_weight=None):
"""

if self.n_estimators == 'warn':
warnings.warn("The default value of n_estimators will change from "
warn("The default value of n_estimators will change from "
"10 in version 0.20 to 100 in 0.22.", FutureWarning)
self.n_estimators = 10

Expand All @@ -259,7 +258,7 @@ def fit(self, X, y, sample_weight=None):
X.sort_indices()

# Remap output
n_samples, self.n_features_ = X.shape
self.n_features_ = X.shape[1]

y = np.atleast_1d(y)
if y.ndim == 2 and y.shape[1] == 1:
Expand Down
23 changes: 11 additions & 12 deletions sklearn/ensemble/iforest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from __future__ import division

import numpy as np
import warnings
from warnings import warn
from sklearn.utils.fixes import euler_gamma

Expand Down Expand Up @@ -208,20 +207,20 @@ def fit(self, X, y=None, sample_weight=None):
self : object
"""
if self.contamination == "legacy":
warnings.warn('default contamination parameter 0.1 will change '
'in version 0.22 to "auto". This will change the '
'predict method behavior.',
FutureWarning)
warn('default contamination parameter 0.1 will change '
'in version 0.22 to "auto". This will change the '
'predict method behavior.',
FutureWarning)
self._contamination = 0.1
else:
self._contamination = self.contamination

if self.behaviour == 'old':
warnings.warn('behaviour="old" is deprecated and will be removed '
'in version 0.22. Please use behaviour="new", which '
'makes the decision_function change to match '
'other anomaly detection algorithm API.',
FutureWarning)
warn('behaviour="old" is deprecated and will be removed '
Copy link
Member

Choose a reason for hiding this comment

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

actually I think you need to fix the indentation here. make sure you run flake8 on this file

'in version 0.22. Please use behaviour="new", which '
'makes the decision_function change to match '
'other anomaly detection algorithm API.',
FutureWarning)

X = check_array(X, accept_sparse=['csc'])
if issparse(X):
Expand Down Expand Up @@ -414,8 +413,8 @@ def threshold_(self):
if self.behaviour != 'old':
raise AttributeError("threshold_ attribute does not exist when "
"behaviour != 'old'")
warnings.warn("threshold_ attribute is deprecated in 0.20 and will"
" be removed in 0.22.", DeprecationWarning)
warn("threshold_ attribute is deprecated in 0.20 and will"
" be removed in 0.22.", DeprecationWarning)
return self._threshold_


Expand Down
0