Getting started

library(learningmachine)
library(caret)
library(mlbench)
library(palmerpenguins)
X <- as.matrix(mtcars[,-1])
y <- mtcars$mpg
set.seed(123)
(index_train <- base::sample.int(n = nrow(X),
                                 size = floor(0.8*nrow(X)),
                                 replace = FALSE))
##  [1] 31 15 19 14  3 10 18 22 11  5 20 29 23 30  9 28  8 27  7 32 26 17  4  1 24
X_train <- X[index_train, ]
y_train <- y[index_train]
X_test <- X[-index_train, ]
y_test <- y[-index_train]
dim(X_train)
## [1] 25 10
dim(X_test)
## [1]  7 10

0 - lm regression

obj <- learningmachine::Regressor$new(method = "lm", pi_method = "splitconformal")
obj$get_type()
## [1] "regression"
obj$get_name()
## [1] "Regressor"
obj$get_method()
## [1] "lm"
t0 <- proc.time()[3]
obj$fit(X_train, y_train)
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.002 s
print(sqrt(mean((obj$predict(X_test)$preds - y_test)^2)))
## [1] 3.548852
(res <- obj$predict(X = X_test))
## $preds
##       Mazda RX4 Wag             Valiant          Merc 450SE          Merc 450SL 
##            21.67584            19.80291            14.75149            15.70693 
## Lincoln Continental       Toyota Corona    Pontiac Firebird 
##            12.03666            28.20630            13.55241 
## 
## $lower
##       Mazda RX4 Wag             Valiant          Merc 450SE          Merc 450SL 
##           10.675844            8.802908            3.751488            4.706932 
## Lincoln Continental       Toyota Corona    Pontiac Firebird 
##            1.036659           17.206298            2.552412 
## 
## $upper
##       Mazda RX4 Wag             Valiant          Merc 450SE          Merc 450SL 
##            32.67584            30.80291            25.75149            26.70693 
## Lincoln Continental       Toyota Corona    Pontiac Firebird 
##            23.03666            39.20630            24.55241
plot(c(y_train, res$preds), type='l',
     main="",
     ylab="",
     ylim = c(min(c(res$upper, res$lower, y)),
              max(c(res$upper, res$lower, y))))
lines(c(y_train, res$upper), col="gray60")
lines(c(y_train, res$lower), col="gray60")
lines(c(y_train, res$preds), col = "red")
lines(c(y_train, y_test), col = "blue")

mean((y_test >= as.numeric(res$lower)) * (y_test <= as.numeric(res$upper)))
## [1] 1
t0 <- proc.time()[3]
obj$fit(X_train, y_train, 
        pi_method = "jackknifeplus")
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.041 s
obj$set_level(95L)

res <- obj$predict(X = X_test)

plot(c(y_train, res$preds), type='l',
     main="",
     ylab="",
     ylim = c(min(c(res$upper, res$lower, y)),
              max(c(res$upper, res$lower, y))))
lines(c(y_train, res$upper), col="gray60")
lines(c(y_train, res$lower), col="gray60")
lines(c(y_train, res$preds), col = "red")
lines(c(y_train, y_test), col = "blue")

mean((y_test >= as.numeric(res$lower)) * (y_test <= as.numeric(res$upper)))
## [1] 1

1 - ranger regression

obj <- learningmachine::Regressor$new(method = "ranger", pi_method = "splitconformal")
obj$get_type()
## [1] "regression"
obj$get_name()
## [1] "Regressor"
t0 <- proc.time()[3]
obj$fit(X_train, y_train)
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.01 s
print(sqrt(mean((obj$predict(X_test)$preds - y_test)^2)))
## [1] 2.302783
t0 <- proc.time()[3]
obj$fit(X_train, y_train)
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.011 s
obj$set_level(95)

res <- obj$predict(X = X_test)

plot(c(y_train, res$preds), type='l',
     main="",
     ylab="",
     ylim = c(min(c(res$upper, res$lower, y)),
              max(c(res$upper, res$lower, y))))
lines(c(y_train, res$upper), col="gray60")
lines(c(y_train, res$lower), col="gray60")
lines(c(y_train, res$preds), col = "red")
lines(c(y_train, y_test), col = "blue")

mean((y_test >= as.numeric(res$lower)) * (y_test <= as.numeric(res$upper)))
## [1] 1
res <- obj$predict(X = X_test)

plot(c(y_train, res$preds), type='l',
     main="",
     ylab="",
     ylim = c(min(c(res$upper, res$lower, y)),
              max(c(res$upper, res$lower, y))))
lines(c(y_train, res$upper), col="gray60")
lines(c(y_train, res$lower), col="gray60")
lines(c(y_train, res$preds), col = "red")
lines(c(y_train, y_test), col = "blue")

mean((y_test >= as.numeric(res$lower)) * (y_test <= as.numeric(res$upper)))
## [1] 1

2 - KRR & ranger regression on Boston

# Boston dataset (dataset has an ethical problem)
library(MASS)
data("Boston")

set.seed(13)
train_idx <- sample(nrow(Boston), 0.8 * nrow(Boston))
X_train <- as.matrix(Boston[train_idx, -ncol(Boston)])
X_test <- as.matrix(Boston[-train_idx, -ncol(Boston)])
y_train <- Boston$medv[train_idx]
y_test <- Boston$medv[-train_idx]

KRR

obj <- learningmachine::Regressor$new(method = "krr", pi_method = "none")
obj$get_type()
## [1] "regression"
obj$get_name()
## [1] "Regressor"
obj$get_method()
## [1] "krr"
t0 <- proc.time()[3]
obj$fit(X_train, y_train, reg_lambda = 0.1)
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.029 s
print(sqrt(mean((obj$predict(X_test) - y_test)^2)))
## [1] 2.888748
t0 <- proc.time()[3]
obj$summary(X_test, y=y_test, show_progress=FALSE)
## $R_squared
## [1] 0.906853
## 
## $R_squared_adj
## [1] 0.8930926
## 
## $Residuals
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
## -8.33671 -1.10461 -0.02411  0.12105  1.46980  9.29398 
## 
## $citests
##              estimate         lower         upper      p-value signif
## crim    -0.0544164530  -0.075529516 -0.0333033896 1.509961e-06    ***
## zn      -0.0046418101  -0.009605912  0.0003222914 6.652189e-02      .
## indus   -0.0245357110  -0.051187606  0.0021161842 7.077114e-02      .
## chas     7.1730075477   6.375361838  7.9706532576 5.512518e-33    ***
## nox     -9.4958030753 -12.095806303 -6.8957998474 8.811259e-11    ***
## rm       4.7080249286   3.939353604  5.4766962526 1.787394e-21    ***
## age     -0.0439718628  -0.053082559 -0.0348611667 7.779486e-16    ***
## dis     -1.4214523042  -1.573146091 -1.2697585171 2.257304e-34    ***
## rad      0.1810040336   0.155692359  0.2063157080 8.827967e-26    ***
## tax     -0.0115644823  -0.013066430 -0.0100625342 5.303780e-28    ***
## ptratio -0.4819300831  -0.582754790 -0.3811053766 1.242164e-15    ***
## black   -0.0002461991  -0.001967809  0.0014754112 7.772335e-01       
## lstat   -0.4091458985  -0.475209948 -0.3430818492 9.126116e-22    ***
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             102    
## Number of columns          13     
## _______________________           
## Column type frequency:            
##   numeric                  13     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable      mean       sd       p0       p25        p50      p75
##  1 crim          -0.0544    0.107    -0.416   -0.0696  -0.00478    0.00661
##  2 zn            -0.00464   0.0253   -0.0524  -0.0200  -0.00301    0.00416
##  3 indus         -0.0245    0.136    -0.308   -0.109   -0.0396     0.0220 
##  4 chas           7.17      4.06    -17.7      5.97     7.12       9.16   
##  5 nox           -9.50     13.2     -78.3    -15.0     -7.32      -2.30   
##  6 rm             4.71      3.91     -3.43     1.83     4.48       7.72   
##  7 age           -0.0440    0.0464   -0.138   -0.0778  -0.0506    -0.00674
##  8 dis           -1.42      0.772    -3.43    -1.80    -1.32      -0.933  
##  9 rad            0.181     0.129    -0.0944   0.0827   0.173      0.261  
## 10 tax           -0.0116    0.00765  -0.0388  -0.0148  -0.00963   -0.00718
## 11 ptratio       -0.482     0.513    -2.13    -0.671   -0.441     -0.209  
## 12 black         -0.000246  0.00877  -0.0263  -0.00450  0.0000316  0.00344
## 13 lstat         -0.409     0.336    -1.62    -0.474   -0.310     -0.189  
##        p100 hist 
##  1  0.107   ▁▁▂▇▅
##  2  0.0728  ▃▇▇▂▁
##  3  0.499   ▂▇▂▁▁
##  4 14.8     ▁▁▁▇▅
##  5 15.5     ▁▁▁▇▃
##  6 12.4     ▃▇▇▇▅
##  7  0.0628  ▂▇▆▃▂
##  8  0.0716  ▂▂▇▇▃
##  9  0.492   ▂▇▇▃▂
## 10  0.00304 ▁▁▃▇▂
## 11  1.01    ▁▁▇▃▁
## 12  0.0391  ▁▇▇▁▁
## 13  0.0311  ▁▁▂▆▇
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.793 s
t0 <- proc.time()[3]
obj$summary(X_test, y=y_test, show_progress=FALSE, type_ci="bootstrap")
## $R_squared
## [1] 0.906853
## 
## $R_squared_adj
## [1] 0.8930926
## 
## $Residuals
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
## -8.33671 -1.10461 -0.02411  0.12105  1.46980  9.29398 
## 
## $citests
##              estimate        lower         upper       p-value signif
## crim    -0.0538049728  -0.07788039 -0.0339150922 3.330856e-165    ***
## zn      -0.0046264575  -0.00930898  0.0002208004 2.129513e-162    ***
## indus   -0.0250873356  -0.04983945  0.0013580905 3.367434e-162    ***
## chas     7.1874845264   6.31700628  7.8848224325 3.330856e-165    ***
## nox     -9.4746636134 -12.26642878 -6.9077586130 3.330856e-165    ***
## rm       4.7102428290   3.86896609  5.5034002307 3.330856e-165    ***
## age     -0.0440650425  -0.05296489 -0.0349701343 3.330856e-165    ***
## dis     -1.4211028552  -1.56809609 -1.2833726839 3.330856e-165    ***
## rad      0.1812312885   0.15663376  0.2067723827 3.330856e-165    ***
## tax     -0.0115489146  -0.01305204 -0.0100571311 3.330856e-165    ***
## ptratio -0.4789522388  -0.58263847 -0.3853958372 3.330856e-165    ***
## black   -0.0002264778  -0.00187825  0.0015182254  9.583495e-16    ***
## lstat   -0.4057946096  -0.47807035 -0.3461364993 3.330856e-165    ***
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             102    
## Number of columns          13     
## _______________________           
## Column type frequency:            
##   numeric                  13     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable      mean       sd       p0       p25        p50      p75
##  1 crim          -0.0544    0.107    -0.416   -0.0696  -0.00478    0.00661
##  2 zn            -0.00464   0.0253   -0.0524  -0.0200  -0.00301    0.00416
##  3 indus         -0.0245    0.136    -0.308   -0.109   -0.0396     0.0220 
##  4 chas           7.17      4.06    -17.7      5.97     7.12       9.16   
##  5 nox           -9.50     13.2     -78.3    -15.0     -7.32      -2.30   
##  6 rm             4.71      3.91     -3.43     1.83     4.48       7.72   
##  7 age           -0.0440    0.0464   -0.138   -0.0778  -0.0506    -0.00674
##  8 dis           -1.42      0.772    -3.43    -1.80    -1.32      -0.933  
##  9 rad            0.181     0.129    -0.0944   0.0827   0.173      0.261  
## 10 tax           -0.0116    0.00765  -0.0388  -0.0148  -0.00963   -0.00718
## 11 ptratio       -0.482     0.513    -2.13    -0.671   -0.441     -0.209  
## 12 black         -0.000246  0.00877  -0.0263  -0.00450  0.0000316  0.00344
## 13 lstat         -0.409     0.336    -1.62    -0.474   -0.310     -0.189  
##        p100 hist 
##  1  0.107   ▁▁▂▇▅
##  2  0.0728  ▃▇▇▂▁
##  3  0.499   ▂▇▂▁▁
##  4 14.8     ▁▁▁▇▅
##  5 15.5     ▁▁▁▇▃
##  6 12.4     ▃▇▇▇▅
##  7  0.0628  ▂▇▆▃▂
##  8  0.0716  ▂▂▇▇▃
##  9  0.492   ▂▇▇▃▂
## 10  0.00304 ▁▁▃▇▂
## 11  1.01    ▁▁▇▃▁
## 12  0.0391  ▁▇▇▁▁
## 13  0.0311  ▁▁▂▆▇
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  1.229 s
t0 <- proc.time()[3]
obj$summary(X_test, y=y_test, show_progress=FALSE, type_ci="conformal")
## $R_squared
## [1] 0.906853
## 
## $R_squared_adj
## [1] 0.8930926
## 
## $Residuals
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
## -8.33671 -1.10461 -0.02411  0.12105  1.46980  9.29398 
## 
## $citests
##             estimate        lower         upper      p-value signif
## crim    -0.037922954  -0.07328928 -0.0139185368 1.268525e-83    ***
## zn      -0.003245926  -0.01123917  0.0042341372 8.112018e-51    ***
## indus   -0.009505317  -0.05165442  0.0376237962 3.771573e-16    ***
## chas     7.003792862   6.02912386  7.9131077572 1.268525e-83    ***
## nox     -8.038548064 -12.47241636 -4.7336175973 1.268525e-83    ***
## rm       5.371557272   4.35587894  6.1934399509 1.268525e-83    ***
## age     -0.050808359  -0.06384589 -0.0376572320 1.268525e-83    ***
## dis     -1.371538135  -1.57056696 -1.1796657263 1.268525e-83    ***
## rad      0.185007799   0.15210036  0.2141058406 1.268525e-83    ***
## tax     -0.011855390  -0.01433893 -0.0099523056 1.268525e-83    ***
## ptratio -0.561089487  -0.71011786 -0.4057723234 1.268525e-83    ***
## black   -0.001429035  -0.00335513  0.0004864625 1.733542e-76    ***
## lstat   -0.403259203  -0.50131121 -0.3087645375 1.268525e-83    ***
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             102    
## Number of columns          13     
## _______________________           
## Column type frequency:            
##   numeric                  13     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable      mean       sd       p0       p25        p50      p75
##  1 crim          -0.0544    0.107    -0.416   -0.0696  -0.00478    0.00661
##  2 zn            -0.00464   0.0253   -0.0524  -0.0200  -0.00301    0.00416
##  3 indus         -0.0245    0.136    -0.308   -0.109   -0.0396     0.0220 
##  4 chas           7.17      4.06    -17.7      5.97     7.12       9.16   
##  5 nox           -9.50     13.2     -78.3    -15.0     -7.32      -2.30   
##  6 rm             4.71      3.91     -3.43     1.83     4.48       7.72   
##  7 age           -0.0440    0.0464   -0.138   -0.0778  -0.0506    -0.00674
##  8 dis           -1.42      0.772    -3.43    -1.80    -1.32      -0.933  
##  9 rad            0.181     0.129    -0.0944   0.0827   0.173      0.261  
## 10 tax           -0.0116    0.00765  -0.0388  -0.0148  -0.00963   -0.00718
## 11 ptratio       -0.482     0.513    -2.13    -0.671   -0.441     -0.209  
## 12 black         -0.000246  0.00877  -0.0263  -0.00450  0.0000316  0.00344
## 13 lstat         -0.409     0.336    -1.62    -0.474   -0.310     -0.189  
##        p100 hist 
##  1  0.107   ▁▁▂▇▅
##  2  0.0728  ▃▇▇▂▁
##  3  0.499   ▂▇▂▁▁
##  4 14.8     ▁▁▁▇▅
##  5 15.5     ▁▁▁▇▃
##  6 12.4     ▃▇▇▇▅
##  7  0.0628  ▂▇▆▃▂
##  8  0.0716  ▂▂▇▇▃
##  9  0.492   ▂▇▇▃▂
## 10  0.00304 ▁▁▃▇▂
## 11  1.01    ▁▁▇▃▁
## 12  0.0391  ▁▇▇▁▁
## 13  0.0311  ▁▁▂▆▇
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.774 s

ranger

obj <- learningmachine::Regressor$new(method = "ranger", pi_method="splitconformal")
obj$get_type()
## [1] "regression"
obj$get_name()
## [1] "Regressor"
t0 <- proc.time()[3]
obj$fit(X_train, y_train)
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.052 s
print(sqrt(mean((obj$predict(X_test)$preds - y_test)^2)))
## [1] 3.74535
t0 <- proc.time()[3]
obj$summary(X_test, y=y_test, show_progress=FALSE)
## $R_squared
## [1] 0.8434207
## 
## $R_squared_adj
## [1] 0.8202897
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -8.8563 -1.5963 -0.1491  0.4260  1.9961 12.6714 
## 
## $Coverage_rate
## [1] 100
## 
## $citests
##             estimate         lower        upper      p-value signif
## crim     -49.6344261 -232.91685299  133.6480007 5.923034e-01       
## zn         0.0784486   -0.06027044    0.2171676 2.645894e-01       
## indus    -18.8096072  -34.04595819   -3.5732562 1.604939e-02      *
## chas       0.0000000           NaN          NaN          NaN       
## nox     -467.8840363 -627.07556952 -308.6925031 6.664467e-08    ***
## rm       276.5215702  225.72209883  327.3210416 1.573542e-18    ***
## age       -2.0367081   -2.86343009   -1.2099861 3.857020e-06    ***
## dis       22.5199587   -1.94139968   46.9813170 7.076063e-02      .
## rad        1.5745877   -0.25222578    3.4014011 9.036604e-02      .
## tax       -0.6832444   -0.89986179   -0.4666270 9.564055e-09    ***
## ptratio  -31.9041989  -38.38822071  -25.4201770 3.019931e-16    ***
## black     -0.3827134   -0.63975500   -0.1256717 3.907316e-03     **
## lstat    -44.9609199  -57.58730968  -32.3345300 2.116676e-10    ***
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             102    
## Number of columns          13     
## _______________________           
## Column type frequency:            
##   numeric                  13     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable      mean      sd       p0      p25      p50     p75     p100
##  1 crim           -49.6    933.    -6399.    -70.6    -10.7    53.3   2113.   
##  2 zn               0.0784   0.706    -1.09    0        0       0        5.76 
##  3 indus          -18.8     77.6    -451.     -7.13     2.68    7.68    49.6  
##  4 chas             0        0         0       0        0       0        0    
##  5 nox           -468.     810.    -3221.   -897.    -224.     53.8    769.   
##  6 rm             277.     259.      -17.7    73.5    191.    361.     855.   
##  7 age             -2.04     4.21    -34.1    -2.99    -1.10    0        7.16 
##  8 dis             22.5    125.     -167.    -25.8     -3.58    4.74   644.   
##  9 rad              1.57     9.30     -4.32    0        0       0.242   88.1  
## 10 tax             -0.683    1.10     -4.90   -0.606   -0.305  -0.121    0.333
## 11 ptratio        -31.9     33.0    -150.    -42.1    -21.2    -8.87     7.14 
## 12 black           -0.383    1.31     -4.96   -0.884    0       0.424    2.11 
## 13 lstat          -45.0     64.3    -332.    -53.9    -24.2    -6.86    24.7  
##    hist 
##  1 ▁▁▁▇▁
##  2 ▇▁▁▁▁
##  3 ▁▁▁▁▇
##  4 ▁▁▇▁▁
##  5 ▁▁▅▇▆
##  6 ▇▃▂▁▂
##  7 ▁▁▁▇▇
##  8 ▇▇▁▁▁
##  9 ▇▁▁▁▁
## 10 ▁▁▁▁▇
## 11 ▁▁▂▅▇
## 12 ▁▁▂▇▂
## 13 ▁▁▁▂▇
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.455 s
t0 <- proc.time()[3]
obj$summary(X_test, y=y_test, show_progress=FALSE, type_ci="bootstrap")
## Warning in wilcox.test.default(x, mu = mu_0): cannot compute exact p-value with
## zeroes
## $R_squared
## [1] 0.8434207
## 
## $R_squared_adj
## [1] 0.8202897
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -8.8563 -1.5963 -0.1491  0.4260  1.9961 12.6714 
## 
## $Coverage_rate
## [1] 100
## 
## $citests
##              estimate         lower        upper       p-value signif
## crim     -45.39300398 -252.35254750  105.6958272  1.682119e-56    ***
## zn         0.07113834   -0.04309201    0.2304618 3.967833e-137    ***
## indus    -18.37780619  -34.75011937   -5.5584701 3.371100e-165    ***
## chas       0.00000000    0.00000000    0.0000000           NaN       
## nox     -464.07375760 -633.95015108 -310.1167462 3.330856e-165    ***
## rm       274.35623912  225.68252481  332.0295218 3.330856e-165    ***
## age       -2.01815861   -2.94318020   -1.2850614 3.330856e-165    ***
## dis       21.29375149    0.03005176   48.1614331 5.506114e-163    ***
## rad        1.43034678    0.30692307    3.5901415 3.330856e-165    ***
## tax       -0.68195179   -0.90608771   -0.4707029 3.330856e-165    ***
## ptratio  -31.83678007  -39.05187548  -25.5074573 3.330856e-165    ***
## black     -0.38032502   -0.61610598   -0.1410594 3.360994e-165    ***
## lstat    -44.75647422  -58.07568071  -33.4538379 3.330856e-165    ***
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             102    
## Number of columns          13     
## _______________________           
## Column type frequency:            
##   numeric                  13     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable      mean      sd       p0      p25      p50     p75     p100
##  1 crim           -49.6    933.    -6399.    -70.6    -10.7    53.3   2113.   
##  2 zn               0.0784   0.706    -1.09    0        0       0        5.76 
##  3 indus          -18.8     77.6    -451.     -7.13     2.68    7.68    49.6  
##  4 chas             0        0         0       0        0       0        0    
##  5 nox           -468.     810.    -3221.   -897.    -224.     53.8    769.   
##  6 rm             277.     259.      -17.7    73.5    191.    361.     855.   
##  7 age             -2.04     4.21    -34.1    -2.99    -1.10    0        7.16 
##  8 dis             22.5    125.     -167.    -25.8     -3.58    4.74   644.   
##  9 rad              1.57     9.30     -4.32    0        0       0.242   88.1  
## 10 tax             -0.683    1.10     -4.90   -0.606   -0.305  -0.121    0.333
## 11 ptratio        -31.9     33.0    -150.    -42.1    -21.2    -8.87     7.14 
## 12 black           -0.383    1.31     -4.96   -0.884    0       0.424    2.11 
## 13 lstat          -45.0     64.3    -332.    -53.9    -24.2    -6.86    24.7  
##    hist 
##  1 ▁▁▁▇▁
##  2 ▇▁▁▁▁
##  3 ▁▁▁▁▇
##  4 ▁▁▇▁▁
##  5 ▁▁▅▇▆
##  6 ▇▃▂▁▂
##  7 ▁▁▁▇▇
##  8 ▇▇▁▁▁
##  9 ▇▁▁▁▁
## 10 ▁▁▁▁▇
## 11 ▁▁▂▅▇
## 12 ▁▁▂▇▂
## 13 ▁▁▁▂▇
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.69 s
t0 <- proc.time()[3]
obj$summary(X_test, y=y_test, show_progress=FALSE, type_ci="conformal")
## Warning in wilcox.test.default(x, mu = mu_0): cannot compute exact p-value with
## zeroes
## $R_squared
## [1] 0.8434207
## 
## $R_squared_adj
## [1] 0.8202897
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -8.8563 -1.5963 -0.1491  0.4260  1.9961 12.6714 
## 
## $Coverage_rate
## [1] 100
## 
## $citests
##             estimate         lower        upper      p-value signif
## crim      -5.7668376 -191.32459192  166.6670019 4.503969e-02      *
## zn         0.1435863   -0.04898389    0.4653465 1.780801e-75    ***
## indus    -30.1885421  -60.17170897   -7.3625392 1.268525e-83    ***
## chas       0.0000000    0.00000000    0.0000000          NaN       
## nox     -475.8384341 -689.18361469 -238.1966040 1.268525e-83    ***
## rm       295.6431870  225.05343996  372.1962857 1.268525e-83    ***
## age       -1.7449947   -3.43479688   -0.6898904 1.268525e-83    ***
## dis       20.2776295  -14.47594907   65.3191964 5.215786e-65    ***
## rad        2.4761206    0.27316780    7.7188457 1.331000e-83    ***
## tax       -0.6569972   -1.03400273   -0.3784882 1.268525e-83    ***
## ptratio  -34.7056749  -43.95146053  -26.6399388 1.268525e-83    ***
## black     -0.6447480   -1.08425142   -0.2753894 1.268525e-83    ***
## lstat    -48.7558107  -68.57485771  -32.8653183 1.268525e-83    ***
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             102    
## Number of columns          13     
## _______________________           
## Column type frequency:            
##   numeric                  13     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable      mean      sd       p0      p25      p50     p75     p100
##  1 crim           -49.6    933.    -6399.    -70.6    -10.7    53.3   2113.   
##  2 zn               0.0784   0.706    -1.09    0        0       0        5.76 
##  3 indus          -18.8     77.6    -451.     -7.13     2.68    7.68    49.6  
##  4 chas             0        0         0       0        0       0        0    
##  5 nox           -468.     810.    -3221.   -897.    -224.     53.8    769.   
##  6 rm             277.     259.      -17.7    73.5    191.    361.     855.   
##  7 age             -2.04     4.21    -34.1    -2.99    -1.10    0        7.16 
##  8 dis             22.5    125.     -167.    -25.8     -3.58    4.74   644.   
##  9 rad              1.57     9.30     -4.32    0        0       0.242   88.1  
## 10 tax             -0.683    1.10     -4.90   -0.606   -0.305  -0.121    0.333
## 11 ptratio        -31.9     33.0    -150.    -42.1    -21.2    -8.87     7.14 
## 12 black           -0.383    1.31     -4.96   -0.884    0       0.424    2.11 
## 13 lstat          -45.0     64.3    -332.    -53.9    -24.2    -6.86    24.7  
##    hist 
##  1 ▁▁▁▇▁
##  2 ▇▁▁▁▁
##  3 ▁▁▁▁▇
##  4 ▁▁▇▁▁
##  5 ▁▁▅▇▆
##  6 ▇▃▂▁▂
##  7 ▁▁▁▇▇
##  8 ▇▇▁▁▁
##  9 ▇▁▁▁▁
## 10 ▁▁▁▁▇
## 11 ▁▁▂▅▇
## 12 ▁▁▂▇▂
## 13 ▁▁▁▂▇
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.487 s

3 - KRR regression on mtcars

X <- as.matrix(mtcars[,-1])
y <- mtcars$mpg

set.seed(123)
(index_train <- base::sample.int(n = nrow(X),
                                 size = floor(0.7*nrow(X)),
                                 replace = FALSE))
##  [1] 31 15 19 14  3 10 18 22 11  5 20 29 23 30  9 28  8 27  7 32 26 17
X_train <- X[index_train, ]
y_train <- y[index_train]
X_test <- X[-index_train, ]
y_test <- y[-index_train]
dim(X_train)
## [1] 22 10
dim(X_test)
## [1] 10 10
obj <- learningmachine::Regressor$new(method = "krr", pi_method = "splitconformal")
obj$get_type()
## [1] "regression"
obj$get_name()
## [1] "Regressor"
t0 <- proc.time()[3]
obj$fit(X_train, y_train, reg_lambda = 0.1)
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.002 s
print(obj$predict(X_test))
## $preds
##  [1] 22.151349 21.802194 12.541365 10.124759 13.408181 14.155816  7.421184
##  [8] 16.879536 13.615153 12.749565
## 
## $lower
##  [1] 12.1513495 11.8021941  2.5413650  0.1247588  3.4081805  4.1558157
##  [7] -2.5788160  6.8795365  3.6151533  2.7495651
## 
## $upper
##  [1] 32.15135 31.80219 22.54137 20.12476 23.40818 24.15582 17.42118 26.87954
##  [9] 23.61515 22.74957
t0 <- proc.time()[3]
obj$fit(X_train, y_train, reg_lambda = 0.1)
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.002 s
obj$set_level(95)
obj$set_pi_method("splitconformal")
res <- obj$predict(X = X_test)

plot(c(y_train, res$preds), type='l',
     main="",
     ylab="",
     ylim = c(min(c(res$upper, res$lower, y)),
              max(c(res$upper, res$lower, y))))
lines(c(y_train, res$upper), col="gray60")
lines(c(y_train, res$lower), col="gray60")
lines(c(y_train, res$preds), col = "red")
lines(c(y_train, y_test), col = "blue")

mean((y_test >= as.numeric(res$lower)) * (y_test <= as.numeric(res$upper)))
## [1] 1
t0 <- proc.time()[3]
obj$fit(X_train, y_train, reg_lambda = 0.1)
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.002 s
res <- obj$predict(X = X_test)

plot(c(y_train, res$preds), type='l',
     main="",
     ylab="",
     ylim = c(min(c(res$upper, res$lower, y)),
              max(c(res$upper, res$lower, y))))
lines(c(y_train, res$upper), col="gray60")
lines(c(y_train, res$lower), col="gray60")
lines(c(y_train, res$preds), col = "red")
lines(c(y_train, y_test), col = "blue")

mean((y_test >= as.numeric(res$lower)) * (y_test <= as.numeric(res$upper)))
## [1] 1
t0 <- proc.time()[3]
obj$summary(X_test, y=y_test, show_progress=FALSE)
## $R_squared
## [1] -0.8614864
## 
## $R_squared_adj
## [1] 17.75338
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -1.1513  0.5083  3.0680  3.4751  5.9929  8.8586 
## 
## $Coverage_rate
## [1] 100
## 
## $citests
##           estimate        lower        upper      p-value signif
## cyl   -23.98943109  -46.4975109   -1.4813513 3.918219e-02      *
## disp   -0.61133395   -0.9655770   -0.2570909 3.597927e-03     **
## hp     -0.07828878   -0.3785573    0.2219797 5.698268e-01       
## drat  310.94399534  160.4146969  461.4732937 1.163859e-03     **
## wt   -197.39979731 -240.1776661 -154.6219286 2.500030e-06    ***
## qsec  -19.50660485  -54.1139966   15.1007869 2.342132e-01       
## vs     69.84795566  -85.8899529  225.5858643 3.368080e-01       
## am    137.97019623   -0.2148915  276.1552839 5.028830e-02      .
## gear  191.57905165  134.3446800  248.8134233 3.424783e-05    ***
## carb    3.39227959  -22.2875140   29.0720732 7.718555e-01       
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             10     
## Number of columns          10     
## _______________________           
## Column type frequency:            
##   numeric                  10     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable      mean      sd      p0      p25       p50      p75      p100
##  1 cyl            -24.0     31.5    -64.0   -40.9    -34.1      -0.849   37.6   
##  2 disp            -0.611    0.495   -1.66   -0.934   -0.429    -0.307   -0.0817
##  3 hp              -0.0783   0.420   -1.00   -0.218   -0.0402    0.235    0.359 
##  4 drat           311.     210.    -159.    195.     369.      464.     534.    
##  5 wt            -197.      59.8   -280.   -252.    -196.     -144.    -124.    
##  6 qsec           -19.5     48.4    -73.4   -60.0    -29.3      12.8     60.3   
##  7 vs              69.8    218.    -218.   -104.      86.1     103.     421.    
##  8 am             138.     193.    -161.     99.8    162.      201.     516.    
##  9 gear           192.      80.0     74.7   142.     178.      224.     367.    
## 10 carb             3.39    35.9    -56.3    -6.54     3.71     36.0     41.3   
##    hist 
##  1 ▃▇▂▃▂
##  2 ▂▂▂▆▇
##  3 ▂▁▆▃▇
##  4 ▂▁▆▃▇
##  5 ▇▁▇▂▇
##  6 ▇▇▂▂▅
##  7 ▆▂▇▁▃
##  8 ▂▁▇▁▁
##  9 ▂▇▃▂▂
## 10 ▃▁▆▂▇
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.098 s
t0 <- proc.time()[3]
obj$summary(X_test, y=y_test, show_progress=FALSE, type_ci="bootstrap")
## $R_squared
## [1] -0.8614864
## 
## $R_squared_adj
## [1] 17.75338
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -1.1513  0.5083  3.0680  3.4751  5.9929  8.8586 
## 
## $Coverage_rate
## [1] 100
## 
## $citests
##           estimate        lower        upper       p-value signif
## cyl   -24.90623398  -40.2794196   -5.6202611 3.536958e-165    ***
## disp   -0.60214954   -0.9189034   -0.3419554 3.330824e-165    ***
## hp     -0.06820063   -0.3342753    0.1339877  1.174915e-64    ***
## drat  314.63303511  178.9216937  418.0172986 3.330824e-165    ***
## wt   -197.32353350 -232.9121566 -163.3831785 3.330824e-165    ***
## qsec  -19.52528169  -44.6875092    9.0752923 1.159421e-146    ***
## vs     71.87587019  -47.6861837  190.9669405 1.623953e-133    ***
## am    139.18488710   28.8373119  248.4883434 4.072915e-165    ***
## gear  190.53694931  146.5700802  240.0194316 3.330824e-165    ***
## carb    3.53972676  -17.6098472   22.3805033  3.220691e-21    ***
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             10     
## Number of columns          10     
## _______________________           
## Column type frequency:            
##   numeric                  10     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable      mean      sd      p0      p25       p50      p75      p100
##  1 cyl            -24.0     31.5    -64.0   -40.9    -34.1      -0.849   37.6   
##  2 disp            -0.611    0.495   -1.66   -0.934   -0.429    -0.307   -0.0817
##  3 hp              -0.0783   0.420   -1.00   -0.218   -0.0402    0.235    0.359 
##  4 drat           311.     210.    -159.    195.     369.      464.     534.    
##  5 wt            -197.      59.8   -280.   -252.    -196.     -144.    -124.    
##  6 qsec           -19.5     48.4    -73.4   -60.0    -29.3      12.8     60.3   
##  7 vs              69.8    218.    -218.   -104.      86.1     103.     421.    
##  8 am             138.     193.    -161.     99.8    162.      201.     516.    
##  9 gear           192.      80.0     74.7   142.     178.      224.     367.    
## 10 carb             3.39    35.9    -56.3    -6.54     3.71     36.0     41.3   
##    hist 
##  1 ▃▇▂▃▂
##  2 ▂▂▂▆▇
##  3 ▂▁▆▃▇
##  4 ▂▁▆▃▇
##  5 ▇▁▇▂▇
##  6 ▇▇▂▂▅
##  7 ▆▂▇▁▃
##  8 ▂▁▇▁▁
##  9 ▂▇▃▂▂
## 10 ▃▁▆▂▇
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.223 s
t0 <- proc.time()[3]
obj$summary(X_test, y=y_test, show_progress=FALSE, type_ci="conformal")
## $R_squared
## [1] -0.8614864
## 
## $R_squared_adj
## [1] 17.75338
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -1.1513  0.5083  3.0680  3.4751  5.9929  8.8586 
## 
## $Coverage_rate
## [1] 100
## 
## $citests
##          estimate        lower        upper      p-value signif
## cyl   -30.3071287  -49.9396464   -8.4953754 1.274399e-83    ***
## disp   -0.5711107   -0.9053391   -0.2698173 1.248685e-83    ***
## hp     -0.1447852   -0.6649476    0.2193783 1.927937e-42    ***
## drat  235.3168021   22.7135545  438.1655998 2.124126e-83    ***
## wt   -212.1232593 -259.4448623 -164.8016563 1.252428e-83    ***
## qsec   -4.0186808  -46.0259583   39.5943470 4.746701e-04    ***
## vs     83.9673011  -61.9645779  278.4586560 5.121587e-65    ***
## am     96.8375738  -40.2796351  191.6570772 6.634928e-76    ***
## gear  167.6983530  105.2072207  220.0858429 1.255511e-83    ***
## carb   -7.0945741  -33.9051378   13.4955287 2.013463e-30    ***
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             10     
## Number of columns          10     
## _______________________           
## Column type frequency:            
##   numeric                  10     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable      mean      sd      p0      p25       p50      p75      p100
##  1 cyl            -24.0     31.5    -64.0   -40.9    -34.1      -0.849   37.6   
##  2 disp            -0.611    0.495   -1.66   -0.934   -0.429    -0.307   -0.0817
##  3 hp              -0.0783   0.420   -1.00   -0.218   -0.0402    0.235    0.359 
##  4 drat           311.     210.    -159.    195.     369.      464.     534.    
##  5 wt            -197.      59.8   -280.   -252.    -196.     -144.    -124.    
##  6 qsec           -19.5     48.4    -73.4   -60.0    -29.3      12.8     60.3   
##  7 vs              69.8    218.    -218.   -104.      86.1     103.     421.    
##  8 am             138.     193.    -161.     99.8    162.      201.     516.    
##  9 gear           192.      80.0     74.7   142.     178.      224.     367.    
## 10 carb             3.39    35.9    -56.3    -6.54     3.71     36.0     41.3   
##    hist 
##  1 ▃▇▂▃▂
##  2 ▂▂▂▆▇
##  3 ▂▁▆▃▇
##  4 ▂▁▆▃▇
##  5 ▇▁▇▂▇
##  6 ▇▇▂▂▅
##  7 ▆▂▇▁▃
##  8 ▂▁▇▁▁
##  9 ▂▇▃▂▂
## 10 ▃▁▆▂▇
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.1 s
obj$set_pi_method("kdejackknifeplus")
t0 <- proc.time()[3]
obj$fit(X_train, y_train, reg_lambda = 0.1)
##   |                                                                              |                                                                      |   0%  |                                                                              |===                                                                   |   5%  |                                                                              |=======                                                               |  10%  |                                                                              |==========                                                            |  14%  |                                                                              |=============                                                         |  19%  |                                                                              |=================                                                     |  24%  |                                                                              |====================                                                  |  29%  |                                                                              |=======================                                               |  33%  |                                                                              |===========================                                           |  38%  |                                                                              |==============================                                        |  43%  |                                                                              |=================================                                     |  48%  |                                                                              |=====================================                                 |  52%  |                                                                              |========================================                              |  57%  |                                                                              |===========================================                           |  62%  |                                                                              |===============================================                       |  67%  |                                                                              |==================================================                    |  71%  |                                                                              |=====================================================                 |  76%  |                                                                              |=========================================================             |  81%  |                                                                              |============================================================          |  86%  |                                                                              |===============================================================       |  90%  |                                                                              |===================================================================   |  95%  |                                                                              |======================================================================| 100%
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.012 s
res <- obj$predict(X = X_test)

plot(c(y_train, res$preds), type='l',
     main="",
     ylab="",
     ylim = c(min(c(res$upper, res$lower, y)),
              max(c(res$upper, res$lower, y))))
lines(c(y_train, res$upper), col="gray60")
lines(c(y_train, res$lower), col="gray60")
lines(c(y_train, res$preds), col = "red")
lines(c(y_train, y_test), col = "blue")

mean((y_test >= as.numeric(res$lower)) * (y_test <= as.numeric(res$upper)))
## [1] 1
t0 <- proc.time()[3]
obj$summary(X_test, y=y_test, show_progress=FALSE)
## $R_squared
## [1] -3.416998
## 
## $R_squared_adj
## [1] 40.75299
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   3.516   4.540   6.386   6.917   8.633  12.992 
## 
## $Coverage_rate
## [1] 100
## 
## $citests
##          estimate        lower       upper      p-value signif
## cyl   -36.7817740  -50.6623622 -22.9011858 2.038888e-04    ***
## disp   -0.2133047   -0.6537255   0.2271161 3.017009e-01       
## hp     -0.2920633   -0.8288709   0.2447443 2.495994e-01       
## drat  259.9789584  141.9967301 377.9611867 7.545111e-04    ***
## wt   -125.6032827 -159.9084338 -91.2981317 1.675653e-05    ***
## qsec    6.1547882  -22.2053730  34.5149494 6.352182e-01       
## vs     35.1176737  -92.7670167 163.0023641 5.498770e-01       
## am     85.8109695  -32.8651723 204.4871113 1.363325e-01       
## gear  264.4099446  185.2573493 343.5625399 3.479849e-05    ***
## carb  -24.1859057  -56.7206453   8.3488338 1.269314e-01       
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             10     
## Number of columns          10     
## _______________________           
## Column type frequency:            
##   numeric                  10     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable     mean      sd      p0      p25        p50      p75    p100
##  1 cyl            -36.8    19.4    -52.8   -48.3    -40.9      -37.7    13.0  
##  2 disp            -0.213   0.616   -1.19   -0.561   -0.212     -0.146   0.781
##  3 hp              -0.292   0.750   -1.73   -0.461    0.00750    0.135   0.531
##  4 drat           260.    165.     -74.7   161.     265.       381.    485.   
##  5 wt            -126.     48.0   -202.   -152.    -125.      -105.    -30.9  
##  6 qsec             6.15   39.6    -55.5   -20.7     -1.84      33.6    64.2  
##  7 vs              35.1   179.    -232.   -108.      68.7       95.1   292.   
##  8 am              85.8   166.    -205.     94.4    122.       144.    346.   
##  9 gear           264.    111.     122.    206.     242.       301.    529.   
## 10 carb           -24.2    45.5    -73.7   -54.9    -47.2       22.6    39.5  
##    hist 
##  1 ▇▅▂▁▂
##  2 ▂▃▇▁▃
##  3 ▃▁▂▇▆
##  4 ▂▃▁▇▆
##  5 ▃▂▇▂▂
##  6 ▂▇▅▅▅
##  7 ▇▁▇▅▅
##  8 ▃▁▇▆▂
##  9 ▇▇▇▁▂
## 10 ▇▇▁▂▇
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.146 s
t0 <- proc.time()[3]
obj$summary(X_test, y=y_test, show_progress=FALSE, type_ci="bootstrap")
## $R_squared
## [1] -3.416998
## 
## $R_squared_adj
## [1] 40.75299
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   3.516   4.540   6.386   6.917   8.633  12.992 
## 
## $Coverage_rate
## [1] 100
## 
## $citests
##          estimate        lower       upper       p-value signif
## cyl   -37.7454484  -45.5951036 -25.4424864 3.330824e-165    ***
## disp   -0.2106604   -0.5751210   0.1509308 3.774075e-133    ***
## hp     -0.2879116   -0.7162016   0.1127945 9.161570e-149    ***
## drat  260.2656421  157.3020284 349.2281183 3.330824e-165    ***
## wt   -126.0333424 -152.2494144 -97.9210297 3.330824e-165    ***
## qsec    6.5179006  -16.0686231  30.1460294  2.976614e-52    ***
## vs     38.6340339  -67.2977058 131.2472107  2.898223e-78    ***
## am     87.8700197   -8.0927507 171.5314902 7.071000e-160    ***
## gear  263.7730423  206.7863856 330.1303853 3.330824e-165    ***
## carb  -24.3011733  -49.1225434   2.5087847 7.537326e-162    ***
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             10     
## Number of columns          10     
## _______________________           
## Column type frequency:            
##   numeric                  10     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable     mean      sd      p0      p25        p50      p75    p100
##  1 cyl            -36.8    19.4    -52.8   -48.3    -40.9      -37.7    13.0  
##  2 disp            -0.213   0.616   -1.19   -0.561   -0.212     -0.146   0.781
##  3 hp              -0.292   0.750   -1.73   -0.461    0.00750    0.135   0.531
##  4 drat           260.    165.     -74.7   161.     265.       381.    485.   
##  5 wt            -126.     48.0   -202.   -152.    -125.      -105.    -30.9  
##  6 qsec             6.15   39.6    -55.5   -20.7     -1.84      33.6    64.2  
##  7 vs              35.1   179.    -232.   -108.      68.7       95.1   292.   
##  8 am              85.8   166.    -205.     94.4    122.       144.    346.   
##  9 gear           264.    111.     122.    206.     242.       301.    529.   
## 10 carb           -24.2    45.5    -73.7   -54.9    -47.2       22.6    39.5  
##    hist 
##  1 ▇▅▂▁▂
##  2 ▂▃▇▁▃
##  3 ▃▁▂▇▆
##  4 ▂▃▁▇▆
##  5 ▃▂▇▂▂
##  6 ▂▇▅▅▅
##  7 ▇▁▇▅▅
##  8 ▃▁▇▆▂
##  9 ▇▇▇▁▂
## 10 ▇▇▁▂▇
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.271 s
t0 <- proc.time()[3]
obj$summary(X_test, y=y_test, show_progress=FALSE, type_ci="conformal")
## $R_squared
## [1] -3.416998
## 
## $R_squared_adj
## [1] 40.75299
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   3.516   4.540   6.386   6.917   8.633  12.992 
## 
## $Coverage_rate
## [1] 100
## 
## $citests
##          estimate        lower       upper      p-value signif
## cyl   -39.6925349  -46.8125094 -31.4799014 1.250193e-83    ***
## disp   -0.2225326   -0.8085783   0.3715319 2.958215e-47    ***
## hp     -0.1914698   -0.8268261   0.3270041 1.743778e-31    ***
## drat  241.6087630   67.3659664 403.8505741 1.354810e-83    ***
## wt   -125.2136758 -160.8136793 -75.5920029 1.249915e-83    ***
## qsec    5.3742789  -34.4860716  45.2346295 3.512780e-08    ***
## vs     57.7189131  -67.2086900 197.2153460 2.032329e-56    ***
## am     65.7388561  -67.8044887 153.3095833 2.324709e-56    ***
## gear  224.5553844  167.1960533 274.9425132 1.248716e-83    ***
## carb  -40.1390242  -64.1761115  -4.3770155 1.820336e-83    ***
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             10     
## Number of columns          10     
## _______________________           
## Column type frequency:            
##   numeric                  10     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable     mean      sd      p0      p25        p50      p75    p100
##  1 cyl            -36.8    19.4    -52.8   -48.3    -40.9      -37.7    13.0  
##  2 disp            -0.213   0.616   -1.19   -0.561   -0.212     -0.146   0.781
##  3 hp              -0.292   0.750   -1.73   -0.461    0.00750    0.135   0.531
##  4 drat           260.    165.     -74.7   161.     265.       381.    485.   
##  5 wt            -126.     48.0   -202.   -152.    -125.      -105.    -30.9  
##  6 qsec             6.15   39.6    -55.5   -20.7     -1.84      33.6    64.2  
##  7 vs              35.1   179.    -232.   -108.      68.7       95.1   292.   
##  8 am              85.8   166.    -205.     94.4    122.       144.    346.   
##  9 gear           264.    111.     122.    206.     242.       301.    529.   
## 10 carb           -24.2    45.5    -73.7   -54.9    -47.2       22.6    39.5  
##    hist 
##  1 ▇▅▂▁▂
##  2 ▂▃▇▁▃
##  3 ▃▁▂▇▆
##  4 ▂▃▁▇▆
##  5 ▃▂▇▂▂
##  6 ▂▇▅▅▅
##  7 ▇▁▇▅▅
##  8 ▃▁▇▆▂
##  9 ▇▇▇▁▂
## 10 ▇▇▁▂▇
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.148 s

xgboost

obj <- learningmachine::Regressor$new(method = "xgboost", pi_method = "splitconformal")
obj$get_type()
## [1] "regression"
obj$get_name()
## [1] "Regressor"
t0 <- proc.time()[3]
obj$fit(X_train, y_train, nrounds=10, verbose=FALSE)
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.014 s
print(obj$predict(X_test))
## $preds
##  [1] 18.13500 18.13500 17.13105 17.13105 14.64118 14.64118 14.03685 21.29947
##  [9] 15.33300 14.03685
## 
## $lower
##  [1] 12.135002 12.135002 11.131052 11.131052  8.641179  8.641179  8.036854
##  [8] 15.299475  9.333004  8.036854
## 
## $upper
##  [1] 24.13500 24.13500 23.13105 23.13105 20.64118 20.64118 20.03685 27.29947
##  [9] 21.33300 20.03685
t0 <- proc.time()[3]
obj$summary(X_test, y=y_test, show_progress=FALSE)
## $R_squared
## [1] 0.2881145
## 
## $R_squared_adj
## [1] 7.406969
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -3.6369  0.3926  2.2088  1.5079  2.8650  5.1631 
## 
## $Coverage_rate
## [1] 100
## 
## $citests
##        estimate       lower      upper   p-value signif
## cyl   0.0000000         NaN        NaN       NaN       
## disp -0.1859971  -0.6067516  0.2347575 0.3434364       
## hp    0.0000000         NaN        NaN       NaN       
## drat 28.9866074 -18.4823056 76.4555203 0.2004909       
## wt    0.0000000         NaN        NaN       NaN       
## qsec -1.7295559  -5.6420830  2.1829713 0.3434364       
## vs    0.0000000         NaN        NaN       NaN       
## am    0.0000000         NaN        NaN       NaN       
## gear  0.0000000         NaN        NaN       NaN       
## carb  0.0000000         NaN        NaN       NaN       
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             10     
## Number of columns          10     
## _______________________           
## Column type frequency:            
##   numeric                  10     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable   mean     sd     p0 p25 p50 p75 p100 hist 
##  1 cyl            0      0       0      0   0   0   0  ▁▁▇▁▁
##  2 disp          -0.186  0.588  -1.86   0   0   0   0  ▁▁▁▁▇
##  3 hp             0      0       0      0   0   0   0  ▁▁▇▁▁
##  4 drat          29.0   66.4     0      0   0   0 200. ▇▁▁▁▁
##  5 wt             0      0       0      0   0   0   0  ▁▁▇▁▁
##  6 qsec          -1.73   5.47  -17.3    0   0   0   0  ▁▁▁▁▇
##  7 vs             0      0       0      0   0   0   0  ▁▁▇▁▁
##  8 am             0      0       0      0   0   0   0  ▁▁▇▁▁
##  9 gear           0      0       0      0   0   0   0  ▁▁▇▁▁
## 10 carb           0      0       0      0   0   0   0  ▁▁▇▁▁
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.181 s
t0 <- proc.time()[3]
obj$summary(X_test, y=y_test, show_progress=FALSE, type_ci="bootstrap")
## Warning in wilcox.test.default(x, mu = mu_0): cannot compute exact p-value with
## zeroes
## Warning in wilcox.test.default(x, mu = mu_0): cannot compute exact p-value with
## zeroes
## Warning in wilcox.test.default(x, mu = mu_0): cannot compute exact p-value with
## zeroes
## Warning in wilcox.test.default(x, mu = mu_0): cannot compute exact p-value with
## zeroes
## Warning in wilcox.test.default(x, mu = mu_0): cannot compute exact p-value with
## zeroes
## Warning in wilcox.test.default(x, mu = mu_0): cannot compute exact p-value with
## zeroes
## Warning in wilcox.test.default(x, mu = mu_0): cannot compute exact p-value with
## zeroes
## $R_squared
## [1] 0.2881145
## 
## $R_squared_adj
## [1] 7.406969
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -3.6369  0.3926  2.2088  1.5079  2.8650  5.1631 
## 
## $Coverage_rate
## [1] 100
## 
## $citests
##        estimate      lower    upper       p-value signif
## cyl   0.0000000  0.0000000  0.00000           NaN       
## disp -0.1859971 -0.5579912  0.00000 8.962365e-118    ***
## hp    0.0000000  0.0000000  0.00000           NaN       
## drat 28.9866074  0.0000000 77.95299 5.856765e-149    ***
## wt    0.0000000  0.0000000  0.00000           NaN       
## qsec -1.7295559 -5.1886676  0.00000 9.526227e-117    ***
## vs    0.0000000  0.0000000  0.00000           NaN       
## am    0.0000000  0.0000000  0.00000           NaN       
## gear  0.0000000  0.0000000  0.00000           NaN       
## carb  0.0000000  0.0000000  0.00000           NaN       
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             10     
## Number of columns          10     
## _______________________           
## Column type frequency:            
##   numeric                  10     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable   mean     sd     p0 p25 p50 p75 p100 hist 
##  1 cyl            0      0       0      0   0   0   0  ▁▁▇▁▁
##  2 disp          -0.186  0.588  -1.86   0   0   0   0  ▁▁▁▁▇
##  3 hp             0      0       0      0   0   0   0  ▁▁▇▁▁
##  4 drat          29.0   66.4     0      0   0   0 200. ▇▁▁▁▁
##  5 wt             0      0       0      0   0   0   0  ▁▁▇▁▁
##  6 qsec          -1.73   5.47  -17.3    0   0   0   0  ▁▁▁▁▇
##  7 vs             0      0       0      0   0   0   0  ▁▁▇▁▁
##  8 am             0      0       0      0   0   0   0  ▁▁▇▁▁
##  9 gear           0      0       0      0   0   0   0  ▁▁▇▁▁
## 10 carb           0      0       0      0   0   0   0  ▁▁▇▁▁
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.303 s
t0 <- proc.time()[3]
obj$summary(X_test, y=y_test, show_progress=FALSE, type_ci="conformal")
## Warning in wilcox.test.default(x, mu = mu_0): cannot compute exact p-value with
## zeroes
## Warning in wilcox.test.default(x, mu = mu_0): cannot compute exact p-value with
## zeroes
## Warning in wilcox.test.default(x, mu = mu_0): cannot compute exact p-value with
## zeroes
## Warning in wilcox.test.default(x, mu = mu_0): cannot compute exact p-value with
## zeroes
## Warning in wilcox.test.default(x, mu = mu_0): cannot compute exact p-value with
## zeroes
## Warning in wilcox.test.default(x, mu = mu_0): cannot compute exact p-value with
## zeroes
## Warning in wilcox.test.default(x, mu = mu_0): cannot compute exact p-value with
## zeroes
## Warning in wilcox.test.default(x, mu = mu_0): cannot compute exact p-value with
## zeroes
## $R_squared
## [1] 0.2881145
## 
## $R_squared_adj
## [1] 7.406969
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -3.6369  0.3926  2.2088  1.5079  2.8650  5.1631 
## 
## $Coverage_rate
## [1] 100
## 
## $citests
##        estimate     lower    upper     p-value signif
## cyl   0.0000000  0.000000   0.0000         NaN       
## disp -0.3719941 -1.115982   0.0000 3.09525e-59    ***
## hp    0.0000000  0.000000   0.0000         NaN       
## drat 39.9595601  0.000000 119.8787 2.16282e-59    ***
## wt    0.0000000  0.000000   0.0000         NaN       
## qsec  0.0000000  0.000000   0.0000         NaN       
## vs    0.0000000  0.000000   0.0000         NaN       
## am    0.0000000  0.000000   0.0000         NaN       
## gear  0.0000000  0.000000   0.0000         NaN       
## carb  0.0000000  0.000000   0.0000         NaN       
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             10     
## Number of columns          10     
## _______________________           
## Column type frequency:            
##   numeric                  10     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable   mean     sd     p0 p25 p50 p75 p100 hist 
##  1 cyl            0      0       0      0   0   0   0  ▁▁▇▁▁
##  2 disp          -0.186  0.588  -1.86   0   0   0   0  ▁▁▁▁▇
##  3 hp             0      0       0      0   0   0   0  ▁▁▇▁▁
##  4 drat          29.0   66.4     0      0   0   0 200. ▇▁▁▁▁
##  5 wt             0      0       0      0   0   0   0  ▁▁▇▁▁
##  6 qsec          -1.73   5.47  -17.3    0   0   0   0  ▁▁▁▁▇
##  7 vs             0      0       0      0   0   0   0  ▁▁▇▁▁
##  8 am             0      0       0      0   0   0   0  ▁▁▇▁▁
##  9 gear           0      0       0      0   0   0   0  ▁▁▇▁▁
## 10 carb           0      0       0      0   0   0   0  ▁▁▇▁▁
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.181 s
t0 <- proc.time()[3]
obj$fit(X_train, y_train, nrounds=10, verbose=FALSE)
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.007 s
obj$set_level(95)
res <- obj$predict(X = X_test)

plot(c(y_train, res$preds), type='l',
     main="",
     ylab="",
     ylim = c(min(c(res$upper, res$lower, y)),
              max(c(res$upper, res$lower, y))))
lines(c(y_train, res$upper), col="gray60")
lines(c(y_train, res$lower), col="gray60")
lines(c(y_train, res$preds), col = "red")
lines(c(y_train, y_test), col = "blue")

mean((y_test >= as.numeric(res$lower)) * (y_test <= as.numeric(res$upper)))
## [1] 1
obj$set_pi_method("kdesplitconformal")
t0 <- proc.time()[3]
obj$fit(X_train, y_train, nrounds=10, verbose=FALSE)
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.008 s
obj$set_level(95)
res <- obj$predict(X = X_test)

plot(c(y_train, res$preds), type='l',
     main="",
     ylab="",
     ylim = c(min(c(res$upper, res$lower, y)),
              max(c(res$upper, res$lower, y))))
lines(c(y_train, res$upper), col="gray60")
lines(c(y_train, res$lower), col="gray60")
lines(c(y_train, res$preds), col = "red")
lines(c(y_train, y_test), col = "blue")

mean((y_test >= as.numeric(res$lower)) * (y_test <= as.numeric(res$upper)))
## [1] 1
obj$set_pi_method("bootjackknifeplus")
t0 <- proc.time()[3]
obj$fit(X_train, y_train, nrounds=10, verbose=FALSE)
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0 s
obj$set_level(95)
res <- obj$predict(X = X_test)

plot(c(y_train, res$preds), type='l',
     main="",
     ylab="",
     ylim = c(min(c(res$upper, res$lower, y)),
              max(c(res$upper, res$lower, y))))
lines(c(y_train, res$upper), col="gray60")
lines(c(y_train, res$lower), col="gray60")
lines(c(y_train, res$preds), col = "red")
lines(c(y_train, y_test), col = "blue")

mean((y_test >= as.numeric(res$lower)) * (y_test <= as.numeric(res$upper)))
## [1] 1

4 - RVFL regression

obj <- learningmachine::Regressor$new(method = "rvfl", 
                                      nb_hidden = 50L,
                                      pi_method = "splitconformal")
obj$get_type()
## [1] "regression"
obj$get_name()
## [1] "Regressor"
t0 <- proc.time()[3]
obj$fit(X_train, y_train, reg_lambda = 0.01)
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.004 s
print(obj$predict(X_test))
## $preds
##           Mazda RX4       Mazda RX4 Wag      Hornet 4 Drive             Valiant 
##           21.350888           19.789387           13.106761            9.695310 
##          Merc 450SE          Merc 450SL Lincoln Continental       Toyota Corona 
##           11.131161           12.568682            2.044672           19.289805 
##          Camaro Z28    Pontiac Firebird 
##           14.847878           12.282272 
## 
## $lower
##           Mazda RX4       Mazda RX4 Wag      Hornet 4 Drive             Valiant 
##          12.3508879          10.7893873           4.1067608           0.6953102 
##          Merc 450SE          Merc 450SL Lincoln Continental       Toyota Corona 
##           2.1311611           3.5686817          -6.9553279          10.2898053 
##          Camaro Z28    Pontiac Firebird 
##           5.8478777           3.2822719 
## 
## $upper
##           Mazda RX4       Mazda RX4 Wag      Hornet 4 Drive             Valiant 
##            30.35089            28.78939            22.10676            18.69531 
##          Merc 450SE          Merc 450SL Lincoln Continental       Toyota Corona 
##            20.13116            21.56868            11.04467            28.28981 
##          Camaro Z28    Pontiac Firebird 
##            23.84788            21.28227
t0 <- proc.time()[3]
obj$summary(X_test, y=y_test, show_progress=FALSE)
## $R_squared
## [1] -1.505856
## 
## $R_squared_adj
## [1] 23.55271
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  -1.548   1.461   5.000   4.349   7.949   8.405 
## 
## $Coverage_rate
## [1] 100
## 
## $citests
##         estimate       lower        upper      p-value signif
## cyl   137.649985   39.777048  235.5229227 1.115728e-02      *
## disp   -2.406399   -4.650678   -0.1621204 3.825959e-02      *
## hp     -0.527573   -1.402043    0.3468975 2.054686e-01       
## drat  707.372951  246.095138 1168.6507638 7.059500e-03     **
## wt   -500.429007 -565.047979 -435.8100352 2.910469e-08    ***
## qsec  -89.930939 -124.899691  -54.9621860 2.537870e-04    ***
## vs    234.198406 -127.886990  596.2838006 1.774484e-01       
## am   -235.789718 -512.422513   40.8430776 8.592503e-02      .
## gear   52.646721   -6.640614  111.9340567 7.547657e-02      .
## carb  -17.100561  -87.819649   53.6185270 5.976705e-01       
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             10     
## Number of columns          10     
## _______________________           
## Column type frequency:            
##   numeric                  10     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable     mean     sd      p0      p25      p50       p75     p100
##  1 cyl            138.    137.     -8.40   75.8     91.1     98.6     394.   
##  2 disp            -2.41    3.14   -8.46   -1.32    -1.08    -0.775    -0.300
##  3 hp              -0.528   1.22   -3.40   -0.695   -0.188    0.0137    0.893
##  4 drat           707.    645.     55.7   388.     482.     563.     1939.   
##  5 wt            -500.     90.3  -698.   -538.    -500.    -458.     -377.   
##  6 qsec           -89.9    48.9  -145.   -128.    -102.     -64.0       2.67 
##  7 vs             234.    506.   -121.    -13.2     36.8     53.2    1269.   
##  8 am            -236.    387.   -653.   -450.    -397.    -168.      519.   
##  9 gear            52.6    82.9  -107.     -4.69    66.2    112.      170.   
## 10 carb           -17.1    98.9  -117.    -64.6    -60.6    -17.5     171.   
##    hist 
##  1 ▂▇▁▁▂
##  2 ▂▁▁▁▇
##  3 ▁▁▁▇▂
##  4 ▅▇▁▁▃
##  5 ▂▁▆▇▃
##  6 ▇▆▁▂▃
##  7 ▇▁▁▁▂
##  8 ▆▇▂▁▃
##  9 ▂▅▅▅▇
## 10 ▇▂▁▁▂
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.123 s
t0 <- proc.time()[3]
obj$summary(X_test, y=y_test, show_progress=FALSE, type_ci="bootstrap")
## $R_squared
## [1] -1.505856
## 
## $R_squared_adj
## [1] 23.55271
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  -1.548   1.461   5.000   4.349   7.949   8.405 
## 
## $Coverage_rate
## [1] 100
## 
## $citests
##          estimate       lower         upper       p-value signif
## cyl   137.0111423   69.296022  213.05499150 3.330824e-165    ***
## disp   -2.4063335   -4.151551   -0.85145010 3.330755e-165    ***
## hp     -0.4894821   -1.206580    0.06393166 1.559621e-159    ***
## drat  704.2409575  379.648789 1088.69475280 3.330824e-165    ***
## wt   -499.6464041 -553.621396 -453.75958810 3.330824e-165    ***
## qsec  -89.9155324 -116.434421  -60.70468612 3.330824e-165    ***
## vs    235.1520119  -14.444923  528.12353553 2.876117e-162    ***
## am   -241.1699530 -437.064336   -4.24144263 3.530328e-163    ***
## gear   52.2145847    5.676782   96.67674463 1.907992e-164    ***
## carb  -17.7070158  -67.018662   43.26358463  1.396168e-56    ***
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             10     
## Number of columns          10     
## _______________________           
## Column type frequency:            
##   numeric                  10     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable     mean     sd      p0      p25      p50       p75     p100
##  1 cyl            138.    137.     -8.40   75.8     91.1     98.6     394.   
##  2 disp            -2.41    3.14   -8.46   -1.32    -1.08    -0.775    -0.300
##  3 hp              -0.528   1.22   -3.40   -0.695   -0.188    0.0137    0.893
##  4 drat           707.    645.     55.7   388.     482.     563.     1939.   
##  5 wt            -500.     90.3  -698.   -538.    -500.    -458.     -377.   
##  6 qsec           -89.9    48.9  -145.   -128.    -102.     -64.0       2.67 
##  7 vs             234.    506.   -121.    -13.2     36.8     53.2    1269.   
##  8 am            -236.    387.   -653.   -450.    -397.    -168.      519.   
##  9 gear            52.6    82.9  -107.     -4.69    66.2    112.      170.   
## 10 carb           -17.1    98.9  -117.    -64.6    -60.6    -17.5     171.   
##    hist 
##  1 ▂▇▁▁▂
##  2 ▂▁▁▁▇
##  3 ▁▁▁▇▂
##  4 ▅▇▁▁▃
##  5 ▂▁▆▇▃
##  6 ▇▆▁▂▃
##  7 ▇▁▁▁▂
##  8 ▆▇▂▁▃
##  9 ▂▅▅▅▇
## 10 ▇▂▁▁▂
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.235 s
t0 <- proc.time()[3]
obj$summary(X_test, y=y_test, show_progress=FALSE, type_ci="conformal")
## $R_squared
## [1] -1.505856
## 
## $R_squared_adj
## [1] 23.55271
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  -1.548   1.461   5.000   4.349   7.949   8.405 
## 
## $Coverage_rate
## [1] 100
## 
## $citests
##          estimate       lower         upper      p-value signif
## cyl   150.3445262   88.261264  269.41286765 1.248649e-83    ***
## disp   -2.4328464   -5.421507   -0.81931062 1.249850e-83    ***
## hp     -0.4640731   -1.082605   -0.06685299 1.794965e-83    ***
## drat  662.0105731  262.533030 1325.90195856 1.252851e-83    ***
## wt   -474.1652942 -517.745280 -421.84616624 1.255113e-83    ***
## qsec  -87.0403486 -131.680654  -38.41153592 1.246480e-83    ***
## vs    250.8622825  -48.266736  766.57411839 4.761711e-64    ***
## am   -253.3430623 -539.300395  152.68582253 3.046252e-73    ***
## gear   67.8915285   20.918430  106.80377874 1.252445e-83    ***
## carb  -15.7962310  -70.922940   80.05178042 7.220253e-13    ***
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             10     
## Number of columns          10     
## _______________________           
## Column type frequency:            
##   numeric                  10     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable     mean     sd      p0      p25      p50       p75     p100
##  1 cyl            138.    137.     -8.40   75.8     91.1     98.6     394.   
##  2 disp            -2.41    3.14   -8.46   -1.32    -1.08    -0.775    -0.300
##  3 hp              -0.528   1.22   -3.40   -0.695   -0.188    0.0137    0.893
##  4 drat           707.    645.     55.7   388.     482.     563.     1939.   
##  5 wt            -500.     90.3  -698.   -538.    -500.    -458.     -377.   
##  6 qsec           -89.9    48.9  -145.   -128.    -102.     -64.0       2.67 
##  7 vs             234.    506.   -121.    -13.2     36.8     53.2    1269.   
##  8 am            -236.    387.   -653.   -450.    -397.    -168.      519.   
##  9 gear            52.6    82.9  -107.     -4.69    66.2    112.      170.   
## 10 carb           -17.1    98.9  -117.    -64.6    -60.6    -17.5     171.   
##    hist 
##  1 ▂▇▁▁▂
##  2 ▂▁▁▁▇
##  3 ▁▁▁▇▂
##  4 ▅▇▁▁▃
##  5 ▂▁▆▇▃
##  6 ▇▆▁▂▃
##  7 ▇▁▁▁▂
##  8 ▆▇▂▁▃
##  9 ▂▅▅▅▇
## 10 ▇▂▁▁▂
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.113 s
t0 <- proc.time()[3]
obj$fit(X_train, y_train)
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.003 s
obj$set_level(95)
res <- obj$predict(X = X_test)

plot(c(y_train, res$preds), type='l',
     main="",
     ylab="",
     ylim = c(min(c(res$upper, res$lower, y)),
              max(c(res$upper, res$lower, y))))
lines(c(y_train, res$upper), col="gray60")
lines(c(y_train, res$lower), col="gray60")
lines(c(y_train, res$preds), col = "red")
lines(c(y_train, y_test), col = "blue")
abline(v = length(y_train), lty=2, col="black")

mean((y_test >= as.numeric(res$lower)) * (y_test <= as.numeric(res$upper)))
## [1] 1

update RVFL model

previous_coefs <- drop(obj$model$coef)
newx <- X_test[1, ]
newy <- y_test[1]

new_X_test <- X_test[-1, ]
new_y_test <- y_test[-1]

t0 <- proc.time()[3]
obj$update(newx, newy)
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.003 s
summary(previous_coefs)
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
## -0.68212 -0.26567 -0.05157  0.00700  0.21046  2.19222
summary(drop(obj$model$coef) - previous_coefs)
##      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
## -0.030666 -0.002610  0.004189  0.002917  0.011386  0.025243
plot(drop(obj$model$coef) - previous_coefs, type='l')
abline(h = 0, lty=2, col="red")

start <- proc.time()[3]
obj$summary(new_X_test, y=new_y_test, show_progress=FALSE)
## $R_squared
## [1] -1.809339
## 
## $R_squared_adj
## [1] 12.23735
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  -1.168   2.513   5.541   5.058   8.185   8.703 
## 
## $Coverage_rate
## [1] 100
## 
## $citests
##          estimate       lower        upper      p-value signif
## cyl   111.6701473   17.076928  206.2633669 2.615518e-02      *
## disp   -1.7983224   -3.876380    0.2797349 8.106884e-02      .
## hp     -0.4167545   -1.501658    0.6681495 4.015523e-01       
## drat  569.9102780  148.862037  990.9585186 1.420088e-02      *
## wt   -504.1496696 -583.757006 -424.5423330 4.741273e-07    ***
## qsec -107.9102921 -138.571336  -77.2492482 3.936777e-05    ***
## vs    145.0280002 -173.164419  463.2204193 3.239468e-01       
## am   -319.6910568 -566.618653  -72.7634604 1.745263e-02      *
## gear   57.7630332  -18.934712  134.4607782 1.206459e-01       
## carb  -42.9572292 -108.690903   22.7764447 1.702409e-01       
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             9      
## Number of columns          10     
## _______________________           
## Column type frequency:            
##   numeric                  10     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable     mean     sd      p0      p25       p50       p75     p100
##  1 cyl            112.    123.    -13.5    64.5     93.6      93.9     426.   
##  2 disp            -1.80    2.70   -8.94   -1.41    -0.805    -0.689    -0.361
##  3 hp              -0.417   1.41   -3.54   -0.679   -0.0942   -0.0556    1.19 
##  4 drat           570.    548.     36.8   371.     439.      501.     1972.   
##  5 wt            -504.    104.   -742.   -523.    -497.     -461.     -382.   
##  6 qsec          -108.     39.9  -152.   -143.    -115.      -93.0     -35.9  
##  7 vs             145.    414.   -116.    -23.9     51.1      81.2    1231.   
##  8 am            -320.    321.   -575.   -479.    -395.     -368.      465.   
##  9 gear            57.8    99.8  -113.      1.22    35.2     130.      196.   
## 10 carb           -43.0    85.5  -129.    -79.6    -77.9     -22.5     165.   
##    hist 
##  1 ▅▇▁▁▂
##  2 ▁▁▁▁▇
##  3 ▂▁▂▇▃
##  4 ▅▇▁▁▂
##  5 ▂▁▂▇▃
##  6 ▇▅▅▂▂
##  7 ▇▁▁▁▁
##  8 ▇▁▁▁▁
##  9 ▃▇▇▇▇
## 10 ▇▅▁▁▂
cat("Elapsed: ", proc.time()[3] - start, "s \n")
## Elapsed:  0.127 s
start <- proc.time()[3]
obj$summary(new_X_test, y=new_y_test, show_progress=FALSE, type_ci="bootstrap")
## $R_squared
## [1] -1.809339
## 
## $R_squared_adj
## [1] 12.23735
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  -1.168   2.513   5.541   5.058   8.185   8.703 
## 
## $Coverage_rate
## [1] 100
## 
## $citests
##          estimate       lower      upper       p-value signif
## cyl   112.3919404   55.200080  198.90428 3.330730e-165    ***
## disp   -1.7848239   -3.647352   -0.74150 3.330730e-165    ***
## hp     -0.3674135   -1.299011    0.34313 3.063436e-110    ***
## drat  565.9832345  325.398523  950.32059 3.330730e-165    ***
## wt   -504.3143079 -572.073593 -451.85782 3.330730e-165    ***
## qsec -107.9791731 -129.437921  -82.20922 3.330730e-165    ***
## vs    144.4399640  -32.248151  427.63924 2.565958e-145    ***
## am   -324.5343769 -475.286679 -100.58739 3.688681e-165    ***
## gear   57.8310159   -1.595434  116.61761 2.545767e-162    ***
## carb  -42.8382811  -84.631850   12.61998 4.603546e-153    ***
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             9      
## Number of columns          10     
## _______________________           
## Column type frequency:            
##   numeric                  10     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable     mean     sd      p0      p25       p50       p75     p100
##  1 cyl            112.    123.    -13.5    64.5     93.6      93.9     426.   
##  2 disp            -1.80    2.70   -8.94   -1.41    -0.805    -0.689    -0.361
##  3 hp              -0.417   1.41   -3.54   -0.679   -0.0942   -0.0556    1.19 
##  4 drat           570.    548.     36.8   371.     439.      501.     1972.   
##  5 wt            -504.    104.   -742.   -523.    -497.     -461.     -382.   
##  6 qsec          -108.     39.9  -152.   -143.    -115.      -93.0     -35.9  
##  7 vs             145.    414.   -116.    -23.9     51.1      81.2    1231.   
##  8 am            -320.    321.   -575.   -479.    -395.     -368.      465.   
##  9 gear            57.8    99.8  -113.      1.22    35.2     130.      196.   
## 10 carb           -43.0    85.5  -129.    -79.6    -77.9     -22.5     165.   
##    hist 
##  1 ▅▇▁▁▂
##  2 ▁▁▁▁▇
##  3 ▂▁▂▇▃
##  4 ▅▇▁▁▂
##  5 ▂▁▂▇▃
##  6 ▇▅▅▂▂
##  7 ▇▁▁▁▁
##  8 ▇▁▁▁▁
##  9 ▃▇▇▇▇
## 10 ▇▅▁▁▂
cat("Elapsed: ", proc.time()[3] - start, "s \n")
## Elapsed:  0.234 s
start <- proc.time()[3]
obj$summary(new_X_test, y=new_y_test, show_progress=FALSE, type_ci="conformal")
## $R_squared
## [1] -1.809339
## 
## $R_squared_adj
## [1] 12.23735
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  -1.168   2.513   5.541   5.058   8.185   8.703 
## 
## $Coverage_rate
## [1] 100
## 
## $citests
##         estimate       lower        upper      p-value signif
## cyl   140.206405   31.603822  293.1593917 1.250495e-83    ***
## disp   -2.350759   -5.684574   -0.5579624 1.246806e-83    ***
## hp     -1.063336   -2.384855   -0.2331024 1.246643e-83    ***
## drat  664.475986  223.820350 1304.6007257 1.251103e-83    ***
## wt   -497.028711 -612.525811 -408.8952369 1.252549e-83    ***
## qsec -102.835585 -141.642304  -62.5335162 1.250340e-83    ***
## vs    301.065907   64.994420  770.3673395 1.170730e-83    ***
## am   -223.403879 -467.258502  171.5791962 8.896529e-68    ***
## gear  107.408867   52.086950  163.9796862 1.250275e-83    ***
## carb  -40.474522 -108.737967   67.5130388 4.138039e-49    ***
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             9      
## Number of columns          10     
## _______________________           
## Column type frequency:            
##   numeric                  10     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable     mean     sd      p0      p25       p50       p75     p100
##  1 cyl            112.    123.    -13.5    64.5     93.6      93.9     426.   
##  2 disp            -1.80    2.70   -8.94   -1.41    -0.805    -0.689    -0.361
##  3 hp              -0.417   1.41   -3.54   -0.679   -0.0942   -0.0556    1.19 
##  4 drat           570.    548.     36.8   371.     439.      501.     1972.   
##  5 wt            -504.    104.   -742.   -523.    -497.     -461.     -382.   
##  6 qsec          -108.     39.9  -152.   -143.    -115.      -93.0     -35.9  
##  7 vs             145.    414.   -116.    -23.9     51.1      81.2    1231.   
##  8 am            -320.    321.   -575.   -479.    -395.     -368.      465.   
##  9 gear            57.8    99.8  -113.      1.22    35.2     130.      196.   
## 10 carb           -43.0    85.5  -129.    -79.6    -77.9     -22.5     165.   
##    hist 
##  1 ▅▇▁▁▂
##  2 ▁▁▁▁▇
##  3 ▂▁▂▇▃
##  4 ▅▇▁▁▂
##  5 ▂▁▂▇▃
##  6 ▇▅▅▂▂
##  7 ▇▁▁▁▁
##  8 ▇▁▁▁▁
##  9 ▃▇▇▇▇
## 10 ▇▅▁▁▂
cat("Elapsed: ", proc.time()[3] - start, "s \n")
## Elapsed:  0.11 s
res <- obj$predict(X = new_X_test)
 
new_y_train <- c(y_train, newy)

plot(c(new_y_train, res$preds), type='l',
    main="",
    ylab="",
    ylim = c(min(c(res$upper, res$lower, y)),
             max(c(res$upper, res$lower, y))))
lines(c(new_y_train, res$upper), col="gray60")
lines(c(new_y_train, res$lower), col="gray60")
lines(c(new_y_train, res$preds), col = "red")
lines(c(new_y_train, new_y_test), col = "blue")
abline(v = length(y_train), lty=2, col="black")

mean((new_y_test >= as.numeric(res$lower)) * (new_y_test <= as.numeric(res$upper)))
## [1] 1

update RVFL model (Pt.2)

newx <- X_test[2, ]
newy <- y_test[2]

new_X_test <- X_test[-c(1, 2), ]
new_y_test <- y_test[-c(1, 2)]
t0 <- proc.time()[3]
obj$update(newx, newy)
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.002 s
t0 <- proc.time()[3]
obj$summary(new_X_test, y=new_y_test, show_progress=FALSE)
## $R_squared
## [1] -3.356623
## 
## $R_squared_adj
## [1] 11.16545
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  -1.950   5.030   6.374   6.369   8.774  11.528 
## 
## $Coverage_rate
## [1] 75
## 
## $citests
##          estimate       lower        upper      p-value signif
## cyl    40.8981137    6.878148   74.9180798 2.494779e-02      *
## disp   -0.7335494   -1.206939   -0.2601595 8.026181e-03     **
## hp     -0.8233606   -2.198927    0.5522055 1.998737e-01       
## drat  549.7206897  416.053783  683.3875968 2.570765e-05    ***
## wt   -469.9351032 -535.877454 -403.9927527 6.344763e-07    ***
## qsec -116.6183871 -156.767393  -76.4693814 2.380078e-04    ***
## vs   -194.4213942 -288.046178 -100.7966103 1.732503e-03     **
## am   -395.7216847 -562.762331 -228.6810387 8.143911e-04    ***
## gear   53.0732573  -59.833653  165.9801679 3.030574e-01       
## carb  -25.9448064  -63.759959   11.8703467 1.487567e-01       
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             8      
## Number of columns          10     
## _______________________           
## Column type frequency:            
##   numeric                  10     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable     mean      sd      p0     p25      p50      p75     p100
##  1 cyl             40.9    40.7    -40.5    23.9    56.3     69.9     77.8  
##  2 disp            -0.734   0.566   -1.64   -1.03   -0.571   -0.372   -0.139
##  3 hp              -0.823   1.65    -3.99   -1.18   -0.974   -0.196    1.25 
##  4 drat           550.    160.     170.    549.    606.     642.     643.   
##  5 wt            -470.     78.9   -543.   -537.   -489.    -437.    -336.   
##  6 qsec          -117.     48.0   -179.   -143.   -131.     -99.1    -29.9  
##  7 vs            -194.    112.    -377.   -283.   -162.    -120.     -46.3  
##  8 am            -396.    200.    -719.   -481.   -357.    -319.     -67.7  
##  9 gear            53.1   135.    -143.    -23.9    16.5    172.     231.   
## 10 carb           -25.9    45.2   -101.    -48.8   -23.8     -9.36    45.7  
##    hist 
##  1 ▂▂▂▁▇
##  2 ▅▁▂▇▅
##  3 ▂▁▇▂▃
##  4 ▁▁▁▁▇
##  5 ▇▅▂▁▅
##  6 ▂▇▂▂▂
##  7 ▂▅▂▇▂
##  8 ▃▁▇▂▂
##  9 ▂▅▅▁▇
## 10 ▂▅▇▁▅
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.1 s
t0 <- proc.time()[3]
obj$summary(new_X_test, y=new_y_test, show_progress=FALSE, type_ci="bootstrap")
## $R_squared
## [1] -3.356623
## 
## $R_squared_adj
## [1] 11.16545
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  -1.950   5.030   6.374   6.369   8.774  11.528 
## 
## $Coverage_rate
## [1] 75
## 
## $citests
##          estimate       lower        upper       p-value signif
## cyl    41.4258367   12.588077   65.2679002 4.350539e-165    ***
## disp   -0.7222008   -1.115485   -0.4125830 3.330513e-165    ***
## hp     -0.8065083   -1.909190    0.1497299 1.786493e-158    ***
## drat  558.7650921  437.296154  627.3085008 3.330513e-165    ***
## wt   -472.0764594 -515.956910 -418.1652602 3.330513e-165    ***
## qsec -118.3772945 -145.482273  -83.8895245 3.330513e-165    ***
## vs   -193.6445785 -265.087370 -124.5273605 3.329761e-165    ***
## am   -388.8129686 -519.250653 -272.5465744 3.330513e-165    ***
## gear   51.8672891  -32.695264  137.3143094 4.222165e-136    ***
## carb  -25.7347296  -54.019221    2.3478991 1.826091e-161    ***
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             8      
## Number of columns          10     
## _______________________           
## Column type frequency:            
##   numeric                  10     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable     mean      sd      p0     p25      p50      p75     p100
##  1 cyl             40.9    40.7    -40.5    23.9    56.3     69.9     77.8  
##  2 disp            -0.734   0.566   -1.64   -1.03   -0.571   -0.372   -0.139
##  3 hp              -0.823   1.65    -3.99   -1.18   -0.974   -0.196    1.25 
##  4 drat           550.    160.     170.    549.    606.     642.     643.   
##  5 wt            -470.     78.9   -543.   -537.   -489.    -437.    -336.   
##  6 qsec          -117.     48.0   -179.   -143.   -131.     -99.1    -29.9  
##  7 vs            -194.    112.    -377.   -283.   -162.    -120.     -46.3  
##  8 am            -396.    200.    -719.   -481.   -357.    -319.     -67.7  
##  9 gear            53.1   135.    -143.    -23.9    16.5    172.     231.   
## 10 carb           -25.9    45.2   -101.    -48.8   -23.8     -9.36    45.7  
##    hist 
##  1 ▂▂▂▁▇
##  2 ▅▁▂▇▅
##  3 ▂▁▇▂▃
##  4 ▁▁▁▁▇
##  5 ▇▅▂▁▅
##  6 ▂▇▂▂▂
##  7 ▂▅▂▇▂
##  8 ▃▁▇▂▂
##  9 ▂▅▅▁▇
## 10 ▂▅▇▁▅
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.228 s
t0 <- proc.time()[3]
obj$summary(new_X_test, y=new_y_test, show_progress=FALSE, type_ci="conformal")
## $R_squared
## [1] -3.356623
## 
## $R_squared_adj
## [1] 11.16545
## 
## $Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  -1.950   5.030   6.374   6.369   8.774  11.528 
## 
## $Coverage_rate
## [1] 75
## 
## $citests
##          estimate       lower        upper      p-value signif
## cyl    58.2449258   39.674124   73.4093157 1.110860e-83    ***
## disp   -0.7298717   -1.364532   -0.2545631 1.136036e-83    ***
## hp     -0.3864945   -1.054373    0.6831616 3.352809e-48    ***
## drat  597.4424346  554.087929  640.7969406 1.131334e-83    ***
## wt   -506.1389175 -537.214571 -475.0632642 1.118220e-83    ***
## qsec -132.3622867 -143.160353 -118.9186944 1.094728e-83    ***
## vs   -222.6300825 -283.532484 -160.6471851 1.142960e-83    ***
## am   -360.1349715 -411.143585 -309.3340192 1.145999e-83    ***
## gear    3.3479327  -77.909561  114.9982065 4.143707e-04    ***
## carb  -17.1193947  -34.343046    8.3335623 1.780062e-74    ***
## 
## $signif_codes
## [1] "Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
## 
## $effects
## ── Data Summary ────────────────────────
##                            Values 
## Name                       effects
## Number of rows             8      
## Number of columns          10     
## _______________________           
## Column type frequency:            
##   numeric                  10     
## ________________________          
## Group variables            None   
## 
## ── Variable type: numeric ──────────────────────────────────────────────────────
##    skim_variable     mean      sd      p0     p25      p50      p75     p100
##  1 cyl             40.9    40.7    -40.5    23.9    56.3     69.9     77.8  
##  2 disp            -0.734   0.566   -1.64   -1.03   -0.571   -0.372   -0.139
##  3 hp              -0.823   1.65    -3.99   -1.18   -0.974   -0.196    1.25 
##  4 drat           550.    160.     170.    549.    606.     642.     643.   
##  5 wt            -470.     78.9   -543.   -537.   -489.    -437.    -336.   
##  6 qsec          -117.     48.0   -179.   -143.   -131.     -99.1    -29.9  
##  7 vs            -194.    112.    -377.   -283.   -162.    -120.     -46.3  
##  8 am            -396.    200.    -719.   -481.   -357.    -319.     -67.7  
##  9 gear            53.1   135.    -143.    -23.9    16.5    172.     231.   
## 10 carb           -25.9    45.2   -101.    -48.8   -23.8     -9.36    45.7  
##    hist 
##  1 ▂▂▂▁▇
##  2 ▅▁▂▇▅
##  3 ▂▁▇▂▃
##  4 ▁▁▁▁▇
##  5 ▇▅▂▁▅
##  6 ▂▇▂▂▂
##  7 ▂▅▂▇▂
##  8 ▃▁▇▂▂
##  9 ▂▅▅▁▇
## 10 ▂▅▇▁▅
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
## Elapsed:  0.112 s
res <- obj$predict(X = new_X_test)
 
new_y_train <- c(y_train, y_test[c(1, 2)])

plot(c(new_y_train, res$preds), type='l',
    main="",
    ylab="",
    ylim = c(min(c(res$upper, res$lower, y)),
             max(c(res$upper, res$lower, y))))
lines(c(new_y_train, res$upper), col="gray60")
lines(c(new_y_train, res$lower), col="gray60")
lines(c(new_y_train, res$preds), col = "red")
lines(c(new_y_train, new_y_test), col = "blue")
abline(v = length(y_train), lty=2, col="black")

mean((new_y_test >= as.numeric(res$lower)) * (new_y_test <= as.numeric(res$upper)))
## [1] 0.75