How to use 'sklearn preprocessing labelencoder' in Python

Every line of 'sklearn preprocessing labelencoder' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
103def fit_transform(self, X, y=None):
104 """Encode categorical columns into label encoded columns
105
106 Args:
107 X (pandas.DataFrame): categorical columns to encode
108
109 Returns:
110 X (pandas.DataFrame): label encoded columns
111 """
112
113 self.label_encoders = [None] * X.shape[1]
114 self.label_maxes = [None] * X.shape[1]
115
116 for i, col in enumerate(X.columns):
117 self.label_encoders[i], self.label_maxes[i] = \
118 self._get_label_encoder_and_max(X[col])
119
120 X.loc[:, col] = X[col].fillna(NAN_INT).map(self.label_encoders[i]).fillna(0)
121
122 return X
48def fit_transform(self, X, y=None):
49 is_sparse = scipy.sparse.issparse(X)
50 X = self._fit(X)
51 if is_sparse:
52 return X
53 elif isinstance(X, np.ndarray):
54 return X
55 else:
56 return X.toarray()

Related snippets