manujosephv / pytorch_tabular

A standard framework for modelling Deep Learning Models for tabular data
https://pytorch-tabular.readthedocs.io/
MIT License
1.38k stars 140 forks source link

How can I get the original value? #504

Open lwq-star opened 1 day ago

lwq-star commented 1 day ago

PyTorch Tabular has the following functions : Continuous features are scaled automatically using StandardScaler and target transformation can be enabled with a parameter. This will also handle the inverse tranformation automatically.

But how can I to convert the predicted values ​​obtained after the original data is input into the model for regression model into the original scale?

scikit-learn have power.inverse_transform and scaler.inverse_transform functions to get original scale but PyTorch Tabular?

This is my code for data preprocessing:

data_config = DataConfig(
    target=['Abovegroun'],  
    continuous_cols=df.columns.tolist(),  
    categorical_cols=[],  
    normalize_continuous_features=True,  
    continuous_feature_transform="yeo-johnson",  
)
dosubot[bot] commented 1 day ago

Hey @lwq-star! I'm here to assist you with any bugs, questions, or contributions you have. Let's tackle this issue together!

To convert the predicted values obtained from a regression model in PyTorch Tabular back to the original scale, you can use the inverse_transform method provided by the target_transforms attribute of the datamodule. This is similar to how scikit-learn uses power.inverse_transform and scaler.inverse_transform functions. Here is an example of how you can do it:

if self.datamodule.do_target_transform:
    for i, target_col in enumerate(self.config.target):
        pred_df[f"{target_col}_prediction"] = self.datamodule.target_transforms[i].inverse_transform(
            point_predictions[:, i].reshape(-1, 1)
        )

This code snippet shows how the inverse transformation is applied to the predicted values to convert them back to the original scale. The target_transforms is a list of transformers applied to each target column, and inverse_transform is used to revert the transformation [1].

To continue talking to Dosu, mention @dosu.

lwq-star commented 1 day ago

Hey @lwq-star! I'm here to assist you with any bugs, questions, or contributions you have. Let's tackle this issue together!嘿 !我随时为您提供帮助,解决您遇到的任何错误、问题或贡献。让我们一起来解决这个问题吧!

To convert the predicted values obtained from a regression model in PyTorch Tabular back to the original scale, you can use the inverse_transform method provided by the target_transforms attribute of the datamodule. This is similar to how scikit-learn uses power.inverse_transform and scaler.inverse_transform functions. Here is an example of how you can do it:要将 PyTorch Tabular 中的回归模型获得的预测值转换回原始比例,可以使用datamoduletarget_transforms属性提供的inverse_transform方法。这类似于 scikit-learn 使用power.inverse_transformscaler.inverse_transform函数的方式。以下是如何执行此操作的示例:

if self.datamodule.do_target_transform:
    for i, target_col in enumerate(self.config.target):
        pred_df[f"{target_col}_prediction"] = self.datamodule.target_transforms[i].inverse_transform(
            point_predictions[:, i].reshape(-1, 1)
        )

This code snippet shows how the inverse transformation is applied to the predicted values to convert them back to the original scale. The target_transforms is a list of transformers applied to each target column, and inverse_transform is used to revert the transformation [1].此代码片段显示了如何将逆变换应用于预测值以将其转换回原始比例。 target_transforms是应用于每个目标列的转换器列表, inverse_transform用于恢复转换[1]

To continue talking to Dosu, mention @dosu.继续跟Dosu说话,提一下。

Wrong demonstration !