#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sat Mar 20 09:50:53 2021 @author: doug """ import matplotlib.pyplot as plt from sklearn.cluster import KMeans import scipy.io mat_contents = scipy.io.loadmat('HWMar26data.mat') A = mat_contents['A'] # We don't need the other matrices yet. kmeans = KMeans(n_clusters=3, random_state=0) idx = kmeans.fit_predict(A) kmeans.cluster_centers_.shape idx1 = [i for (i, val) in enumerate(idx) if val == 0] idx2 = [i for (i, val) in enumerate(idx) if val == 1] idx3 = [i for (i, val) in enumerate(idx) if val == 2] plt.scatter(A[idx1,0],A[idx1,1],marker='^') plt.scatter(A[idx2,0],A[idx2,1],marker='o') plt.scatter(A[idx3,0],A[idx3,1],marker='*')