# Visualization problem of 15 attributes which is clustered into 2 cluster [duplicate]

This question already has an answer here:

I am new in python and clustering problem. I need some help for visualization of clustered data.

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: cols_x=train.columns[0:14] cols_y = train.columns 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) ## marked as duplicate by jbowman, kjetil b halvorsen, mdewey, Peter Flom♦Jan 25 '18 at 14:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

## 1 Answer

This post: How to produce a pretty plot of the results of k-means cluster analysis? goes over some suggestions on how to visualize clustering results. Although the post and examples are given in R, you can find equivalent packages in python. Some of the main suggestions with the python equivalent packages:

• Performing PCA to reduce the number of dimensions you are dealing with and taking the first 2 or 3 principal components for visualization. Note that if you do go with this method, taking the first 2 or 3 will only be useful if the majority of the variance is accounted for by your first 2 or 3 principal components (see explained_variance_ on the sklearn PCA page)

• Performing a Silhouette analysis. This analysis gives you an idea of the separation between your samples in each cluster and could be used to figure out how "good" your clusters are (i.e. are the samples within the cluster far apart, close together, close to the decision boundary). This analysis can be performed after PCA or without, but the resulting visualization are pair-plots (i.e. 2D plots looking at pairs of your features). Looking at pair plots for 15 attributes (105 plots) is a little cumbersome, so I would suggest first performing PCA to see if you can reduce the number of dimensions you are working with. Here an sklearn example of a Silhouette analysis