MCPcopy Create free account
hub / github.com/Persper/code-analytics / predict

Method predict

persper/classifier.py:270–296  ·  view source on GitHub ↗
(self, X)

Source from the content-addressed store, hash-verified

268 for column in columns)
269
270 def predict(self, X):
271 if(hasattr(self.pipelines[0], 'decision_function') and
272 is_classifier(self.pipelines[0])):
273 thresh = 0
274 else:
275 thresh = 0.5
276
277 n_samples = X['count'].shape[0]
278 if self.label_binarizer.y_type_ == 'multiclass':
279 maxima = np.empty(n_samples, dtype=float)
280 maxima.fill(-np.inf)
281 argmaxima = np.zeros(n_samples, dtype=int)
282 for i, p in enumerate(self.pipelines):
283 pred = _predict_binary(p, X)
284 np.maximum(maxima, pred, out=maxima)
285 argmaxima[maxima == pred] = i
286 return self.classes[np.array(argmaxima.T)]
287 else:
288 indices = array.array('i')
289 indptr = array.array('i', [0])
290 for p in self.pipelines:
291 indices.extend(np.where(_predict_binary(p, X) > thresh)[0])
292 indptr.append(len(indices))
293 data = np.ones(len(indices), dtype=int)
294 indicator = csc_matrix((data, indices, indptr),
295 shape=(n_samples, len(self.pipelines)))
296 return self.label_binarizer.inverse_transform(indicator)
297
298class Classifier():
299

Callers 1

runMethod · 0.95

Calls 2

_predict_binaryFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected