-
Notifications
You must be signed in to change notification settings - Fork 1
/
CODE_asteroids_dataset_split.R
49 lines (40 loc) · 2.05 KB
/
CODE_asteroids_dataset_split.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
setwd("~/Github/AsteroidsClassification")
#load dataset RObject as asteroids_data
load("DATA_asteroids_dataset.RData")
split.data = function(data, p = 0.7, s = 1){
set.seed(s)
index = sample(1:dim(data)[1])
train = data[index[1:floor(dim(data)[1] * p)], ]
test = data[index[((ceiling(dim(data)[1] * p)) + 1):dim(data)[1]], ]
return(list(train=train, test=test))
}
split_perc <- 0.7
asteroids_split <- split.data(asteroids_data, p = split_perc)
img_name_plot <- paste("IMG_asteroids_dataset_splited_hazardous_", as.character(split_perc), ".png", sep = "")
png(img_name_plot)
par(mfrow=c(1,2))
pie(table(asteroids_split$train$Hazardous),
labels = paste(round(prop.table(table(asteroids_split$train$Hazardous))*100), "% (",table(asteroids_split$train$Hazardous),")" , sep = ""),
col = heat.colors(5), main = "Train set - Hazardous class"
)
pie(table(asteroids_split$test$Hazardous),
labels = paste(round(prop.table(table(asteroids_split$test$Hazardous))*100), "% (",table(asteroids_split$test$Hazardous),")" , sep = ""),
col = heat.colors(5), main = "Test set - Hazardous class"
)
dev.off()
img_name_plot <- paste("IMG_asteroids_dataset_splited_classification_", as.character(split_perc), ".png", sep = "")
png(img_name_plot)
par(mfrow=c(1,2))
pie(table(asteroids_split$train$Classification),
labels = paste(round(prop.table(table(asteroids_split$train$Classification))*100), "% (",table(asteroids_split$train$Classification),")" , sep = ""),
col = heat.colors(5), main = "Train set - Classification of asteroids "
)
pie(table(asteroids_split$test$Classification),
labels = paste(round(prop.table(table(asteroids_split$test$Classification))*100), "% (",table(asteroids_split$test$Classification),")" , sep = ""),
col = heat.colors(5), main = "Test set - Classification of asteroids"
)
dev.off()
name_file <- paste("DATA_asteroids_dataset_split_", as.character(split_perc), ".RData", sep = "")
rm(asteroids_data,split.data,split_perc,img_name_plot)
save(asteroids_split, file=name_file)
rm(asteroids_split,name_file)