Skip to content

Commit

Permalink
MAINT drop support for NumPy < 1.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
larsmans committed Mar 2, 2014
1 parent 551ea22 commit b97fb3c
Show file tree
Hide file tree
Showing 38 changed files with 285 additions and 480 deletions.
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -37,7 +37,7 @@ Dependencies
scikit-learn is tested to work under Python 2.6+ and Python 3.3+
(using the same codebase thanks to an embedded copy of `six <http://pythonhosted.org/six/>`_).

The required dependencies to build the software Numpy >= 1.3, SciPy >= 0.7
The required dependencies to build the software NumPy >= 1.6.1, SciPy >= 0.9
and a working C/C++ compiler.

For running the examples Matplotlib >= 0.99.1 is required and for running the
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/bench_sparsify.py
Expand Up @@ -45,15 +45,14 @@

from scipy.sparse.csr import csr_matrix
import numpy as np
from sklearn.utils.fixes import count_nonzero
from sklearn.linear_model.stochastic_gradient import SGDRegressor
from sklearn.metrics import r2_score

np.random.seed(42)


def sparsity_ratio(X):
return count_nonzero(X) / float(n_samples * n_features)
return np.count_nonzero(X) / float(n_samples * n_features)

n_samples, n_features = 5000, 300
X = np.random.randn(n_samples, n_features)
Expand Down
6 changes: 1 addition & 5 deletions doc/developers/index.rst
Expand Up @@ -764,10 +764,7 @@ E.g., here's a custom classifier::
... return self
... def predict(self, X):
... return np.repeat(self.classes_[self.majority_], len(X))
... # doctest: +SKIP

.. We don't run the above "doctest" because it requires a recent NumPy and we
don't want users to import from sklearn.utils.fixes.

get_params and set_params
-------------------------
Expand Down Expand Up @@ -860,12 +857,11 @@ should match the order in which ``predict_proba``, ``predict_log_proba``
and ``decision_function`` return their values.
The easiest way to achieve this is to put::

self.classes_, y = unique(y, return_inverse=True)
self.classes_, y = np.unique(y, return_inverse=True)

in ``fit``.
This return a new ``y`` that contains class indexes, rather than labels,
in the range [0, ``n_classes``).
``unique`` is available in ``sklearn.utils.fixes``.

A classifier's ``predict`` method should return
arrays containing class labels from ``classes_``.
Expand Down
17 changes: 2 additions & 15 deletions doc/developers/utilities.rst
Expand Up @@ -181,26 +181,13 @@ Graph Routines
Backports
=========

- :func:`fixes.unique`: (backport of ``np.unique`` from numpy 1.4). Find the
unique entries in an array. In numpy versions < 1.4, ``np.unique`` is less
flexible. Used in :mod:`sklearn.cross_validation`.

- :func:`fixes.copysign`: (backport of ``np.copysign`` from numpy 1.4).
Change the sign of ``x1`` to that of ``x2``, element-wise.

- :func:`fixes.in1d`: (backport of ``np.in1d`` from numpy 1.4).
Test whether each element of an array is in a second array. Used in
``sklearn.datasets.twenty_newsgroups`` and
``sklearn.feature_extraction.image``.
- :func:`fixes.expit`: Logistic sigmoid function. Replacement for SciPy 0.10's
``scipy.special.expit``.

- :func:`fixes.savemat` (backport of ``scipy.io.savemat`` from scipy 0.7.2).
Save an array in MATLAB-format. In earlier versions, the keyword
``oned_as`` is not available.

- :func:`fixes.count_nonzero` (backport of ``np.count_nonzero`` from
numpy 1.6). Count the nonzero elements of a matrix. Used in
tests of :mod:`sklearn.linear_model`.

- :func:`arrayfuncs.solve_triangular`
(Back-ported from scipy v0.9) Used in ``sklearn.linear_model.omp``,
independent back-ports in ``sklearn.mixture.gmm`` and
Expand Down
2 changes: 1 addition & 1 deletion doc/install.rst
Expand Up @@ -35,7 +35,7 @@ Getting the dependencies
------------------------

Installing from source requires you to have installed Python (>= 2.6),
NumPy (>= 1.3), SciPy (>= 0.7), setuptools, Python development headers
NumPy (>= 1.6.1), SciPy (>= 0.9), setuptools, Python development headers
and a working C++ compiler.
Under Debian-based operating systems, which include Ubuntu,
you can install all these requirements by issuing::
Expand Down
4 changes: 1 addition & 3 deletions doc/modules/computational_performance.rst
Expand Up @@ -109,10 +109,8 @@ max, to be checked depending on the hardware) for the sparse input
representation to be faster than the dense input representation on a machine
with many CPUs and an optimized BLAS implementation.

Here is sample code to test the sparsity of your input
(requires a relatively recent NumPy for the ``count_nonzero`` function)::
Here is sample code to test the sparsity of your input::

from sklearn.utils.fixes import count_nonzero
def sparsity_ratio(X):
return 1.0 - np.count_nonzero(X) / float(X.shape[0] * X.shape[1])
print("input sparsity ratio:", sparsity_ratio(X))
Expand Down
3 changes: 1 addition & 2 deletions examples/applications/plot_model_complexity_influence.py
Expand Up @@ -33,7 +33,6 @@
from sklearn.ensemble.gradient_boosting import GradientBoostingRegressor
from sklearn.linear_model.stochastic_gradient import SGDClassifier
from sklearn.metrics.metrics import hamming_loss
from sklearn.utils.fixes import count_nonzero

###############################################################################
# Routines
Expand Down Expand Up @@ -121,7 +120,7 @@ def plot_influence(conf, mse_values, prediction_times, complexities):

def _count_nonzero_coefficients(estimator):
a = estimator.coef_.todense()
return count_nonzero(a)
return np.count_nonzero(a)

###############################################################################
# main code
Expand Down
3 changes: 1 addition & 2 deletions examples/applications/plot_prediction_latency.py
Expand Up @@ -30,7 +30,6 @@
from sklearn.linear_model.ridge import Ridge
from sklearn.linear_model.stochastic_gradient import SGDRegressor
from sklearn.svm.classes import SVR
from sklearn.utils.fixes import count_nonzero


def _not_in_sphinx():
Expand Down Expand Up @@ -287,7 +286,7 @@ def plot_benchmark_throughput(throughputs, configuration):
'instance': SGDRegressor(penalty='elasticnet', alpha=0.01,
l1_ratio=0.25, fit_intercept=True),
'complexity_label': 'non-zero coefficients',
'complexity_computer': lambda clf: count_nonzero(clf.coef_)},
'complexity_computer': lambda clf: np.count_nonzero(clf.coef_)},
{'name': 'RandomForest',
'instance': RandomForestRegressor(),
'complexity_label': 'estimators',
Expand Down
3 changes: 1 addition & 2 deletions examples/ensemble/plot_gradient_boosting_regularization.py
Expand Up @@ -30,14 +30,13 @@

from sklearn import ensemble
from sklearn import datasets
from sklearn.utils.fixes import unique


X, y = datasets.make_hastie_10_2(n_samples=12000, random_state=1)
X = X.astype(np.float32)

# map labels from {-1, 1} to {0, 1}
labels, y = unique(y, return_inverse=True)
labels, y = np.unique(y, return_inverse=True)

X_train, X_test = X[:2000], X[2000:]
y_train, y_test = y[:2000], y[2000:]
Expand Down
3 changes: 1 addition & 2 deletions sklearn/cluster/_feature_agglomeration.py
Expand Up @@ -9,7 +9,6 @@

from ..base import TransformerMixin
from ..utils import array2d
from ..utils.fixes import unique


###############################################################################
Expand Down Expand Up @@ -67,5 +66,5 @@ def inverse_transform(self, Xred):
A vector of size n_samples with the values of Xred assigned to
each of the cluster of samples.
"""
unil, inverse = unique(self.labels_, return_inverse=True)
unil, inverse = np.unique(self.labels_, return_inverse=True)
return Xred[..., inverse]

0 comments on commit b97fb3c

Please sign in to comment.