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

Method predict

python-package/lightgbmmt/basic.py:2437–2484  ·  view source on GitHub ↗

Make a prediction. Parameters ---------- data : string, numpy array, pandas DataFrame, H2O DataTable's Frame or scipy.sparse Data source for prediction. If string, it represents the path to txt file. num_iteration : int or None, optional (defa

(self, data, num_iteration=None,
                raw_score=False, pred_leaf=False, pred_contrib=False,
                data_has_header=False, is_reshape=True, **kwargs)

Source from the content-addressed store, hash-verified

2435 return ret
2436
2437 def predict(self, data, num_iteration=None,
2438 raw_score=False, pred_leaf=False, pred_contrib=False,
2439 data_has_header=False, is_reshape=True, **kwargs):
2440 """Make a prediction.
2441
2442 Parameters
2443 ----------
2444 data : string, numpy array, pandas DataFrame, H2O DataTable's Frame or scipy.sparse
2445 Data source for prediction.
2446 If string, it represents the path to txt file.
2447 num_iteration : int or None, optional (default=None)
2448 Limit number of iterations in the prediction.
2449 If None, if the best iteration exists, it is used; otherwise, all iterations are used.
2450 If <= 0, all iterations are used (no limits).
2451 raw_score : bool, optional (default=False)
2452 Whether to predict raw scores.
2453 pred_leaf : bool, optional (default=False)
2454 Whether to predict leaf index.
2455 pred_contrib : bool, optional (default=False)
2456 Whether to predict feature contributions.
2457
2458 .. note::
2459
2460 If you want to get more explanations for your model&#x27;s predictions using SHAP values,
2461 like SHAP interaction values,
2462 you can install the shap package (https://github.com/slundberg/shap).
2463 Note that unlike the shap package, with ``pred_contrib`` we return a matrix with an extra
2464 column, where the last column is the expected value.
2465
2466 data_has_header : bool, optional (default=False)
2467 Whether the data has header.
2468 Used only if data is string.
2469 is_reshape : bool, optional (default=True)
2470 If True, result is reshaped to [nrow, ncol].
2471 **kwargs
2472 Other parameters for the prediction.
2473
2474 Returns
2475 -------
2476 result : numpy array
2477 Prediction result.
2478 """
2479 predictor = self._to_predictor(copy.deepcopy(kwargs))
2480 if num_iteration is None:
2481 num_iteration = self.best_iteration
2482 return predictor.predict(data, num_iteration,
2483 raw_score, pred_leaf, pred_contrib,
2484 data_has_header, is_reshape)
2485
2486 def refit(self, data, label, decay_rate=0.9, **kwargs):
2487 """Refit the existing Booster by new data.

Callers 15

testMethod · 0.95
refitMethod · 0.45
train_predict_checkMethod · 0.45
test_regressionMethod · 0.45
test_lambdarankMethod · 0.45
test_binaryMethod · 0.45
test_rfMethod · 0.45
test_regressionMethod · 0.45

Calls 1

_to_predictorMethod · 0.95

Tested by 15

testMethod · 0.76
train_predict_checkMethod · 0.36
test_regressionMethod · 0.36
test_lambdarankMethod · 0.36
test_binaryMethod · 0.36
test_rfMethod · 0.36
test_regressionMethod · 0.36