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

Function _check_response_method

sklearn/utils/validation.py:2248–2291  ·  view source on GitHub ↗

Check if `response_method` is available in estimator and return it. .. versionadded:: 1.3 Parameters ---------- estimator : estimator instance Classifier or regressor to check. response_method : {"predict_proba", "predict_log_proba", "decision_function", "p

(estimator, response_method)

Source from the content-addressed store, hash-verified

2246
2247
2248def _check_response_method(estimator, response_method):
2249 """Check if `response_method` is available in estimator and return it.
2250
2251 .. versionadded:: 1.3
2252
2253 Parameters
2254 ----------
2255 estimator : estimator instance
2256 Classifier or regressor to check.
2257
2258 response_method : {"predict_proba", "predict_log_proba", "decision_function",
2259 "predict"} or list of such str
2260 Specifies the response method to use get prediction from an estimator
2261 (i.e. :term:`predict_proba`, :term:`predict_log_proba`,
2262 :term:`decision_function` or :term:`predict`). Possible choices are:
2263 - if `str`, it corresponds to the name to the method to return;
2264 - if a list of `str`, it provides the method names in order of
2265 preference. The method returned corresponds to the first method in
2266 the list and which is implemented by `estimator`.
2267
2268 Returns
2269 -------
2270 prediction_method : callable
2271 Prediction method of estimator.
2272
2273 Raises
2274 ------
2275 AttributeError
2276 If `response_method` is not available in `estimator`.
2277 """
2278 if isinstance(response_method, str):
2279 list_methods = [response_method]
2280 else:
2281 list_methods = response_method
2282
2283 prediction_method = [getattr(estimator, method, None) for method in list_methods]
2284 prediction_method = reduce(lambda x, y: x or y, prediction_method)
2285 if prediction_method is None:
2286 raise AttributeError(
2287 f"{estimator.__class__.__name__} has none of the following attributes: "
2288 f"{', '.join(list_methods)}."
2289 )
2290
2291 return prediction_method
2292
2293
2294def _check_method_params(X, params, indices=None):

Callers 11

fitMethod · 0.90
_fit_calibratorFunction · 0.90
predict_probaMethod · 0.90
fitMethod · 0.90
_get_response_valuesFunction · 0.90
_use_cacheMethod · 0.90
_scoreMethod · 0.90
_method_nameMethod · 0.90

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…