Skip to content

Commit

Permalink
[python][scikit-learn] add new attribute for used number of features (m…
Browse files Browse the repository at this point in the history
…icrosoft#3129)

* update number of features attribute

Fixes issue related to scikit-learn/scikit-learn#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 <nekit94-08@mail.ru>
  • Loading branch information
2 people authored and ChipKerchner committed Jun 10, 2020
1 parent 3e5cc03 commit ee7e789
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python-package/lightgbm/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'):
Expand Down

0 comments on commit ee7e789

Please sign in to comment.