MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / LGBMRanker

Class LGBMRanker

python-package/lightgbmmt/sklearn.py:899–947  ·  view source on GitHub ↗

LightGBM ranker.

Source from the content-addressed store, hash-verified

897
898
899class LGBMRanker(LGBMModel):
900 """LightGBM ranker."""
901
902 def fit(self, X, y,
903 sample_weight=None, init_score=None, group=None,
904 eval_set=None, eval_names=None, eval_sample_weight=None,
905 eval_init_score=None, eval_group=None, eval_metric=None,
906 eval_at=[1, 2, 3, 4, 5], early_stopping_rounds=None, verbose=True,
907 feature_name='auto', categorical_feature='auto',
908 callbacks=None, init_model=None):
909 """Docstring is inherited from the LGBMModel."""
910 # check group data
911 if group is None:
912 raise ValueError("Should set group for ranking task")
913
914 if eval_set is not None:
915 if eval_group is None:
916 raise ValueError("Eval_group cannot be None when eval_set is not None")
917 elif len(eval_group) != len(eval_set):
918 raise ValueError("Length of eval_group should be equal to eval_set")
919 elif (isinstance(eval_group, dict)
920 and any(i not in eval_group or eval_group[i] is None for i in range_(len(eval_group)))
921 or isinstance(eval_group, list)
922 and any(group is None for group in eval_group)):
923 raise ValueError("Should set group for all eval datasets for ranking task; "
924 "if you use dict, the index should start from 0")
925
926 self._eval_at = eval_at
927 super(LGBMRanker, self).fit(X, y, sample_weight=sample_weight,
928 init_score=init_score, group=group,
929 eval_set=eval_set, eval_names=eval_names,
930 eval_sample_weight=eval_sample_weight,
931 eval_init_score=eval_init_score, eval_group=eval_group,
932 eval_metric=eval_metric,
933 early_stopping_rounds=early_stopping_rounds,
934 verbose=verbose, feature_name=feature_name,
935 categorical_feature=categorical_feature,
936 callbacks=callbacks, init_model=init_model)
937 return self
938
939 _base_doc = LGBMModel.fit.__doc__
940 fit.__doc__ = (_base_doc[:_base_doc.find('eval_class_weight :')]
941 + _base_doc[_base_doc.find('eval_init_score :'):])
942 _base_doc = fit.__doc__
943 _before_early_stop, _early_stop, _after_early_stop = _base_doc.partition('early_stopping_rounds :')
944 fit.__doc__ = (_before_early_stop
945 + 'eval_at : list of int, optional (default=[1, 2, 3, 4, 5])\n'
946 + ' ' * 12 + 'The evaluation positions of the specified metric.\n'
947 + ' ' * 8 + _early_stop + _after_early_stop)

Callers

nothing calls this directly

Calls 2

partitionMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected