-
Notifications
You must be signed in to change notification settings - Fork 3
/
pls_regression.r
37 lines (33 loc) · 886 Bytes
/
pls_regression.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
library(readr)
library(tidyverse)
library(dplyr)
library(caret)
library(pls)
data <- read_csv("data/concrete.csv")
data_noid <- data %>% select(-c("id"))
concrete_plr <- plsr(
slump + flow + compressive_strength ~ .,
data = data_noid,
validation = "LOO",
center = T,
scale = T
)
cv = RMSEP(concrete_plr)
dims <- which.min(cv$val[estimate = "adjCV", , ]) - 1
concrete_plr <- plsr(
slump + flow + compressive_strength ~ .,
data = data_noid,
center = T,
scale = T,
ncomp = dims,
)
coefficients = coef(concrete_plr)
sum.coef = sum(sapply(coefficients, abs))
coefficients = coefficients * 100 / sum.coef
coefficients = sort(coefficients[, 1 , 1])
par(mfcol=c(2, 3))
barplot(tail(coefficients, 4))
barplot(head(coefficients, 3))
scoreplot(concrete_plr, labels = "names")
loadingplot(concrete_plr, labels = "names")
corrplot(concrete_plr, labels = "names")