Skip to content

DeleteVars

DeleteVars

The function removes variables to be deleted from training and testing sets and removes from the dataframe of sign expectation.

Parameters:

  • x_train: pd.DataFrame
    A pandas DataFrame with training data set.
  • x_test: pd.DataFrame
    A pandas DataFrame with testing data set.
  • df_sign: pd.DataFrame
    A pandas DataFrame with coefficients expectation.
  • vars_to_remove: list
    A list of variables to be removed.

Returns:

  • final_data: dict
  • Keys:
    x_train_new
    x_test_new
    df_sign_new

Exceptions:

  • ValueError:
    Raised if the columns of x_test and x_train are not identical.
    Raised if x_train parameter is not a pandas DataFrame.
    Raised if the number of columns in x_train and x_test are not identical.
    Raised if x_test parameter is not a pandas DataFrame.
    Raised if df_sign parameter is not a pandas DataFrame.
    Raised if vars_to_remove parameter is not a list.
    Raised if the number of x_train columns is not identical with the length of df_sign.
    Raised if any item in vars_to_remove is not in x_train.columns.

Example:

import pandas as pd
from combat.utitities import DeleteVars

# Sample input data
x_train = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
x_test = pd.DataFrame({'A': [7, 8, 9], 'B': [10, 11, 12]})
df_sign = pd.DataFrame({'A': [0.1, 0.2], 'B': [0.3, 0.4]})
vars_to_remove = ['B']

# Remove variables
result = DeleteVars(x_train, x_test, df_sign, vars_to_remove)