Boost Sales Efficiency by harnessing K-Means and KNN for Geospatial Customer Optimization
Gain a competitive edge by integrating geographical insights into your sales strategies, resulting in substantial cost reductions and enhanced sales performance.
What happens in most companies, is you start off with a GREAT spread of customers over your sales force. Then, over time, the waters get muddied and a few years down the line you probably have something similar to figure 1.
Note: The different colors denote different reps and see how much they overlap. This article will deal with sorting this mess out.
For a stress-free solution, check out callcycles.com. Say goodbye to coding as we've got you covered, and then some.
We will be using KMEAN's as our initial algorithm to group the customers according to their locations. However, usual KMEAN's doesn't quite do the trick in our scenario, since KMEAN's can end up with very unbalanced areas. One rep could end up with 20 customers and another could end up with 150. So k-means-constrained to the rescue. We can give minimum and maximum for each area. So, first up, install using pip.
pip install k-means-constrained
Now, let's import the packages we need:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import folium
from k_means_constrained import KMeansConstrained
Now import your data into a data frame as I have below in figure 2. I have blocked out some data, but you get the point, you need the following fields:
You can use the code below to plot the existing customer base with each representative as a different colour.
Let's set up our training parameters:
Now, let's set up our KMEAN's parameters and run fit_predict. Importantly, we will want to save the centroids for each cluster. In our case, each centroid will be a central location for each representative's area or territory.
A little like the highest common denominator, let's use an APPLY to find the most common representative in a cluster and assign them to the whole cluster.
Well, KMEANS-constrained is great, but the constraints now cause a few outliers which we can use KNN to resolve. Figure 5 highlights the issue for you. Can you see one customer assigned to the brown representative, BUT it doesn't make sense…. It should actually be with the purple representative.
Easy to spot on a map and let's use KNN to resolve this.
First up, let's setup a train and test dataset. Now that we classified our data using KMEAN's, let's train a KNN model to predict based on the KMEAN's results. This will help us with the following:
Now that we trained, let's run a prediction on our test set and then measure accuracy. We should see above 92% accuracy of our model.
We have a KNN model, so let's predict for latitude/longitude on our entire dataset. This will help show us some outliers where KMEAN's made an odd choice due to the constraint of min/max customers per rep.
Now let's plot our results to see if KNN solved our outlier problem. Great, as you can see in figure 7, our outlier has been reassigned to the purple representative. Note, we do give it a black border so we can easily pick the outliers out.
In conclusion, optimizing your sales force territories can be a complex task, but with solutions like leveraging machine learning or visiting www.callcycles.com, you can streamline the process and maximize efficiency.
If you find the task daunting, head over to www.callcycles.com for a hassle-free experience. Let us take care of the details so you can focus on what matters most — driving your sales force towards success.