Created
August 6, 2020 07:51
-
-
Save smly/52e634e98a4cd5bca07cf72d979984c5 to your computer and use it in GitHub Desktop.
(xfeat:PR#3) Test code and the result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
col target | |
0 Cat 1 | |
1 Dog 1 | |
2 Dog 0 | |
3 Dog 0 | |
4 Fox 0 | |
<class 'cudf.core.dataframe.DataFrame'> | |
col target col_le | |
0 Cat 1 0 | |
1 Dog 1 1 | |
2 Dog 0 1 | |
3 Dog 0 1 | |
4 Fox 0 2 | |
<class 'cudf.core.dataframe.DataFrame'> | |
col target | |
0 Cat 1 | |
1 Dog 1 | |
2 Dog 0 | |
3 Dog 0 | |
4 Fox 0 | |
col target col_te | |
0 Cat 1 1.0 | |
1 Dog 1 0.0 | |
2 Dog 0 0.5 | |
3 Dog 0 0.5 | |
4 Fox 0 0.0 | |
<class 'cudf.core.dataframe.DataFrame'> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import cudf | |
from xfeat.cat_encoder import TargetEncoder, LabelEncoder | |
df_train = cudf.from_pandas(pd.DataFrame({ | |
"col": ["Cat", "Dog", "Dog", "Dog", "Fox", "Cat", "Rabbit"], | |
"target": [1, 1, 0, 0, 0, 1, 1], | |
})) | |
print(df_train.head()) | |
print(type(df_train)) | |
encoder = LabelEncoder(input_cols=["col"]) | |
df_train_le = encoder.fit_transform(df_train) | |
print(df_train_le.head()) | |
print(type(df_train_le)) | |
df_train = cudf.from_pandas(pd.DataFrame({ | |
"col": ["Cat", "Dog", "Dog", "Dog", "Fox", "Cat", "Rabbit"], | |
"target": [1, 1, 0, 0, 0, 1, 1], | |
})) | |
print(df_train.head()) | |
target_encoder = TargetEncoder(input_cols=["col"], target_col="target") | |
df_train_te = target_encoder.fit_transform(df_train) | |
print(df_train_te.head()) | |
print(type(df_train_te)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment