forked from MariekeDirk/ML_project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild_6h_dataset.R
More file actions
96 lines (44 loc) · 2.22 KB
/
Build_6h_dataset.R
File metadata and controls
96 lines (44 loc) · 2.22 KB
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
#############################################################################################################
# This is the script in which the 6h dataset for the 2nd round of model runs is built
#############################################################################################################
# Empty environment
rm(list=ls())
# Read in the environmental dataset
load("/usr/people/kleingel/Projects/MLProject/Env_Data.Rda")
# Build the training set -------------------------------------------------
# Read in the 6h GMS dataset and remove al data which is not labeled as 'valid'
load("/usr/people/kleingel/Projects/MLProject/GMS_6h.Rda")
GMS_6h <- GMS_6h[GMS_6h$QUALITY == "valid", ]
# Drop the quality column in the 6h GMS dataset
GMS_6h <- GMS_6h[ ,-7]
# Merge 6h GMS data and environmental dataset
Data_6h <-merge(GMS_6h,Env_Data_4,by.x=c("LOCATION","SENSOR"),by.y=c("MISD","SENSOR"))
# Split into input (predictors) and output (target variable)
# Output
Target_Train <- Data_6h$TEMP
# Input
# Drop LOCATION/SENSOR/TIMESTAMP en TEMP
Data_6h <- Data_6h[ ,-(1:3)]
Data_6h <- Data_6h[ ,-3]
Predictors_Train <- Data_6h
# Build the test set -----------------------------------------------------
# Read in the 1.5h GMS dataset and remove al data which is not labeled as 'valid'
load("/usr/people/kleingel/Projects/MLProject/GMS_1.5h.Rda")
GMS_1.5h <- GMS_1.5h[GMS_1.5h$QUALITY == "valid"]
GMS_1.5h <- GMS_1.5h[ ,-7]
Data_1.5h <-merge(GMS_1.5h,Env_Data_4,by.x=c("LOCATION","SENSOR"),by.y=c("MISD","SENSOR"))
# Split into input (predictors) and output (target variable)
# Output
Target_Test <- Data_1.5h$TEMP
# Input
# Drop LOCATION/SENSOR/TIMESTAMP en TEMP
Data_1.5h <- Data_1.5h[ ,-(1:3)]
Data_1.5h <- Data_1.5h[ ,-3]
Predictors_Test <- Data_1.5h
# Some analysis -----------------------------------------------------------
NearZero_Train <- nearZeroVar(Predictors_Train, names = TRUE, saveMetrics = TRUE)
# Preprocessing (Centering, Scaling, Box-Cox, PCA) ------------------------
library(caret)
xTrans <- preProcess(Predictors_Train[, 1:6], method = c("expoTrans","center","scale"),
na.remove = TRUE)
Predictors_Train[, 1:6] <- predict(xTrans, Predictors_Train[ ,1:6])