MCPcopy
hub / github.com/scikit-learn/scikit-learn / predict

Method predict

sklearn/compose/_target.py:301–346  ·  view source on GitHub ↗

Predict using the base regressor, applying inverse. The regressor is used to predict and the `inverse_func` or `inverse_transform` is applied before returning the prediction. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_featur

(self, X, **predict_params)

Source from the content-addressed store, hash-verified

299 return self
300
301 def predict(self, X, **predict_params):
302 """Predict using the base regressor, applying inverse.
303
304 The regressor is used to predict and the `inverse_func` or
305 `inverse_transform` is applied before returning the prediction.
306
307 Parameters
308 ----------
309 X : {array-like, sparse matrix} of shape (n_samples, n_features)
310 Samples.
311
312 **predict_params : dict of str -> object
313 - If `enable_metadata_routing=False` (default): Parameters directly passed
314 to the `predict` method of the underlying regressor.
315
316 - If `enable_metadata_routing=True`: Parameters safely routed to the
317 `predict` method of the underlying regressor.
318
319 .. versionchanged:: 1.6
320 See :ref:`Metadata Routing User Guide <metadata_routing>`
321 for more details.
322
323 Returns
324 -------
325 y_hat : ndarray of shape (n_samples,)
326 Predicted values.
327 """
328 check_is_fitted(self)
329 if _routing_enabled():
330 routed_params = process_routing(self, "predict", **predict_params)
331 else:
332 routed_params = Bunch(regressor=Bunch(predict=predict_params))
333
334 pred = self.regressor_.predict(X, **routed_params.regressor.predict)
335 if pred.ndim == 1:
336 pred_trans = self.transformer_.inverse_transform(pred.reshape(-1, 1))
337 else:
338 pred_trans = self.transformer_.inverse_transform(pred)
339 if (
340 self._training_dim == 1
341 and pred_trans.ndim == 2
342 and pred_trans.shape[1] == 1
343 ):
344 pred_trans = pred_trans.squeeze(axis=1)
345
346 return pred_trans
347
348 def __sklearn_tags__(self):
349 regressor = self._get_regressor()

Calls 5

check_is_fittedFunction · 0.90
_routing_enabledFunction · 0.90
process_routingFunction · 0.90
BunchClass · 0.90
inverse_transformMethod · 0.45