MCPcopy Create free account
hub / github.com/catboost/catboost / score

Method score

catboost/python-package/catboost/core.py:6269–6311  ·  view source on GitHub ↗

Calculate R^2. Parameters ---------- X : catboost.Pool or list or numpy.ndarray or pandas.DataFrame or pandas.Series or polars.DataFrame Data to apply model on. y : list or numpy.ndarray or polars.Series True labels. Returns

(self, X, y=None)

Source from the content-addressed store, hash-verified

6267 return self._staged_predict(data, prediction_type, ntree_start, ntree_end, eval_period, thread_count, verbose, 'staged_predict')
6268
6269 def score(self, X, y=None):
6270 """
6271 Calculate R^2.
6272
6273 Parameters
6274 ----------
6275 X : catboost.Pool or list or numpy.ndarray or pandas.DataFrame or pandas.Series or polars.DataFrame
6276 Data to apply model on.
6277 y : list or numpy.ndarray or polars.Series
6278 True labels.
6279
6280 Returns
6281 -------
6282 R^2 : float
6283 """
6284 if isinstance(X, Pool):
6285 if y is not None:
6286 raise CatBoostError("Wrong initializing y: X is catboost.Pool object, y must be initialized inside catboost.Pool.")
6287 y = X.get_label()
6288 if y is None:
6289 raise CatBoostError("Label in X has not initialized.")
6290 elif y is None:
6291 raise CatBoostError("y should be specified.")
6292 y = np.array(y, dtype=np.float64)
6293 predictions = self._predict(
6294 X,
6295 prediction_type=self._get_default_prediction_type(),
6296 ntree_start=0,
6297 ntree_end=0,
6298 thread_count=-1,
6299 verbose=None,
6300 parent_method_name='score'
6301 )
6302 loss = self._object._get_loss_function_name()
6303 if loss == 'RMSEWithUncertainty':
6304 predictions = predictions[:, 0]
6305 if predictions.size != y.size:
6306 msg = "labels and predictions should have same size. But y.size={} != preds.size={}"
6307 raise CatBoostError(msg.format(y.size, predictions.size))
6308 y = y.reshape(predictions.shape)
6309 total_sum_of_squares = np.sum((y - y.mean(axis=0)) ** 2)
6310 residual_sum_of_squares = np.sum((y - predictions) ** 2)
6311 return 1 - residual_sum_of_squares / total_sum_of_squares
6312
6313 @staticmethod
6314 def _check_is_compatible_loss(loss_function):

Callers 2

test_multiregressionFunction · 0.95

Calls 10

isinstanceFunction · 0.85
get_labelMethod · 0.80
_predictMethod · 0.80
reshapeMethod · 0.80
CatBoostErrorClass · 0.50
arrayMethod · 0.45
formatMethod · 0.45
sumMethod · 0.45
meanMethod · 0.45

Tested by 2

test_multiregressionFunction · 0.76