Skip to content

Commit 39216f0

Browse files
committed
get_feature_names() rebased commit
1 parent 9808810 commit 39216f0

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

sklearn/preprocessing/data.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2873,3 +2873,37 @@ def inverse_transform(self, X):
28732873
X_tr[mask, idx] = None
28742874

28752875
return X_tr
2876+
2877+
def get_feature_names(self, input_features=None):
2878+
"""
2879+
Return feature names for output features
2880+
2881+
Parameters
2882+
----------
2883+
input_features : list of string, length n_features, optional
2884+
String names for input features if available. By default,
2885+
"x0", "x1", ... "xn_features" is used.
2886+
2887+
Returns
2888+
-------
2889+
output_feature_names : list of string, length n_output_features
2890+
2891+
"""
2892+
cats = self.categories_
2893+
feature_names = []
2894+
if input_features is None:
2895+
input_features = ['x%d' % i for i in range(len(cats))]
2896+
2897+
cats2=[]
2898+
for i in range(len(cats)):
2899+
temp=[]
2900+
for t in cats[i]:
2901+
temp.append(str(t))
2902+
cats2.append(np.array(temp))
2903+
2904+
for i in range(len(cats)):
2905+
t = [input_features[i] + '_' +f for f in cats2[i] ]
2906+
feature_names.append(t)
2907+
2908+
feature_names = np.concatenate(feature_names)
2909+
return feature_names

0 commit comments

Comments
 (0)