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 ofx_testandx_trainare not identical.
Raised ifx_trainparameter is not a pandas DataFrame.
Raised if the number of columns inx_trainandx_testare not identical.
Raised ifx_testparameter is not a pandas DataFrame.
Raised ifdf_signparameter is not a pandas DataFrame.
Raised ifvars_to_removeparameter is not a list.
Raised if the number ofx_traincolumns is not identical with the length ofdf_sign.
Raised if any item invars_to_removeis not inx_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)