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

Method predict

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

Return the predicted value for each sample. Parameters ---------- X : array-like or sparse matrix of shape = [n_samples, n_features] Input features matrix. raw_score : bool, optional (default=False) Whether to predict raw scores. num_i

(self, X, raw_score=False, num_iteration=None,
                pred_leaf=False, pred_contrib=False, **kwargs)

Source from the content-addressed store, hash-verified

620 return self
621
622 def predict(self, X, raw_score=False, num_iteration=None,
623 pred_leaf=False, pred_contrib=False, **kwargs):
624 """Return the predicted value for each sample.
625
626 Parameters
627 ----------
628 X : array-like or sparse matrix of shape = [n_samples, n_features]
629 Input features matrix.
630 raw_score : bool, optional (default=False)
631 Whether to predict raw scores.
632 num_iteration : int or None, optional (default=None)
633 Limit number of iterations in the prediction.
634 If None, if the best iteration exists, it is used; otherwise, all trees are used.
635 If <= 0, all trees are used (no limits).
636 pred_leaf : bool, optional (default=False)
637 Whether to predict leaf index.
638 pred_contrib : bool, optional (default=False)
639 Whether to predict feature contributions.
640
641 .. note::
642
643 If you want to get more explanations for your model&#x27;s predictions using SHAP values,
644 like SHAP interaction values,
645 you can install the shap package (https://github.com/slundberg/shap).
646 Note that unlike the shap package, with ``pred_contrib`` we return a matrix with an extra
647 column, where the last column is the expected value.
648
649 **kwargs
650 Other parameters for the prediction.
651
652 Returns
653 -------
654 predicted_result : array-like of shape = [n_samples] or shape = [n_samples, n_classes]
655 The predicted values.
656 X_leaves : array-like of shape = [n_samples, n_trees] or shape = [n_samples, n_trees * n_classes]
657 If ``pred_leaf=True``, the predicted leaf of every tree for each sample.
658 X_SHAP_values : array-like of shape = [n_samples, n_features + 1] or shape = [n_samples, (n_features + 1) * n_classes]
659 If ``pred_contrib=True``, the feature contributions for each sample.
660 """
661 if self._n_features is None:
662 raise LGBMNotFittedError("Estimator not fitted, call `fit` before exploiting the model.")
663 if not isinstance(X, (DataFrame, DataTable)):
664 X = _LGBMCheckArray(X, accept_sparse=True, force_all_finite=False)
665 n_features = X.shape[1]
666 if self._n_features != n_features:
667 raise ValueError("Number of features of the model must "
668 "match the input. Model n_features_ is %s and "
669 "input n_features is %s "
670 % (self._n_features, n_features))
671 return self._Booster.predict(X, raw_score=raw_score, num_iteration=num_iteration,
672 pred_leaf=pred_leaf, pred_contrib=pred_contrib, **kwargs)
673
674 @property
675 def n_features_(self):

Callers 1

predict_probaMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected