Clustering in Python

Viewed 94

I have a dataset with thousands of rows. Each row is a person, that I need to insert into 4 clusters. I know that have many possibles to do that and to find the best clusters, but in this case, I know the characteristics of each cluster. Generally, with ML, the clusters are find with IA.

For example, imagine that I have 4 columns to look: money_spending, salary, segment, days_to_buy. Also, I have:

Cluster 1 -> money_spending: 350-700
salary: 700-1000
segment: farmacy
days_to_buy: 12

Cluster 2 -> money_spending: 500-950
salary: 1000-1300
segment: construction material
days_to_buy: 18

Cluster 3 -> money_spending: 900-1400
salary: 1200-2000
segment: supermarket
days_to_buy: 20

Cluster 4 -> money_spending: 250-600
salary: 550-1000
segment: farmacy
days_to_buy: 30

What's the best way to apply this to my dataset? I would use k-nearest, but I don't know how to use my cluster information.

Can someone help me?

Plus: If I have more columns or more clusters the solution keeps works?

Edit: My original dataset only have the columns. The clusters are knowing, but are not in dataset. The job is exactly apply this cluster information to dataset. I don't have any idea how to do that.

1 Answers

You can try the following approach:

  1. Run K means and find the best number of k using the Elbow method or Silhouette graph.

  2. Use the cluster labels as a class. e.g. if 4 is the optimal number of the cluster then class=0,1,2,3 ( which will be the cluster labels)

  3. Merge the class with the original dataset and treat it as a supervised learning problem

  4. Try running any classification model after the train test split.

  5. See the classification report to check model performance.

PS

  • Try using data with normalization too as many clustering algorithms are sensitive to outliers.

  • Please see if the class is somewhat equally distributed like 1000,800,1150,890 and not 1500,80,150,..etc as it will create data imbalance for the classifiers.

Related