@@ -20,15 +20,7 @@ def __init__(self, impl, kernel, degree, gamma, coef0,
2020 coef0 , tol , C , nu , epsilon ,
2121 shrinking , probability , cache_size )
2222
23- # container for when we call fit
24- self ._support_data = np .empty (0 , dtype = np .float64 , order = 'C' )
25- self ._support_indices = np .empty (0 , dtype = np .int32 , order = 'C' )
26- self ._support_indptr = np .empty (0 , dtype = np .int32 , order = 'C' )
27-
2823 # strictly speaking, dual_coef is not sparse (see Notes above)
29- self ._dual_coef_data = np .empty (0 , dtype = np .float64 , order = 'C' )
30- self ._dual_coef_indices = np .empty (0 , dtype = np .int32 , order = 'C' )
31- self ._dual_coef_indptr = np .empty (0 , dtype = np .int32 , order = 'C' )
3224 self .intercept_ = np .empty (0 , dtype = np .float64 , order = 'C' )
3325
3426 # only used in classification
@@ -101,35 +93,28 @@ def fit(self, X, y, class_weight=None, sample_weight=None):
10193 # if custom gamma is not provided ...
10294 self .gamma = 1.0 / X .shape [1 ]
10395
104- self .label_ , self .probA_ , self .probB_ = libsvm .libsvm_sparse_train (
96+ self .support_vectors_ , dual_coef_data , self .label_ , self .probA_ , self .probB_ = \
97+ libsvm .libsvm_sparse_train (
10598 X .shape [1 ], X .data , X .indices , X .indptr , y ,
10699 solver_type , kernel_type , self .degree , self .gamma ,
107- self .coef0 , self .tol , self .C , self ._support_data ,
108- self ._support_indices , self ._support_indptr ,
109- self ._dual_coef_data , self .intercept_ ,
100+ self .coef0 , self .tol , self .C ,
101+ self .intercept_ ,
110102 self .class_weight_label , self .class_weight , sample_weight ,
111103 self .n_support_ , self .nu , self .cache_size , self .epsilon ,
112104 int (self .shrinking ), int (self .probability ))
113105
114106 n_class = len (self .label_ ) - 1
115- n_SV = self ._support_indptr .size - 1
107+ n_SV = self .support_vectors_ .shape [0 ]
108+ import pdb ; pdb .set_trace ()
116109
117110 dual_coef_indices = np .tile (np .arange (n_SV ), n_class )
118111 dual_coef_indptr = np .arange (0 , dual_coef_indices .size + 1 ,
119112 dual_coef_indices .size / n_class )
120113
121- # this will fail if n_SV is zero. This is a limitation
122- # in scipy.sparse, which does not permit empty matrices
123- self .support_vectors_ = scipy .sparse .csr_matrix ((self ._support_data ,
124- self ._support_indices ,
125- self ._support_indptr ),
126- (n_SV , X .shape [1 ]))
127-
128- self .dual_coef_ = scipy .sparse .csr_matrix ((self ._dual_coef_data ,
129- dual_coef_indices ,
130- dual_coef_indptr ),
131- (n_class , n_SV )
132- )
114+
115+ self .dual_coef_ = scipy .sparse .csr_matrix (
116+ (dual_coef_data ,dual_coef_indices , dual_coef_indptr ),
117+ (n_class , n_SV ))
133118 return self
134119
135120 def predict (self , T ):
0 commit comments