Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 847d002

Browse files
GaelVaroquauxFabian Pedregosa
authored and
Fabian Pedregosa
committed
BUG: Make SVMs work on non contiguous arrays
1 parent 7eae6e0 commit 847d002

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

doc/modules/svm.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ The disadvantages of Support Vector Machines include:
3737

3838
.. TODO: add reference to probability estimates
3939
40+
.. note:: **Avoiding data copy**
41+
42+
If the data passed to certain methods is not C-ordered and
43+
contiguous, it will be copied before calling the underlying C
44+
implementation. You can check whether a give numpy array is
45+
C-contiguous by inspecting its `flags` dictionnary.
46+
4047
.. _svm_classification:
4148

4249
Classification

scikits/learn/svm/base.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ class frequencies.
9999
-------
100100
self : object
101101
Returns self.
102+
103+
Notes
104+
------
105+
If X and y are not C-ordered and contiguous arrays, they are
106+
copied.
107+
102108
"""
103109
self._set_params(**params)
104110

@@ -133,7 +139,8 @@ class frequencies.
133139
self.support_, self.support_vectors_, self.n_support_, \
134140
self.dual_coef_, self.intercept_, self.label_, self.probA_, \
135141
self.probB_ = libsvm.fit(
136-
X, y, svm_type=solver_type, sample_weight=sample_weight,
142+
np.ascontiguousarray(X), np.ascontiguousarray(y),
143+
svm_type=solver_type, sample_weight=sample_weight,
137144
class_weight=class_weight,
138145
class_weight_label=class_weight_label,
139146
**self._get_params())

scikits/learn/svm/classes.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ class SVC(BaseLibSVM, ClassifierMixin):
136136
`intercept_` : array, shape = [n_class * (n_class-1) / 2]
137137
Constants in decision function.
138138
139-
140139
Examples
141140
--------
142141
>>> import numpy as np
@@ -575,6 +574,11 @@ def fit(self, X, class_weight={}, sample_weight=[], **params):
575574
-------
576575
self : object
577576
Returns self.
577+
578+
Notes
579+
------
580+
If X is not a C-ordered contiguous array, it is copied.
581+
578582
"""
579583
super(OneClassSVM, self).fit(
580584
X, [], class_weight=class_weight, sample_weight=sample_weight,

0 commit comments

Comments
 (0)