I have the following column CHARGEOFFCOMPLETEDATE it is the date a business customer in…
- User
I have the following column CHARGEOFF_COMPLETE_DATE it is the date a business customer in my credit portfolio charged off. I am wondering what feature could i create that could be useful in a predictive model i am building to predict charge offs, however in my dataset i also have active customers so their CHARGEOFF_COMPLETE_DATE would be empty or blank
- Assistant
You can create several features from the CHARGEOFF_COMPLETE_DATE column, which could be useful for your predictive model. For active customers with an empty or blank CHARGEOFF_COMPLETE_DATE, you can fill those missing values with a specific date or value as a placeholder. Here are some feature ideas you could create:
-
charged_off: Create a binary feature indicating whether a customer has charged off or not (1 for charged off, 0 for active customers). -
days_since_chargeoff: Calculate the number of days between the CHARGEOFF_COMPLETE_DATE and a reference date (e.g., the date when you created the dataset or a constant date like 'today'). For active customers, use the placeholder date you've chosen. -
chargeoff_month: Extract the month from the CHARGEOFF_COMPLETE_DATE. For active customers, use the placeholder date you've chosen.
-
- User
can you list the python code on how i can do it
- Assistant
Sure, here's an example of Python code using the pandas library to create the suggested features:
import pandas as pd from datetime import datetime, timedelta # Assuming your dataset is in a pandas DataFrame called df # You might need to adjust the following line depending on how the date is formatted in your dataset df['CHARGEOFF_COMPLETE_DATE'] = pd.to_datetime(df['CHARGEOFF_COMPLETE_DATE'], errors='coerce') # Set a placeholder date for active customers (e.g., 9999-12-31) placeholder_date = datetime(9999, 12, 31) df.loc[df['CHARGEOFF_COMPLETE_DATE'].isnull(), 'CHARGEOFF_COMPLETE_DATE'] = placeholder_date # Create the charged_off binary feature df['charged_off'] = (df['CHARGEOFF_COMPLETE_DATE'] != placeholder_date).astype(int) # Create the days_since_chargeoff feature reference_date = datetime.now() df['days_since_chargeoff'] = (reference_date - df['CHARGEOFF_COMPLETE_DATE']).dt.days # Create the chargeoff_month, chargeoff_quarter, and chargeoff_year features df['chargeoff_month'] = df['CHARGEOFF_COMPLETE_DATE'].dt.month df['chargeoff_quarter'] = df['CHARGEOFF_COMPLETE_DATE'].dt.quarter df['chargeoff_year'] = df['CHARGEOFF_COMPLETE_DATE'].dt.year - User
What features would you create based on the below columns, assuming the same columns below the data was available for 12 months previous, from month 202203 to 202303: ALLOW_AUTO_LIMIT_INCREASE_202303 0 AMOUNT_FINANCECHARGES_BILLED_LIFETIME_202303 0 AMOUNT_FINANCECHARGES_BILLED_PREVIOUSYEAR_202303 0 AMOUNT_FINANCECHARGES_BILLED_YEARTODATE_202303 0 AMOUNT_FINANCECHARGES_OUTSTANDING_FEE_202303 0 AMOUNT_FINANCECHARGES_OUTSTANDING_PUR_202303 0 AMOUNT_FINANCECHARGES_PAID_LIFETIME_ON_ACCOUNT_202303 0 AMOUNT_FINANCECHARGES_PAID_PREVIOUSYEAR_202303 0 AMOUNT_FINANCECHARGES_PAID_YEARTODATE_202303 0 AMOUNT_OF_LAST_LIMIT_INCREASEORDECREASE_ON_ACCOUNT_CREDITLIMIT_202303 0 LAST_AMOUNT_NON_SUFFICIENT_FUNDS_PAYMENT_ONACCOUNT_202303 0 AMOUNT_LAST_PAYMENT_202303 0 AMOUNT_LAST_PURCHASE_202303 0 AMOUNT_NON_SUFFICENT_FUNDS_PAYMENTS_LIFETIME_202303 0 AMOUNT_OVERLIIT_202303 0 AMOUNT_OF_ALL_PAYMENTS_POSTEDTOACCOUNT_LIFETIME_202303 0 AMOUNT_OF_ALL_PURCHASES_LIFETIME_202303 0 HIGHEST_BALANCE_EVERREACHED_LIFETIME_202303 0 CSRW_ACR_LTD_202303 0 CSRW_ADJ_LTD_202303 0 CSRW_RDM_LTD_202303 0 CURRENT_BALANCE_FEE_202303 0 CURRENT_BALANCE_PURCHASE_202303 0 CURRENT_PUR_OUTSTANDING_AMOUNT_202303 0
- Assistant
You can create some aggregated and trend-based features from these columns for your predictive model. Here's a list of features you can create:
- User
Before i start to do feature enginerring, i have ensured their is no missing or null values in any of my raw columns and data, but now I have some columns which can have high values as i don't know what is the best way to treat these before doing feature enginerring, for example i have columns like the credit limit which can range from 500 to 1000000 and same with others like balances etc.
What way can i treat my credit limit columns, below is df.describe on my credit limit:
CREDITLIMIT_202303 CREDITLIMIT_202302 CREDITLIMIT_202301 CREDITLIMIT_202212 CREDITLIMIT_202211 CREDITLIMIT_202210 CREDITLIMIT_202209 CREDITLIMIT_202208 CREDITLIMIT_202207 CREDITLIMIT_202206 CREDITLIMIT_202205 CREDITLIMIT_202204 CREDITLIMIT_202203 count 32575.000000 32575.000000 32575.000000 32575.000000 32575.000000 32575.000000 32575.000000 32575.000000 32575.000000 32575.000000 32575.000000 32575.000000 32575.000000 mean 1768.571640 2576.038619 2576.731573 2576.253231 2576.657682 2542.681412 2559.309440 2554.210008 2557.507905 2550.245342 2552.063331 2542.250437 2543.716899 std 4117.646069 5353.145319 5360.626910 5363.803946 5393.207338 5339.163064 5378.896495 5381.226659 5735.043678 5724.348387 5735.882196 5733.416593 5738.345361 min 0.000100 0.000100 0.000100 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 25% 500.000000 500.000000 500.000000 500.000000 500.000000 500.000000 500.000000 500.000000 500.000000 500.000000 500.000000 500.000000 500.000000 50% 500.000000 501.000000 501.000000 501.000000 501.000000 501.000000 501.000000 501.000000 501.000000 501.000000 501.000000 501.000000 501.000000 75% 938.000000 1500.000000 1500.000000 1500.000000 1500.000000 1500.000000 1500.000000 1500.000000 1500.000000 1500.000000 1500.000000 1440.000000 1400.000000 max 82500.000000 95000.000000 95000.000000 95000.000000 100000.000000 100000.000000 100000.000000 100000.000000 364000.000000 364000.000000 364000.000000 364000.000000 364000.000000
- Assistant
To treat and normalize high-value columns like credit limit, you can apply different scaling techniques. Some common techniques are:
- Min-Max Scaling: Scale the values so that they lie between a specific range, usually [0, 1]. This method might be sensitive to outliers, though.
- Standard Scaling: Scale the values by subtracting the mean and dividing by the standard deviation. This produces features with zero mean and unit variance.
- Log Transformation: Take the logarithm of the values to compress the scale and reduce the impact of outliers.
Here's an example of how to apply these scaling techniques using Python and the pandas library:
import pandas as pd data = {...} # Your data here as a dictionary df = pd.DataFrame(data) # Choose the columns you want to scale credit_limit_columns = df.filter(regex='^CREDITLIMIT_').columns # Min-Max Scaling df_minmax = df.copy() for col in credit_limit_columns: min_val = df[col].min() max_val = df[col].max() df_minmax[col] = (df[col] - min_val) / (max_val - min_val) # Standard Scaling df_standard = df.copy() for col in credit_limit_columns: mean_val = df[col].mean() std_val = df[col].std() df_standard[col] = (df[col] - mean_val) / std_val # Log Transformation df_log = df.copy() for col in credit_limit_columns: df_log[col] = df[col].apply(lambda x: np.log(x + 1)) # +1 to avoid issues with log(0) - User
Would robust scaler be better to use than log transofrmation or what would be the best or difference between them, and do they also take into consideration of not leaving the minimum value to be 0 because if i am calculating ratio features dividing by zero could cause issues so can we handle these issues as well, plus below a list of all columns i would want to scale on like the credit limit columns so how can i use that:
amount_last_payment_columns current_balance_columns amount_financecharges_billed_lifetime_columns amount_financecharges_billed_previousyear_columns amount_financecharges_billed_year_to_date_columns amount_financecharges_outstanding_fee_columns amount_financecharges_outstanding_pur_columns amount_financecharges_paid_lifetime_on_account_columns amount_financecharges_paid_previous_year_columns amount_financecharges_paid_year_to_date_columns amount_of_last_limit_increase_or_decrease_on_account_creditlimit_columns last_amount_non_sufficentfunds_payment_on_account_columns amount_last_purchase_columns AMOUNT_NON_SUFFICENT_FUNDS_PAYMENTS_LIFETIME_columns AMOUNT_OVERLIMIT_columns
AMOUNT_OF_ALL_PAYMENTS_POSTED_TO_ACCOUNT_LIFETIME_columns AMOUNT_OF_ALL_PURCHASES_LIFETIME_columns HIGHEST_BALANCE_EVERREACHED_LIFETIME_columns CURRENT_BALANCE_FEE_columns CURRENT_BALANCE_PURCHASE_columns CURRENT_PUR_OUTSTANDING_AMOUNT_columns
- Assistant
The Robust Scaler could indeed be a better option for scaling these columns. The Robust Scaler is less sensitive to outliers because it uses the median and the interquartile range (IQR) instead of the mean and standard deviation. The Log Transformation is useful for compressing the scale on non-negative values and reducing the impact of outliers, but it might not handle extreme values as well as the Robust Scaler.
Regarding your concern about leaving the minimum value to be 0, you can apply the Robust Scaler and then add a constant value to every scaled column to ensure that there are no values equal to 0. Be cautious with this approach, as adding a constant might lead to incorrect assumptions in your model, so it's important to analyze the impact it would have on your specific use case.