• Home
  • Data science
  • Workshops
  • Java Lectures
  • Blog
  • Fun-Videos
  • Contact
Have any question?
computeadmin [at the rate of] computing4all.com
RegisterLogin
Computing for All
  • Home
  • Data science
  • Workshops
  • Java Lectures
  • Blog
  • Fun-Videos
  • Contact

Workshops

  • Home
  • Blog
  • Workshops
  • Data Science Workshop 2 (Part 5): Data and Cluster Visualization (Continued)

Data Science Workshop 2 (Part 5): Data and Cluster Visualization (Continued)

  • Posted by M. Shahriar Hossain
  • Categories Workshops
  • Date June 25, 2021
  • Comments 0 comment
Workshop 2, Part 5: Cluster visualization

As I was saying in the previous part, we will not get an interactive graphical interface if we use Google colab. That is why I am using regular Python on my computer.

When I use Python, my program needs to display the figure on a canvas. Unlike directly trying to display fig on the notebook like what we do on Google colab, we will use a method to display the plot on a graphical interface. The entire data and cluster visualization technique is demonstrated in the following YouTube video.

 

The Python code that I wrote in the video is as follows:

import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
import numpy as np
import matplotlib.cm as cm

data = np.array( 
   [[20, 25, 18],
   [3, 2, 3],
   [6, 4, 5],
   [24, 21, 19],
   [22, 24, 21],
   [18, 20, 21],
   [4, 2, 3],
   [1, 5, 2],
   [19, 20, 19],
   [23, 19, 22]]
)

km = KMeans(n_clusters=2).fit(data)
print(km.labels_)

fig=plt.figure()

ax = fig.add_subplot(111, projection='3d')

ax.scatter(data[:,0], data[:, 1], data[:, 2],
           c=km.labels_, cmap=cm.rainbow)

ax.set_xlabel("Feature 1", fontsize=16)
ax.set_ylabel("Feature 2", fontsize=16)
ax.set_zlabel("Feature 3", fontsize=16)

plt.show()

Please write the code in a file with .py extension and run it from the command prompt to view the interactive display. The video explains how to run the program.

 

  • Share:
author avatar
M. Shahriar Hossain

I am an Associate Professor in the Department of Computer Science at the University of Texas at El Paso (UTEP). My specialization is Data Science (Data Mining and Machine Learning.)

Previous post

Data Science Workshop 2 (Part 4): Data and Cluster Visualization
June 25, 2021

Next post

Data Science Workshop 3 (Part 1): Exploratory Data Analysis using Pandas in Python Programming
June 30, 2021

Leave A Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Categories

  • Blog
  • Computing
  • Data Science
  • Education
  • Java
  • Programming
  • Workshops

Computing For All by Computing4All.

Login with your site account

Lost your password?

Not a member yet? Register now

Register a new account

Are you a member? Login now