This tutorial explains how to use feature importance from pyrasgo to perform backward stepwise feature selection. The feature importance used is calculated from SHAP values from catboost.
This notebook will prune the features to model arrival delay for flights in and out of NYC in 2013.
This tutorial uses:
Enter your email and password to create an account. This account gives you free access to the Rasgo API which will calculate dataframe profiles, generate feature importance score, and produce feature explainability for you analysis. In addition, this account allows you to maintain access to your analysis and share with your colleagues.
Note: This only needs to be run the first time you use pyrasgo.
#pyrasgo.register(email='<your email>', password='<your password>')
Enter the email and password you used at registration to connect to Rasgo.
rasgo = pyrasgo.login(email='<your email>', password='<your password>')
Create experiment to track the changes in performance
Activated existing experiment with name Stepwise Feature Selection Tutorial for dataframe: UjNaU_zBWCfXrKzpEF5hN5JNkMGQnprAn6iLhn4qfNA
The data is from rdatasets imported using the Python package statsmodels.
This should return a table resembling something like this:
As this model will predict arrival delay, the Null values are caused by flights did were cancelled or diverted. These can be excluded from this analysis.
Create a function that incremental removes the feature with the lowest feature importance as calculated by PyRasgo until the RMSE stops decreasing.
Call backward_selection on the modeling dataframe. reduced_df will contain the selected features and will be our reduced modeling dataset.
Importance URL: https://app.rasgoml.com/dataframes/UjNaU_zBWCfXrKzpEF5hN5JNkMGQnprAn6iLhn4qfNA/importance5.774396196448282 with 25Prune Method: Keeping top 24 featuresImportance URL: https://app.rasgoml.com/dataframes/UjNaU_zBWCfXrKzpEF5hN5JNkMGQnprAn6iLhn4qfNA/importanceDropped features not in top 24: ['year']Importance URL: https://app.rasgoml.com/dataframes/UjNaU_zBWCfXrKzpEF5hN5JNkMGQnprAn6iLhn4qfNA/importance5.622926184499909 with 24Prune Method: Keeping top 23 featuresImportance URL: https://app.rasgoml.com/dataframes/UjNaU_zBWCfXrKzpEF5hN5JNkMGQnprAn6iLhn4qfNA/importanceDropped features not in top 23: ['sched_dep_time']Importance URL: https://app.rasgoml.com/dataframes/UjNaU_zBWCfXrKzpEF5hN5JNkMGQnprAn6iLhn4qfNA/importance6.0614605291484205 with 23Prune Method: Keeping top 22 featuresImportance URL: https://app.rasgoml.com/dataframes/UjNaU_zBWCfXrKzpEF5hN5JNkMGQnprAn6iLhn4qfNA/importanceDropped features not in top 22: ['tailnum']Importance URL: https://app.rasgoml.com/dataframes/UjNaU_zBWCfXrKzpEF5hN5JNkMGQnprAn6iLhn4qfNA/importance5.669525870310706 with 22Prune Method: Keeping top 21 featuresImportance URL: https://app.rasgoml.com/dataframes/UjNaU_zBWCfXrKzpEF5hN5JNkMGQnprAn6iLhn4qfNA/importanceDropped features not in top 21: ['sched_dep_minute']Importance URL: https://app.rasgoml.com/dataframes/UjNaU_zBWCfXrKzpEF5hN5JNkMGQnprAn6iLhn4qfNA/importance5.682320841457851 with 21Prune Method: Keeping top 20 featuresImportance URL: https://app.rasgoml.com/dataframes/UjNaU_zBWCfXrKzpEF5hN5JNkMGQnprAn6iLhn4qfNA/importanceDropped features not in top 20: ['dep_minute']Importance URL: https://app.rasgoml.com/dataframes/UjNaU_zBWCfXrKzpEF5hN5JNkMGQnprAn6iLhn4qfNA/importance5.9402484082388 with 20Prune Method: Keeping top 19 featuresImportance URL: https://app.rasgoml.com/dataframes/UjNaU_zBWCfXrKzpEF5hN5JNkMGQnprAn6iLhn4qfNA/importanceDropped features not in top 19: ['sched_dep_hour']Importance URL: https://app.rasgoml.com/dataframes/UjNaU_zBWCfXrKzpEF5hN5JNkMGQnprAn6iLhn4qfNA/importance6.31078646630211 with 19