Skip to content

Commit 372c0ed

Browse files
committed
Re inserted the check for X.ndim == 2 in initialization, updated a doc detail for X: coo is converted to csr only in the initialization not in the predict functions
1 parent fd1e316 commit 372c0ed

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

sklearn/ensemble/weight_boosting.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import numpy as np
2626
from numpy.core.umath_tests import inner1d
2727

28+
from scipy.sparse import coo_matrix
29+
from scipy.sparse import issparse
30+
2831
from .base import BaseEnsemble
2932
from ..base import ClassifierMixin, RegressorMixin
3033
from ..externals import six
@@ -34,7 +37,6 @@
3437
from ..utils import array2d, check_arrays, check_random_state, column_or_1d
3538
from ..utils import safe_asarray
3639
from ..metrics import accuracy_score, r2_score
37-
from scipy.sparse import coo_matrix
3840

3941
__all__ = [
4042
'AdaBoostClassifier',
@@ -96,6 +98,9 @@ def fit(self, X, y, sample_weight=None):
9698
X = X.tocsr()
9799
X = safe_asarray(X)
98100

101+
if (X.ndim != 2 and not issparse(X)):
102+
X = array2d(X)
103+
99104
X, = check_arrays(X, dtype=DTYPE)
100105
X, y = check_arrays(X, y, check_ccontiguous=True)
101106

@@ -205,7 +210,7 @@ def staged_score(self, X, y, sample_weight=None):
205210
----------
206211
X : {array-like, sparse matrix} of shape = [n_samples, n_features]
207212
The training input samples. Sparse matrix can be csc, csr, coo,
208-
dok, or lil. coo, dok, and lil are converted to csr.
213+
dok, or lil. dok, and lil are converted to csr.
209214
210215
y : array-like, shape = [n_samples]
211216
Labels for X.
@@ -364,7 +369,7 @@ def fit(self, X, y, sample_weight=None):
364369
----------
365370
X : {array-like, sparse matrix} of shape = [n_samples, n_features]
366371
The training input samples. Sparse matrix can be csc, csr, coo,
367-
dok, or lil. coo, dok, and lil are converted to csr.
372+
dok, or lil. dok, and lil are converted to csr.
368373
369374
y : array-like of shape = [n_samples]
370375
The target values (class labels).
@@ -415,7 +420,7 @@ def _boost(self, iboost, X, y, sample_weight):
415420
416421
X : {array-like, sparse matrix} of shape = [n_samples, n_features]
417422
The training input samples. Sparse matrix can be csc, csr, coo,
418-
dok, or lil. coo, dok, and lil are converted to csr.
423+
dok, or lil. dok, and lil are converted to csr.
419424
420425
y : array-like of shape = [n_samples]
421426
The target values (class labels).
@@ -564,7 +569,7 @@ def predict(self, X):
564569
----------
565570
X : {array-like, sparse matrix} of shape = [n_samples, n_features]
566571
The training input samples. Sparse matrix can be csc, csr, coo,
567-
dok, or lil. coo, dok, and lil are converted to csr.
572+
dok, or lil. dok, and lil are converted to csr.
568573
569574
Returns
570575
-------
@@ -617,7 +622,7 @@ def decision_function(self, X):
617622
----------
618623
X : {array-like, sparse matrix} of shape = [n_samples, n_features]
619624
The training input samples. Sparse matrix can be csc, csr, coo,
620-
dok, or lil. coo, dok, and lil are converted to csr.
625+
dok, or lil. dok, and lil are converted to csr.
621626
622627
Returns
623628
-------
@@ -661,7 +666,7 @@ def staged_decision_function(self, X):
661666
----------
662667
X : {array-like, sparse matrix} of shape = [n_samples, n_features]
663668
The training input samples. Sparse matrix can be csc, csr, coo,
664-
dok, or lil. coo, dok, and lil are converted to csr.
669+
dok, or lil. dok, and lil are converted to csr.
665670
666671
Returns
667672
-------
@@ -715,7 +720,7 @@ def predict_proba(self, X):
715720
----------
716721
X : {array-like, sparse matrix} of shape = [n_samples, n_features]
717722
The training input samples. Sparse matrix can be csc, csr, coo,
718-
dok, or lil. coo, dok, and lil are converted to csr.
723+
dok, or lil. dok, and lil are converted to csr.
719724
720725
Returns
721726
-------
@@ -759,7 +764,7 @@ def staged_predict_proba(self, X):
759764
----------
760765
X : {array-like, sparse matrix} of shape = [n_samples, n_features]
761766
The training input samples. Sparse matrix can be csc, csr, coo,
762-
dok, or lil. coo, dok, and lil are converted to csr.
767+
dok, or lil. dok, and lil are converted to csr.
763768
764769
Returns
765770
-------
@@ -804,7 +809,7 @@ def predict_log_proba(self, X):
804809
----------
805810
X : {array-like, sparse matrix} of shape = [n_samples, n_features]
806811
The training input samples. Sparse matrix can be csc, csr, coo,
807-
dok, or lil. coo, dok, and lil are converted to csr.
812+
dok, or lil. dok, and lil are converted to csr.
808813
809814
Returns
810815
-------
@@ -900,7 +905,7 @@ def fit(self, X, y, sample_weight=None):
900905
----------
901906
X : {array-like, sparse matrix} of shape = [n_samples, n_features]
902907
The training input samples. Sparse matrix can be csc, csr, coo,
903-
dok, or lil. coo, dok, and lil are converted to csr.
908+
dok, or lil. dok, and lil are converted to csr.
904909
905910
y : array-like of shape = [n_samples]
906911
The target values (real numbers).
@@ -940,7 +945,7 @@ def _boost(self, iboost, X, y, sample_weight):
940945
941946
X : {array-like, sparse matrix} of shape = [n_samples, n_features]
942947
The training input samples. Sparse matrix can be csc, csr, coo,
943-
dok, or lil. coo, dok, and lil are converted to csr.
948+
dok, or lil. dok, and lil are converted to csr.
944949
945950
y : array-like of shape = [n_samples]
946951
The target values (class labels in classification, real numbers in
@@ -1050,7 +1055,7 @@ def predict(self, X):
10501055
----------
10511056
X : {array-like, sparse matrix} of shape = [n_samples, n_features]
10521057
The training input samples. Sparse matrix can be csc, csr, coo,
1053-
dok, or lil. coo, dok, and lil are converted to csr.
1058+
dok, or lil. dok, and lil are converted to csr.
10541059
10551060
Returns
10561061
-------
@@ -1076,7 +1081,7 @@ def staged_predict(self, X):
10761081
----------
10771082
X : {array-like, sparse matrix} of shape = [n_samples, n_features]
10781083
The training input samples. Sparse matrix can be csc, csr, coo,
1079-
dok, or lil. coo, dok, and lil are converted to csr.
1084+
dok, or lil. dok, and lil are converted to csr.
10801085
10811086
Returns
10821087
-------

0 commit comments

Comments
 (0)