Created
July 22, 2015 22:11
-
-
Save pprzetacznik/5532d759b274c24a4917 to your computer and use it in GitHub Desktop.
Maraton danych - eRka Kraków
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
data <- read.csv("gau12jbs Master 100715.csv", header=TRUE) | |
names <- select(data, starts_with("RV"), starts_with("RC"), starts_with("SW"), starts_with("SN"), starts_with("WC"), starts_with("AP"), starts_with("PH"), starts_with("SD"), starts_with("SY"), starts_with("RH"), starts_with("FS") ) %>% | |
na.omit %>% | |
row.names | |
train_names <- sample(names, length(names) * 7/10, replace = FALSE) | |
test_names <- setdiff(names, train_names) | |
train_set <- filter(data, row.names(data) %in% train_names) %>% | |
select(starts_with("RV"), starts_with("RC"), starts_with("SW"), starts_with("SN"), starts_with("WC"), starts_with("AP"), starts_with("PH"), starts_with("SD"), starts_with("SY"), starts_with("RH"), starts_with("FS") ) %>% | |
na.omit | |
test_set <- filter(data, row.names(data) %in% test_names) %>% | |
select(starts_with("RV"), starts_with("RC"), starts_with("SW"), starts_with("SN"), starts_with("WC"), starts_with("AP"), starts_with("PH"), starts_with("SD"), starts_with("SY"), starts_with("RH"), starts_with("FS") ) %>% | |
na.omit | |
train_set <- train_set[!sapply(train_set, is.logical)] | |
train_set <- cbind(filter(data, row.names(data) %in% train_names) %>% select(Language), train_set[!sapply(train_set, is.factor)]) | |
test_set <- test_set[!sapply(test_set, is.logical)] | |
test_set <- cbind(filter(data, row.names(data) %in% test_names) %>% select(Language), test_set[!sapply(test_set, is.factor)]) | |
summary(pc.cr <- princomp(train_set[,2:1040])) | |
loadings(pc.cr) | |
library(lattice) | |
pc.cr$scores | |
pca.plot <- xyplot(pc.cr$scores[,1] ~ pc.cr$scores[,2]) | |
pca.plot$xlab <- "First Component" | |
pca.plot$ylab <- "Second Component" | |
pca.plot | |
biplot(pc.cr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment