Reference no: EM132284368
Assignment - PCA and Clustering
1. Principal component analysis
sklearn comes with several data sets. Load data set called digits by running following code from sklearn.datasets import load_digits DigitData =load_digits()
digits is a dataset of handwritten digits in matrix form of 8x8 pixels that means the dimension of data is 64. Our goal is to reduce this dimension to some lower dimension by using principal component analysis.
Run the PCA on the data. Get the first two components and plot it with their corresponding labels.
To run PCA, use PCA from sklearn.decomposition.
Note: you can use pyplot from matplotlib for plotting.
What do you observe? What is the percentage of variance captured by these two components? Is it sufficient or we should find more components?
2. K-mean Clustering
use the same digit data set as above from sklearn.datasets
It is a good idea to scale this data before performing clustering. To do that use scale from sklearn.preprocessing
Show the images with their labels using matplotlib.
Divide the data into training set and test set with testset = 20% of total data.
To divide the data into training and test set, use train_test_split from sklearn.cross validation
Perform clustering assuming there are 10 clusters.
To perform clustering, use cluster from sklearn.
U se KMeans function of cluster (cluster.KMeans).
Assign numbering or labels to your clusters (remember your labeling has nothing to do with actual labels, we pretend that we do not know the actual labels)
Test your cluster on the test data set. What do you observe? Print a confusion matrix of your test.
To divide the data into training and test set, use train_test_split from sklearn.cross validation
Perform clustering assuming there are 10 clusters.
To perform clustering, use cluster from sklearn.
Use KMeans function of cluster (cluster.KMeans).
Assign numbering or labels to your clusters (remember your labeling has nothing to do with actual labels, we pretend that we do not know the actual labels)
Test your cluster on the test data set. What do you observe? Print a confusion matrix of your test.
What to submit? A single jupyter notebook file with code and results.