PCA/LDA Lab CSCE 587 Fall 2018.

Slides:



Advertisements
Similar presentations
Face Recognition Sumitha Balasuriya.
Advertisements

Exercise 1 In the ISwR data set alkfos, do a PCA of the placebo and Tamoxifen groups separately, then together. Plot the first two principal components.
1 CPC group SeminarThursday, June 1, 2006 Classification techniques for Hand-Written Digit Recognition Venkat Raghavan N. S., Saneej B. C., and Karteek.
Face Recognition and Biometric Systems
Chapter 17 Overview of Multivariate Analysis Methods
A Comprehensive Study on Third Order Statistical Features for Image Splicing Detection Xudong Zhao, Shilin Wang, Shenghong Li and Jianhua Li Shanghai Jiao.
Lecture 7: Principal component analysis (PCA)
1 Multivariate Statistics ESM 206, 5/17/05. 2 WHAT IS MULTIVARIATE STATISTICS? A collection of techniques to help us understand patterns in and make predictions.
ETHEM ALPAYDIN © The MIT Press, Lecture Slides for.
LISA Short Course Series Multivariate Analysis in R Liang (Sally) Shan March 3, 2015 LISA: Multivariate Analysis in RMar. 3, 2015.
Principal Component Analysis
Factor Analysis Research Methods and Statistics. Learning Outcomes At the end of this lecture and with additional reading you will be able to Describe.
Dimensional reduction, PCA
09/05/2005 סמינריון במתמטיקה ביולוגית Dimension Reduction - PCA Principle Component Analysis.
1 Data Analysis  Data Matrix Variables ObjectsX1X1 X2X2 X3X3 …XPXP n.
Chapter 5 Part II 5.3 Spread of Data 5.4 Fisher Discriminant.
INTRODUCTION TO Machine Learning ETHEM ALPAYDIN © The MIT Press, Lecture Slides for.
PCA & LDA for Face Recognition
Chapter 2 Dimensionality Reduction. Linear Methods
Principal Components Analysis BMTRY 726 3/27/14. Uses Goal: Explain the variability of a set of variables using a “small” set of linear combinations of.
Feature extraction 1.Introduction 2.T-test 3.Signal Noise Ratio (SNR) 4.Linear Correlation Coefficient (LCC) 5.Principle component analysis (PCA) 6.Linear.
BACKGROUND LEARNING AND LETTER DETECTION USING TEXTURE WITH PRINCIPAL COMPONENT ANALYSIS (PCA) CIS 601 PROJECT SUMIT BASU FALL 2004.
Principal Component Analysis Bamshad Mobasher DePaul University Bamshad Mobasher DePaul University.
Principal Component Analysis Machine Learning. Last Time Expectation Maximization in Graphical Models – Baum Welch.
Principal Components Analysis. Principal Components Analysis (PCA) A multivariate technique with the central aim of reducing the dimensionality of a multivariate.
EE4-62 MLCV Lecture Face Recognition – Subspace/Manifold Learning Tae-Kyun Kim 1 EE4-62 MLCV.
Visualizing and Exploring Data 1. Outline 1.Introduction 2.Summarizing Data: Some Simple Examples 3.Tools for Displaying Single Variable 4.Tools for Displaying.
Speech Lab, ECE, State University of New York at Binghamton  Classification accuracies of neural network (left) and MXL (right) classifiers with various.
Dimensionality reduction
MACHINE LEARNING 7. Dimensionality Reduction. Dimensionality of input Based on E Alpaydın 2004 Introduction to Machine Learning © The MIT Press (V1.1)
Principal Component Analysis (PCA).
Linear Classifiers Dept. Computer Science & Engineering, Shanghai Jiao Tong University.
LDA (Linear Discriminant Analysis) ShaLi. Limitation of PCA The direction of maximum variance is not always good for classification.
1 Statistics & R, TiP, 2011/12 Multivariate Methods  Multivariate data  Data display  Principal component analysis Unsupervised learning technique 
Chapter 15: Classification of Time- Embedded EEG Using Short-Time Principal Component Analysis by Nguyen Duc Thang 5/2009.
CSSE463: Image Recognition Day 25 This week This week Today: Applications of PCA Today: Applications of PCA Sunday night: project plans and prelim work.
Principal Components Analysis ( PCA)
Multivariate statistical methods. Multivariate methods multivariate dataset – group of n objects, m variables (as a rule n>m, if possible). confirmation.
Descriptive Statistics using R. Summary Commands An essential starting point with any set of data is to get an overview of what you are dealing with You.
Machine Learning Supervised Learning Classification and Regression K-Nearest Neighbor Classification Fisher’s Criteria & Linear Discriminant Analysis Perceptron:
Principal Component Analysis (PCA)
Unsupervised Learning
CSSE463: Image Recognition Day 27
PCA/LDA Lab CSCE 587 Spring 2017.
CSSE463: Image Recognition Day 26
Dimensionality Reduction
Background on Classification
Exploring Microarray data
LECTURE 10: DISCRIMINANT ANALYSIS
9.3 Filtered delay embeddings
Gene Set Enrichment Analysis
Principal Component Analysis
Machine Learning Dimensionality Reduction
Principal Component Analysis
Principal Component Analysis (PCA)
Principal Component Analysis and Linear Discriminant Analysis
Principal Component Analysis (PCA)
Introduction PCA (Principal Component Analysis) Characteristics:
Dimensionality Reduction
CSSE463: Image Recognition Day 25
Feature space tansformation methods
Generally Discriminant Analysis
CS4670: Intro to Computer Vision
LECTURE 09: DISCRIMINANT ANALYSIS
CSSE463: Image Recognition Day 25
Feature Selection Methods
Principal Component Analysis
INTRODUCTION TO Machine Learning
Fig. 4 Visualization of the 20 occipital lobe models, trained to predict EmoNet categories from brain responses to emotional images. Visualization of the.
Unsupervised Learning
Presentation transcript:

PCA/LDA Lab CSCE 587 Fall 2018

PCA/LDA Lab # PCA & LDA Lab # We will need the following packages: # stats # ggplot2 # ggfortify # lfda # stats is already installed and loaded # The others should already be installed and only need to loaded.

PCA ############################################################ # example iris data # PCA # extract the independent variables iris_data <- iris[,-5] # generate the PCs iris_pca <- prcomp(iris_data, center = TRUE, scale. = TRUE) # Display the PCA object print(iris_pca)

PCA # convert from SD to var # get percent var #plot percent var tot_var <- sum(sapply(iris_pca$sdev,function(x) x*x)) # get percent var pct_var <- sapply(iris_pca$sdev,function(x) x*x/tot_var) #plot percent var plot(pct_var, type="l")

PCA # first two PCs account for most of the variance sum(pct_var[1:2]) # plot the first two principal components # you can use autoplot to plot the first two PCs # use the work-around plot command autoplot(prcomp(iris_data, center = TRUE, scale. = TRUE)) # ugly version of plot plot(prcomp(iris_data, center = TRUE, scale. = TRUE)$x[,1:2])

PCA # plot the first two principal components and color by species # pretty autoplot autoplot(prcomp(iris_data, center = TRUE, scale. = TRUE), data = iris, colour = 'Species') # ugly standard R plot(prcomp(iris_data , center = TRUE, scale. = TRUE)$x[,1:2], col=iris[,5]) # plot the first two principal using autoplot from ggfortify # components, color by species, and label by observation index autoplot(prcomp(iris_data , center = TRUE, scale. = TRUE), data = iris, colour = 'Species', label = TRUE, label.size = 3)

ggfortify plots for our PCA example # plot the first two PCs and draw # the eigenvectors and label the loadings autoplot(prcomp(iris_data , center = TRUE, scale. = TRUE), data = iris, colour = 'Species', loadings = TRUE, loadings.colour = 'blue',loadings.label = TRUE, loadings.label.size = 3)

LDA using the lfda package ########################################################## # # Create the LDA model. The first argument is the set of 4 # independent variables. # The second argument is the dependent variable. # The third argument is the dimensionality of the reduced space # The fourth argument is the type of metric in the embedding space # iris_LDA <- lfda(iris_data, iris[, 5], r = 2, metric="plain")

LDA using the lfda package # plot the model autoplot(iris_LDA, data = iris, frame = TRUE, frame.colour = 'Species') # # plot the model and color the data by class autoplot(iris_LDA, data = iris, colour="Species", frame = TRUE, frame.colour = 'Species')

LDA from MASS package # Create a data frame for the iris dataset Iris <- data.frame(rbind(iris3[,,1], iris3[,,2], iris3[,,3]),Sp = rep(c("s","c","v"), rep(50,3))) # Decide which observations a comprise the training set set.seed(587) train <- sample(1:150, 75) # Display the class membership of the training data set table(Iris$Sp[train])

LDA from MASS package # create the LDA model # Formula: SP ~., i.e. Sp is the classification and the other columns # are the independant data # Iris is the data set # prior = c(1,1,1)/3 even priors # subset: which observations are used to train with z <- lda(Sp ~ ., Iris, prior = c(1,1,1)/3, subset = train)

LDA from MASS package # Project from 4 iris dimensions onto the dimension of the first eigenvector # Note: this maps all 150 flowers iris_x <- (z$scaling[,1]) %*% t(iris[,-5]) # Project from 4 iris dimensions onto the dimension of the second eigenvector iris_y <- (z$scaling[,2]) %*% t(iris[,-5])

LDA from MASS package # plot 150 iris data points plot(iris_y~iris_x) # plot 150 iris data points & color by species plot(iris_y~iris_x, col=iris[,5])

test <- c(1:150)[-train] table(Original=Iris[test,]$Sp, predict(z,Iris[test,])$class) # Create indices for a test set (use the observations NOT in the training set) test <- c(1:150)[-train] # classify the test set and display as a confusion matrix table(Original=Iris[test,]$Sp, predict(z, Iris[test,])$class)

More difficult PCA example ############################################################## # PCA example using icu data from earlier in the semester tmp <- icu[,-c(1, 2)] pca_tmp <- prcomp(tmp, center = TRUE, scale. = TRUE) print(pca_tmp) plot(pca_tmp, type="l") tot_var <- sum(sapply(pca_tmp$sdev,function(x) x*x))

More difficult PCA example pct_var <- sapply(pca_tmp$sdev,function(x) x*x/tot_var) plot(pct_var, type="l") sum(pct_var[1:10]) # autoplot autoplot(prcomp(tmp, center = TRUE, scale. = TRUE)) #regular plot plot(prcomp(tmp , center = TRUE, scale. = TRUE)$x[,1:2]) autoplot(prcomp(tmp , center = TRUE, scale. = TRUE ), data = icu, colour = 'STA') # regular plot plot(prcomp(tmp , center = TRUE, scale. = TRUE)$x[,1:2], col=icu[,2]+1)

More difficult LDA example # Find linear discriminants icu_LDA <- lfda(icu[,-c(1:2)], icu[, 2], r = 2, metric="plain") # Plot classification autoplot(icu_LDA, data=icu, colour="STA", frame=TRUE, frame.colour='STA')