Utilities
Special Feature Classes
pytorch_tabular.CategoricalEmbeddingTransformer(tabular_model)
Bases: BaseEstimator
, TransformerMixin
Initializes the Transformer and extracts the neural embeddings.
PARAMETER | DESCRIPTION |
---|---|
tabular_model |
The trained TabularModel object
TYPE:
|
Source code in src/pytorch_tabular/categorical_encoders.py
fit(X, y=None)
fit_transform(X, y=None)
Encode given columns of X based on the learned embedding.
PARAMETER | DESCRIPTION |
---|---|
X |
DataFrame of features, shape (n_samples, n_features). Must contain columns to encode.
TYPE:
|
y |
Only for compatibility. Not used. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
pd.DataFrame
|
pd.DataFrame: The encoded dataframe |
Source code in src/pytorch_tabular/categorical_encoders.py
transform(X, y=None)
Transforms the categorical columns specified to the trained neural embedding from the model.
PARAMETER | DESCRIPTION |
---|---|
X |
DataFrame of features, shape (n_samples, n_features). Must contain columns to encode.
TYPE:
|
y |
Only for compatibility. Not used. Defaults to None.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
[description] |
RETURNS | DESCRIPTION |
---|---|
pd.DataFrame
|
pd.DataFrame: The encoded dataframe |
Source code in src/pytorch_tabular/categorical_encoders.py
pytorch_tabular.DeepFeatureExtractor(tabular_model, extract_keys=['backbone_features'], drop_original=True)
Bases: BaseEstimator
, TransformerMixin
Initializes the Transformer and extracts the neural features.
PARAMETER | DESCRIPTION |
---|---|
tabular_model |
The trained TabularModel object
TYPE:
|
Source code in src/pytorch_tabular/feature_extractor.py
fit(X, y=None)
fit_transform(X, y=None)
Encode given columns of X based on the learned features.
PARAMETER | DESCRIPTION |
---|---|
X |
DataFrame of features, shape (n_samples, n_features). Must contain columns to encode.
TYPE:
|
y |
Only for compatibility. Not used. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
pd.DataFrame
|
pd.DataFrame: The encoded dataframe |
Source code in src/pytorch_tabular/feature_extractor.py
transform(X, y=None)
Transforms the categorical columns specified to the trained neural features from the model.
PARAMETER | DESCRIPTION |
---|---|
X |
DataFrame of features, shape (n_samples, n_features). Must contain columns to encode.
TYPE:
|
y |
Only for compatibility. Not used. Defaults to None.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
[description] |
RETURNS | DESCRIPTION |
---|---|
pd.DataFrame
|
pd.DataFrame: The encoded dataframe |
Source code in src/pytorch_tabular/feature_extractor.py
Data Utilities
pytorch_tabular.utils.get_balanced_sampler(y_train)
Source code in src/pytorch_tabular/utils/data_utils.py
pytorch_tabular.utils.get_class_weighted_cross_entropy(y_train, mu=1.0)
Source code in src/pytorch_tabular/utils/data_utils.py
pytorch_tabular.utils.get_gaussian_centers(y, n_components)
Source code in src/pytorch_tabular/utils/data_utils.py
NN Utilities
pytorch_tabular.utils._initialize_layers(activation, initialization, layers)
Source code in src/pytorch_tabular/utils/nn_utils.py
pytorch_tabular.utils._initialize_kaiming(x, initialization, d_sqrt_inv)
Source code in src/pytorch_tabular/utils/nn_utils.py
pytorch_tabular.utils._linear_dropout_bn(activation, initialization, use_batch_norm, in_units, out_units, dropout)
Source code in src/pytorch_tabular/utils/nn_utils.py
pytorch_tabular.utils._make_ix_like(input, dim=0)
pytorch_tabular.utils.reset_all_weights(model)
Resets all parameters in a network.
PARAMETER | DESCRIPTION |
---|---|
model |
The model to reset the parameters of.
TYPE:
|
refs
- https://discuss.pytorch.org/t/how-to-re-set-alll-parameters-in-a-network/20819/6
- https://stackoverflow.com/questions/63627997/reset-parameters-of-a-neural-network-in-pytorch
- https://pytorch.org/docs/stable/generated/torch.nn.Module.html
Source code in src/pytorch_tabular/utils/nn_utils.py
pytorch_tabular.utils.to_one_hot(y, depth=None)
Takes integer with n dims and converts it to 1-hot representation with n + 1 dims.
The n+1'st dimension will have zeros everywhere but at y'th index, where it will be equal to 1.
PARAMETER | DESCRIPTION |
---|---|
y |
input integer (IntTensor, LongTensor or Variable) of any shape
|
depth |
the size of the one hot dimension
TYPE:
|
Source code in src/pytorch_tabular/utils/nn_utils.py
Python Utilities
pytorch_tabular.utils.getattr_nested(_module_src, _model_name)
pytorch_tabular.utils.ifnone(arg, default_arg)
pytorch_tabular.utils.check_numpy(x)
pytorch_tabular.utils.pl_load(path_or_url, map_location=None)
Loads a checkpoint.
PARAMETER | DESCRIPTION |
---|---|
path_or_url |
Path or URL of the checkpoint.
TYPE:
|
map_location |
a function,
TYPE:
|