From ee7e789699810cc51b8f577c1c8040ca16f07a9d Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 3 Jun 2020 02:09:58 +0800 Subject: [PATCH] [python][scikit-learn] add new attribute for used number of features (#3129) * update number of features attribute Fixes issue related to https://github.com/scikit-learn/scikit-learn/issues/17353 (see SLEP010 https://scikit-learn-enhancement-proposals.readthedocs.io/en/latest/slep010/proposal.html). * Update sklearn.py * set public attribute in fit method Reverted ```n_features``` property, and inserted the public attribute ```n_features_in_```. * Update documentation * Update python-package/lightgbm/sklearn.py Co-authored-by: Nikita Titov --- python-package/lightgbm/sklearn.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python-package/lightgbm/sklearn.py b/python-package/lightgbm/sklearn.py index f0dc618918c5..d86e510104e8 100644 --- a/python-package/lightgbm/sklearn.py +++ b/python-package/lightgbm/sklearn.py @@ -257,6 +257,8 @@ def __init__(self, boosting_type='gbdt', num_leaves=31, max_depth=-1, ---------- n_features_ : int The number of features of fitted model. + n_features_in_ : int + The number of features of fitted model. classes_ : array of shape = [n_classes] The class label array (only for classification problem). n_classes_ : int @@ -563,6 +565,8 @@ def fit(self, X, y, sample_weight = np.multiply(sample_weight, class_sample_weight) self._n_features = _X.shape[1] + # set public attribute for consistency + self.n_features_in_ = self._n_features def _construct_dataset(X, y, sample_weight, init_score, group, params, categorical_feature='auto'):