0
$\begingroup$

Im using real customer csv files from my ecommerce store. I was initially going to use k cluster with 2 values. I want the two values to be Province Code, and amount spend on my store. This will eventually show which region spends the most money at my store. However, the province codes are represented as 'CA, QC, UT, ... and you can't really use a string for a k cluster.

So was thinking of assigning a numerical value to each code and plotting it that way but I dont think that would make sense for k cluster. Any ideas on how i can implement ML another way? Ill provide a sample of my cleaned csv. I cant provide the original since it is illegal for me to give out customers addresses. enter image description here

$\endgroup$

3 Answers 3

0
$\begingroup$

Your problem most likely does not require a machine learning solution. If you are interested in the task, "given that a customer is from state X, predict how much the customer will spend", you can compute the median/mean of TotalSpent for each state. Consider plotting the result to display both variance and median/mean, e.g., by using a boxplot.

import seaborn as sns
import pandas as pd
df = pd.read_csv('data.csv')  
sns.boxplot(data=df, x="Province Code", y="Total Spent")
$\endgroup$
2
  • $\begingroup$ Will do, thank you for your help. I still want to try and implement ml just for practice, do you have any ideas on how I can do that with customer data? I run my ecommerce store thru Shopify and their csv files basically just give me the customers contact and location so i can really only use their location and how much they spent, but if i had a third variable such as where they were referred (instagram, tiktok, google, etc) is there any shot of implementing machine learning? trying to get a project on my resume haha $\endgroup$
    – ChickenJoe
    Commented Dec 17, 2022 at 8:11
  • $\begingroup$ @ChickenJoe If you're running an ecommerce store and looking for help with predicting sales, I suggest trying Cross Validated (the SE for statistics), or reading through a book on regressions. You probably don't want to use clustering for this task--clustering is for unsupervised learning rather than prediction. $\endgroup$ Commented Jan 22, 2023 at 23:11
0
$\begingroup$

You need to frame your task first. Do you want to predict how much a customer would spend based on his location, referral channel, and some other variable you might have, or do you want to predict your sales for a given region in a given timeframe? That is, step one of your ML project is determining your target variable.

Once you define your problem, build a data set. I assume that would be somewhat easy for you as you can export a CSV from Shopify so you'd have some training data. Then, start simple with the modelling phase. If you are a beginner in ML, use "simple" algorithms like linear regression, decision trees, logistic regression, Naive Bayes, KNN (be aware that not all would be applicable to your problem - take your time to study each one carefully). You'll probably have some categorical variables (region, channel), so some pre-processing steps will need to be done. I'd recommend you to go through the documentation of sklearn, it is beginner friendly but very powerful and valuable. There are a ton of examples for how to use the library.

In context of the answer from @etet above, I also think that you'd get more value from an in-depth exploratory analysis. Start off with that, then move on to ML.

$\endgroup$
0
$\begingroup$

So let me first point out the problem with using a numerical encoding for Province Code, there would be no logical structure to assigning numbers to provinces and as such, k-means considering continuous data points would try to make sense of that encoded value which would not result in any meaningful information. Thus, direct features about the province like the area and the geographical co-ordinates of the province would prove better if you wanted to use it as a feature for something like k-means. My other point would be to instead properly define the problem statement and exactly what can you derive from the data that you have, you do not need a model to analyze the spending grouped on Province Code as other answers have suggested.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.