-
Notifications
You must be signed in to change notification settings - Fork 1
/
CODE_asteroids_analysis_PCA.R
79 lines (62 loc) · 2.37 KB
/
CODE_asteroids_analysis_PCA.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
setwd("~/Github/AsteroidsClassification")
library("FactoMineR")
library("factoextra")
library("gridExtra")
#load dataset RObject as asteroids_data
load("DATA_asteroids_dataset.RData")
#PCA feature extration
col_active = c("Orbit.Axis..AU.", "Orbit.Eccentricity", "Orbit.Inclination..deg.", "Perihelion.Argument..deg.", "Node.Longitude..deg.", "Mean.Anomoly..deg.", "Perihelion.Distance..AU.", "Aphelion.Distance..AU.", "Orbital.Period..yr.", "Minimum.Orbit.Intersection.Distance..AU.", "Asteroid.Magnitude")
asteroids_data.active <- asteroids_data[,col_active]
asteroids_pca = PCA(asteroids_data.active, graph = TRUE)
asteroids_pca.eig_val <- get_eigenvalue(asteroids_pca)
img_name_plot <- paste("IMG_asteroids_pca_", "Component_eig_values" ,".png", sep = "")
png(img_name_plot)
p<-tableGrob(asteroids_pca.eig_val)
grid.arrange(p)
dev.off()
img_name_plot <- paste("IMG_asteroids_pca_", "Component_explaind_variances" ,".png", sep = "")
png(img_name_plot)
fviz_eig(asteroids_pca, addlabels = TRUE)
dev.off()
#old variable comparison
var <- get_pca_var(asteroids_pca)
img_name_plot <- paste("IMG_asteroids_pca_", "covariables_in_pcaSpace" ,".png", sep = "")
png(img_name_plot)
fviz_pca_var(asteroids_pca, col.var = "blue")
dev.off()
var$coord
var$cos2
var$contrib
#individual analysis
ind <- get_pca_ind(asteroids_pca)
fviz_pca_ind(asteroids_pca)
img_name_plot <- paste("IMG_asteroids_pca_", "individual_class_cos2" ,".png", sep = "")
png(img_name_plot)
fviz_pca_ind(asteroids_pca, col.ind = "cos2",
gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
repel = FALSE # Avoid text overlapping (slow if many points)
)
dev.off()
img_name_plot <- paste("IMG_asteroids_pca_", "individual_class_hazardous" ,".png", sep = "")
png(img_name_plot)
fviz_pca_biplot(asteroids_pca,
geom.ind = "point",
col.ind = asteroids_data$Hazardous,
palette = c("#00AFBB", "#E7B800", "#FC4E07"),
addEllipses = TRUE,
legend.title = "Groups"
)
dev.off()
img_name_plot <- paste("IMG_asteroids_pca_", "individual_class_classification" ,".png", sep = "")
png(img_name_plot)
fviz_pca_biplot(asteroids_pca,
geom.ind = "point",
col.ind = asteroids_data$Classification,
palette = c("#00AFBB", "#E7B800", "#FC4E07"),
addEllipses = TRUE,
legend.title = "Groups"
)
dev.off()
var$coord
var$cos2
var$contrib