MCPcopy Create free account
hub / github.com/dmlc/xgboost / enc_transform

Function enc_transform

demo/guide-python/cat_pipeline.py:71–81  ·  view source on GitHub ↗
(X: pd.DataFrame)

Source from the content-addressed store, hash-verified

69 enc = enc.fit(X_train[cat_feats])
70
71 def enc_transform(X: pd.DataFrame) -> pd.DataFrame:
72 # don't make change inplace so that we can have demonstrations for encoding
73 X = X.copy()
74 cat_cols = enc.transform(X[cat_feats])
75 for i, name in enumerate(cat_feats):
76 # create pd.Series based on the encoder
77 cat_cols[name] = pd.Categorical.from_codes(
78 codes=cat_cols[name].astype(np.int32), categories=enc.categories_[i]
79 )
80 X[cat_feats] = cat_cols
81 return X
82
83 # Encode the data based on fitted encoder.
84 X_train_enc = enc_transform(X_train)

Callers 1

nativeFunction · 0.85

Calls 2

copyMethod · 0.80
transformMethod · 0.80

Tested by

no test coverage detected