MCPcopy Index your code
hub / github.com/scikit-learn/scikit-learn / predict

Method predict

sklearn/dummy.py:252–337  ·  view source on GitHub ↗

Perform classification on test vectors X. Parameters ---------- X : array-like of shape (n_samples, n_features) Test data. Returns ------- y : array-like of shape (n_samples,) or (n_samples, n_outputs) Predicted target values

(self, X)

Source from the content-addressed store, hash-verified

250 return self
251
252 def predict(self, X):
253 """Perform classification on test vectors X.
254
255 Parameters
256 ----------
257 X : array-like of shape (n_samples, n_features)
258 Test data.
259
260 Returns
261 -------
262 y : array-like of shape (n_samples,) or (n_samples, n_outputs)
263 Predicted target values for X.
264 """
265 check_is_fitted(self)
266
267 # numpy random_state expects Python int and not long as size argument
268 # under Windows
269 n_samples = _num_samples(X)
270 rs = check_random_state(self.random_state)
271
272 n_classes_ = self.n_classes_
273 classes_ = self.classes_
274 class_prior_ = self.class_prior_
275 constant = self.constant
276 if self.n_outputs_ == 1:
277 # Get same type even for self.n_outputs_ == 1
278 n_classes_ = [n_classes_]
279 classes_ = [classes_]
280 class_prior_ = [class_prior_]
281 constant = [constant]
282 # Compute probability only once
283 if self._strategy == "stratified":
284 proba = self.predict_proba(X)
285 if self.n_outputs_ == 1:
286 proba = [proba]
287
288 if self.sparse_output_:
289 class_prob = None
290 if self._strategy in ("most_frequent", "prior"):
291 classes_ = [np.array([cp.argmax()]) for cp in class_prior_]
292
293 elif self._strategy == "stratified":
294 class_prob = class_prior_
295
296 elif self._strategy == "uniform":
297 raise ValueError(
298 "Sparse target prediction is not "
299 "supported with the uniform strategy"
300 )
301
302 elif self._strategy == "constant":
303 classes_ = [np.array([c]) for c in constant]
304
305 y = _random_choice_csc(n_samples, classes_, class_prob, self.random_state)
306 else:
307 if self._strategy in ("most_frequent", "prior"):
308 y = np.tile(
309 [

Calls 5

predict_probaMethod · 0.95
check_is_fittedFunction · 0.90
_num_samplesFunction · 0.90
check_random_stateFunction · 0.90
_random_choice_cscFunction · 0.90