Package: rfmanalysis
Here’s the README.md in reStructuredText format:RFM AnalysisThis repository contains a Python implementation of RFM (Recency, Frequency, Monetary) analysis, a customer segmentation technique used in marketing and customer relationship management. The RFM analysis helps identify customer segments based on their purchasing behavior, allowing businesses to tailor their marketing strategies and customer retention efforts.RFMAnalysisTheRFMAnalysisclass provides methods to perform RFM analysis on customer transaction data. Here is an overview of the class and its methods:### Class InitializationRFMAnalysis(data,id_col,date_col,revenue_col)data: Pandas DataFrame containing customer transaction data.id_col: Column name representing the unique customer identifier.date_col: Column name representing the transaction date.revenue_col: Column name representing the transaction revenue.### Methodscreate_rfm_columns(): Creates the RFM columns (Recency, Frequency, Monetary) based on the transaction data.scale_rfm_columns(): Scales the RFM columns into quartiles (4 segments) for scoring.rfm_scores(): Calculates the RFM scores and segments for each customer.top_customers(): Sorts the customers by RFM segments in descending order.give_names_to_segments(): Assigns segment names to each RFM segment based on the RFM scores.segments_distribution(): Returns a DataFrame with the mean RFM values and segment counts.RFMVisualizerTheRFMVisualizerclass provides visualizations for RFM analysis. Here is an overview of the class and its methods:### Static Methodsplot_rfm(rfm_data): Plots the distribution of RFM scores.visualize_segments(rfm_data): Displays a treemap visualization of customer segments.segment_distribution_barplot(rfm_data): Displays a bar chart of segment counts.segment_boxplot(rfm_data): Displays boxplots of RFM scores for each segment.segment_comparison(rfm_data): Displays bar charts comparing average RFM scores for each segment.UsageTo use theRFMAnalysisandRFMVisualizerclasses, follow these steps:Load the customer transaction data into a Pandas DataFrame.Instantiate theRFMAnalysisclass, providing the necessary parameters.Call the methods of theRFMAnalysisclass to perform RFM analysis and generate segment information.Instantiate theRFMVisualizerclass.Call the visualization methods of theRFMVisualizerclass, passing the RFM data generated by theRFMAnalysisclass.Here’s an example of how to use these classes:importpandasaspdfromRFMAnalysisimportRFMAnalysisfromRFMVisualizerimportRFMVisualizer# Load the customer transaction datadata=pd.read_csv('customer_transactions.csv')# Perform RFM analysisanalysis=RFMAnalysis(data,'customer_id','transaction_date','revenue')analysis.create_rfm_columns()analysis.scale_rfm_columns()analysis.rfm_scores()analysis.top_customers()analysis.give_names_to_segments()# Visualize RFM analysisvisualizer=RFMVisualizer()visualizer.plot_rfm(analysis.rfm_data)visualizer.visualize_segments(analysis.rfm_data)
visualizer.segment_distribution_barplot(analysis.rfm_data)
visualizer.segment_boxplot(analysis.rfm_data)
visualizer.segment_comparison(analysis.rfm_data)RequirementsThe implementation requires the following libraries to be installed:pandasseabornmatplotlibsquarifyYou can install them usingpip:pipinstallpandasseabornmatplotlibsquarifyLicenseThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.History0.1.0 (2023-05-16)First release on PyPI.