Calculate NDCG@top 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.ndarrays or pandas.DataFrame or pandas.Series or polars.Series
(self, X, y=None, group_id=None, top=None, type=None, denominator=None, group_weight=None, thread_count=-1)
| 6650 | return self._staged_predict(X, 'RawFormulaVal', ntree_start, ntree_end, eval_period, thread_count, verbose, 'staged_predict') |
| 6651 | |
| 6652 | def score(self, X, y=None, group_id=None, top=None, type=None, denominator=None, group_weight=None, thread_count=-1): |
| 6653 | """ |
| 6654 | Calculate NDCG@top |
| 6655 | Parameters |
| 6656 | ---------- |
| 6657 | X : catboost.Pool or list or numpy.ndarray or pandas.DataFrame or pandas.Series or polars.DataFrame |
| 6658 | Data to apply model on. |
| 6659 | y : list or numpy.ndarrays or pandas.DataFrame or pandas.Series or polars.Series |
| 6660 | True labels. |
| 6661 | group_id : list or numpy.ndarray or pandas.DataFrame or pandas.Series |
| 6662 | Ranking groups. If X is a Pool, group_id must be defined into X |
| 6663 | top : unsigned integer, up to `pow(2, 32) / 2 - 1` |
| 6664 | NDCG, Number of top-ranked objects to calculate NDCG |
| 6665 | type : str |
| 6666 | NDCG, Metric_type: 'Base' or 'Exp' |
| 6667 | denominator : str |
| 6668 | NDCG, Denominator type: 'LogPosition' or 'Position' |
| 6669 | group_weight : list or numpy.ndarray or pandas.DataFrame or pandas.Series |
| 6670 | Group weights. |
| 6671 | thread_count : int, optional (default=-1) |
| 6672 | Number of threads to work with. |
| 6673 | Returns |
| 6674 | ------- |
| 6675 | NDCG@top : float |
| 6676 | higher is better |
| 6677 | """ |
| 6678 | def get_ndcg_metric_name(values, names): |
| 6679 | if np.all(np.equal(values, None)): |
| 6680 | return 'NDCG' |
| 6681 | return 'NDCG:' + ';'.join(['{}={}'.format(n, v) for v, n in zip(values, names) if v is not None]) |
| 6682 | |
| 6683 | if isinstance(X, Pool): |
| 6684 | if y is not None: |
| 6685 | raise CatBoostError("Wrong initializing y: X is catboost.Pool object, y must be initialized inside catboost.Pool.") |
| 6686 | y = X.get_label() |
| 6687 | if group_id is not None: |
| 6688 | raise CatBoostError("Wrong initializing group_id: X is catboost.Pool object, group_id must be initialized inside catboost.Pool.") |
| 6689 | group_id = X.get_group_id_hash() |
| 6690 | |
| 6691 | if y is None: |
| 6692 | raise CatBoostError("y must be initialized.") |
| 6693 | if group_id is None: |
| 6694 | raise CatBoostError("group_id must be initialized. If groups are not expected, pass an array of zeros") |
| 6695 | |
| 6696 | predictions = self.predict(X) |
| 6697 | return _eval_metric_util([y], [predictions], get_ndcg_metric_name([top, type, denominator], ['top', 'type', 'denominator']), None, group_id, group_weight, None, None, thread_count)[0] |
| 6698 | |
| 6699 | @staticmethod |
| 6700 | def _check_is_compatible_loss(loss_function): |