0
$\begingroup$

I have some unlabeled data with 15 attributes and 30161 instances. I took 70% data for clustering and cluster those data into 2 cluster. I also added one column after clustering named 'cluster' and the column '<=50k' was label column. Now I need to plot those data except label column, How can I plot it ? Here's the sample of my code and data.

Data enter image description here

cols_x=train.columns[0:14] cols_y = train.columns[14] X = train[cols_x] y = train[cols_y]

from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.30,random_state=10)

kmeans = KMeans(n_clusters=2) train["cluster"] = kmeans.fit_predict(train[X_train.columns[0:14]]) train.head(10)

enter image description here

$\endgroup$
3
  • $\begingroup$ What exactly you want to plot, it depends on that also.. $\endgroup$
    – Aditya
    Feb 28, 2018 at 14:09
  • $\begingroup$ As I clustered those data into 2 cluster. So, I need to visualized those 2 clustered data with amount that how many data exist in cluster 1 and cluster 2. $\endgroup$
    – IS2057
    Mar 1, 2018 at 6:36
  • $\begingroup$ You can do that using countplot on the target variable? $\endgroup$
    – Aditya
    Mar 1, 2018 at 6:38

2 Answers 2

1
$\begingroup$

KMeans on such data is meaningless if used carelessly. It looks as if your result is based on whether the ID is larger than 200000 or not.

Rather than copy and pasting example code from the internet now also to visualize, I think you should spend more time thinking about what you are actually computing. Because solving the wrong problem doesn't help.

$\endgroup$
2
  • $\begingroup$ Though I am new learner in python and clustering but I didn't just copy and pasting code from internet. And here ID is not larger than 200000, may be your mentioned column is fnlwgt and this data was for adults data, which I didn't mentioned it here. I think I have clear idea about what I need to do but I faced problem about plotting. $\endgroup$
    – IS2057
    Jan 29, 2018 at 15:36
  • $\begingroup$ The column labeled 77516 determines your result. All other columns do not matter, except maybe 2174 when it isn't 0. Sorry, but it clearly looks as if you have not understood what function you optimize. $\endgroup$ Jan 29, 2018 at 15:43
0
$\begingroup$

maybe the first step could be to try to figure out how you could distinguish visually your two grouped elements (using colors maybe ?)

Hopefully you'll find some help here : https://stats.stackexchange.com/questions/31083/how-to-produce-a-pretty-plot-of-the-results-of-k-means-cluster-analysis

good luck !

$\endgroup$

Your Answer

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

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