-
Notifications
You must be signed in to change notification settings - Fork 0
/
solar_energy_forecasting.R
48 lines (33 loc) · 1.33 KB
/
solar_energy_forecasting.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
install.packages('gbm')
install.packages('Metrics')
install.packages('caret')
library(gbm)
library(Metrics)
library(caret)
library(ggplot2)
theme_set(theme_bw())
data <- read.csv('Project_2_dataset.csv')
data = transform.data.frame(data)
n = floor(nrow(data)/2) #number of training data
x_train<-data[1:n,8:10]
y_train<-data[2:(n+1),4]
x_test<-data[(n+1):(nrow(data)-1),8:10]
y_test = data[(n+2):nrow(data), 4]
model <- gbm.fit(x_train,y_train,distribution = 'gaussian',n.trees = 100000,
interaction.depth = 1,n.minobsinnode = 10,shrinkage = 0.0001,bag.fraction = 0.2,verbose = TRUE)#train gbm model
summary(model)
best.iter <- gbm.perf(model,method="OOB",plot.it = TRUE, oobag.curve = TRUE) #calculate optimal parameters
y_predictions <- predict(model,x_test,best.iter)
rmse(actual = y_test, predicted = y_predictions)
postResample(pred = y_predictions, obs = y_test)
#Last dat point in the set with unkown y label
x_unknown_y = data[nrow(data),8:10]
predict_unkown_label = predict(model,x_unknown_y,best.iter)
predict_unkown_label
y_predictions[y_predictions<0]=0
residuals = y_test - y_predictions
hist(residuals)
data$SPI = data$GHI/data$Clearsky.GHI
data$SPI[is.na(data$SPI)] = 0
head(data$SPI)
data$GHI[1:nrow(data)-1] + data$SP[1:nrow(data)-1]*(diff(data$Clearsky.GHI))