This file contains hidden or 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
Dataset | n_rows | n_cols | objective | neg_pos_ratio | |
---|---|---|---|---|---|
adult | 45222 | 15 | binary_classification | 0.3295 | |
bank_marketing | 41188 | 20 | binary_classification | 0.127 | |
nyc_taxi | 1458644 | 26 | regression | NA | |
facebook_comments_vol | 199029 | 54 | regression | NA |
This file contains hidden or 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
trainer = Trainer(model, objective="binary", metrics=[(Accuracy)]) | |
trainer.fit(X_tab=X_tab, target=target, n_epochs=5, batch_size=256, val_split=0.2) |
This file contains hidden or 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
from pytorch_widedeep.models import TabTransformer | |
tabtransformer = TabTransformer( | |
column_idx=tab_preprocessor.column_idx, | |
embed_input=tab_preprocessor.embeddings_input, | |
continuous_cols=cont_cols, | |
shared_embed=True, | |
num_blocks=3, | |
) | |
model = WideDeep(deeptabular=tabtransformer) |
This file contains hidden or 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
embed_cols = [ | |
'workclass', | |
'education', | |
'marital_status', | |
'occupation', | |
'relationship', | |
'race' | |
] | |
tab_preprocessor = TabPreprocessor( | |
embed_cols=embed_cols, |
This file contains hidden or 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
trainer = Trainer(model, objective="binary", metrics=[(Accuracy)]) | |
trainer.fit(X_tab=X_tab, target=target, n_epochs=5, batch_size=256, val_split=0.2) |
This file contains hidden or 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
from pytorch_widedeep.models import TabResnet | |
tabresnet = TabResnet( | |
column_idx=tab_preprocessor.column_idx, | |
embed_input=tab_preprocessor.embeddings_input, | |
continuous_cols=cont_cols, | |
batchnorm_cont=True, | |
blocks_dims=[200, 100, 100], | |
mlp_hidden_dims=[100, 50], | |
) |
This file contains hidden or 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
from pytorch_widedeep import Trainer | |
from pytorch_widedeep.metrics import Accuracy | |
trainer = Trainer(model, objective="binary", metrics=[(Accuracy)]) | |
trainer.fit(X_tab=X_tab, target=target, n_epochs=5, batch_size=256, val_split=0.2) |
This file contains hidden or 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
from pytorch_widedeep.models import TabMlp, WideDeep | |
tabmlp = TabMlp( | |
mlp_hidden_dims=[200, 100], | |
column_idx=tab_preprocessor.column_idx, | |
embed_input=tab_preprocessor.embeddings_input, | |
continuous_cols=cont_cols, | |
batchnorm_cont=True, | |
) | |
model = WideDeep(deeptabular=tabmlp) |
This file contains hidden or 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
from pytorch_widedeep.preprocessing import TabPreprocessor | |
# define the embedding and continuous columns, and target | |
embed_cols = [ | |
('workclass', 6), | |
('education', 8), | |
('marital_status', 6), | |
('occupation',8), | |
('relationship', 6), | |
('race', 6)] |
This file contains hidden or 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 numpy as np | |
from sklearn.model_selection import train_test_split | |
adult = pd.read_csv("data/adult/adult.csv.zip") | |
adult.columns = [c.replace("-", "_") for c in adult.columns] | |
adult["income_label"] = (adult["income"].apply(lambda x: ">50K" in x)).astype(int) | |
adult.drop("income", axis=1, inplace=True) | |
for c in adult.columns: |