MCPcopy Create free account
hub / github.com/Xtra-Computing/thundersvm / _dense_fit

Method _dense_fit

python/thundersvm/thundersvm.py:165–215  ·  view source on GitHub ↗
(self, X, y, solver_type, kernel)

Source from the content-addressed store, hash-verified

163 return self
164
165 def _dense_fit(self, X, y, solver_type, kernel):
166
167 X = np.asarray(X, dtype=np.float32, order='C')
168 samples = X.shape[0]
169 features = X.shape[1]
170 X_1d = X.ravel()
171 data = X_1d.ctypes.data_as(POINTER(c_float))
172 kernel_type = kernel
173 y = np.asarray(y, dtype=np.float32, order='C')
174 label = y.ctypes.data_as(POINTER(c_float))
175 if self.class_weight is None:
176 weight_size = 0
177 self.class_weight = dict()
178 weight_label = (c_int * weight_size)()
179 weight_label[:] = list(self.class_weight.keys())
180 weight = (c_float * weight_size)()
181 weight[:] = list(self.class_weight.values())
182 elif self.class_weight == 'balanced':
183 y_unique = np.unique(y)
184 y_count = np.bincount(y.astype(int))
185 weight_label_list = []
186 weight_list = []
187 for n in range(0, len(y_count)):
188 if y_count[n] != 0:
189 weight_label_list.append(n)
190 weight_list.append(samples / (len(y_unique) * y_count[n]))
191 weight_size = len(weight_list)
192 weight_label = (c_int * weight_size)()
193 weight_label[:] = weight_label_list
194 weight = (c_float * weight_size)()
195 weight[:] = weight_list
196 else:
197 weight_size = len(self.class_weight)
198 weight_label = (c_int * weight_size)()
199 weight_label[:] = list(self.class_weight.keys())
200 weight = (c_float * weight_size)()
201 weight[:] = list(self.class_weight.values())
202
203 n_features = (c_int * 1)()
204 n_classes = (c_int * 1)()
205 self._train_succeed = (c_int * 1)()
206 thundersvm.dense_model_scikit(
207 samples, features, data, label, solver_type,
208 kernel_type, self.degree, c_float(self._gamma), c_float(self.coef0),
209 c_float(self.C), c_float(self.nu), c_float(self.epsilon), c_float(self.tol),
210 self.probability, weight_size, weight_label, weight,
211 self.verbose, self.max_iter, self.n_jobs, self.max_mem_size,
212 self.gpu_id,
213 n_features, n_classes, self._train_succeed, c_void_p(self.model))
214 self.n_features = n_features[0]
215 self.n_classes = n_classes[0]
216
217 def _sparse_fit(self, X, y, solver_type, kernel):
218 X.data = np.asarray(X.data, dtype=np.float32, order='C')

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected