Churn Prediction is a collection of python scripts to explore how to create churn prediction models using the BG/NBG Pareto models.
Most importantly, churn prediction and training the above mentioned models is used as a playground to investigate the integration between python Pandas and database systems.
The idea is that the database system can be used to do the heavy lifting of feature generation when the volume of the data is large, extracting only the final feature table that is going to be used for training.
As raw data, events that are generated by RudderStack and correspond to the customer behavior are considered.
What you will find in this repo
๐ csv2parquet is a small utility script that takes a csv as input and turns it into a parquet file. It uses the arrow python library for parsing and generating the parquet file.
๐ train_model This script attempts to train a model assuming event data are stored into a parquet file. To make it scalable we are using duckdb to query the data on Parquet. Duckdb exploits the parquet format to execute the queries. After the features have been generated the model is trained and saved.
๐ train_model_snow This script is doing the exact same thing as the previous one but this time we assume the data to live on Snowflake. The feature generation happens on snowflake and data is returned to the script to be used for training the model which is then saved.
The Snowflake python connector supports Arrow as a serialization format, this has the benefit of reducing the ser/des that have to happen and hopefully increasing the performance. The data is returned back into a panda's dataframe so no conversion needs to happen there.
In a similar way, Duckdb returns the data into a dataframe format that again is used directly for training the model. Duckdb is still not as mature as snowflake when it comes to data manipulation functions that are supported and there's where the conversion to a dataframe really helped. Some of the manipulation happened after the data was loaded in memory.
BigQuery also offers arrow serialization over their APIs, as a next step I'll look into it and see how it works. Then we can run some tests around performance and scalability.
Keep in mind that the model training is single threaded, when I'm talking about performance and scalability here I'm talking only about shaping the data and calculating the features that we need.