predict.sparseSVM: Model predictions based on "sparseSVM" object.

Description Usage Arguments Value Author(s) See Also Examples

View source: R/predict.sparseSVM.R

Description

This function returns fitted values, coefficients and more from a fitted "sparseSVM" object.

Usage

1
2
3
4
5
## S3 method for class 'sparseSVM'
predict(object, X, lambda, type = c("class","coefficients","nvars"), 
    exact = FALSE, ...)
## S3 method for class 'sparseSVM'
coef(object, lambda, exact = FALSE, ...)

Arguments

object

Fitted "sparseSVM" model object.

X

Matrix of values at which predictions are to be made. Used only for type = "class".

lambda

Values of the regularization parameter lambda at which predictions are requested. Default is the entire sequence used to create the model.

type

Type of prediction. "class" returns the class labels; "coefficients" returns the coefficients; "nvars" returns the number of nonzero coefficients at each value of lambda.

exact

If exact=FALSE (default), then the function uses linear interpolation to make predictions for values of lambda that do not coincide with those used to fit the model. If exact=TRUE, and predictions are requested at values of lambda not included in the original fit, the model is refit on a lambda sequence consisting object$lambda and the new ones before predictions are made.

...

Not used. Other arguments to predict.

Value

The object returned depends on type.

Author(s)

Congrui Yi and Yaohui Zeng
Maintainer: Congrui Yi <eric.ycr@gmail.com>

See Also

sparseSVM

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
X = matrix(rnorm(1000*100), 1000, 100)
b = 3
w = 5*rnorm(10)
eps = rnorm(1000)
y = sign(b + drop(X[,1:10] %*% w + eps))

fit = sparseSVM(X, y)
predict(fit, X[1:5,], lambda = c(0.05, 0.03))
predict(fit, X[1:5,], lambda = 0.05, exact = TRUE)
predict(fit, type = "nvars")
coef(fit, lambda = 0.05)

Example output

     0.05 0.03
[1,]    1    1
[2,]   -1    1
[3,]    1    1
[4,]   -1   -1
[5,]   -1   -1
     [,1]
[1,]    1
[2,]   -1
[3,]    1
[4,]   -1
[5,]   -1
0.3503 0.3344 0.3192 0.3047 0.2908 0.2776  0.265  0.253 0.2415 0.2305   0.22 
     0      2      2      2      3      3      3      4      4      4      4 
  0.21 0.2005 0.1914 0.1827 0.1744 0.1664 0.1589 0.1516 0.1447 0.1382 0.1319 
     5      5      5      5      5      6      6      7      7      7      7 
0.1259 0.1202 0.1147 0.1095 0.1045 0.0998 0.0952 0.0909 0.0868 0.0828 0.0791 
     7      8      8      9      9      9      9      9      9      9      9 
0.0755  0.072 0.0688 0.0656 0.0627 0.0598 0.0571 0.0545  0.052 0.0497 0.0474 
     9      9     10     10     10     10     10     11     11     13     15 
0.0452 0.0432 0.0412 0.0394 0.0376 0.0359 0.0342 0.0327 0.0312 0.0298 0.0284 
    17     17     17     19     21     26     27     29     32     33     34 
0.0271 0.0259 0.0247 0.0236 0.0225 0.0215 0.0205 0.0196 0.0187 0.0178  0.017 
    36     38     42     43     46     48     51     52     52     53     55 
0.0163 0.0155 0.0148 0.0141 0.0135 0.0129 0.0123 0.0117 0.0112 0.0107 0.0102 
    59     61     61     61     65     66     67     68     70     73     75 
0.0097 0.0093 0.0089 0.0085 0.0081 0.0077 0.0074  0.007 0.0067 0.0064 0.0061 
    76     77     77     78     78     78     79     80     81     81     81 
0.0058 0.0056 0.0053 0.0051 0.0049 0.0046 0.0044 0.0042  0.004 0.0038 0.0037 
    81     81     83     85     85     85     86     87     87     87     87 
0.0035 
    88 
 (Intercept)           V1           V2           V3           V4           V5 
 0.111931335  0.294667182  0.582066386  0.200321077 -0.619544736  0.874032594 
          V6           V7           V8           V9          V10          V11 
-0.672054389  0.000000000  0.593167141  0.258387518  0.369085210  0.000000000 
         V12          V13          V14          V15          V16          V17 
 0.000000000  0.000000000  0.000000000  0.000000000 -0.006148207  0.000000000 
         V18          V19          V20          V21          V22          V23 
 0.000000000  0.000000000  0.000000000  0.000000000  0.000000000  0.000000000 
         V24          V25          V26          V27          V28          V29 
 0.000000000  0.000000000  0.000000000  0.000000000  0.003966542  0.000000000 
         V30          V31          V32          V33          V34          V35 
 0.000000000  0.000000000  0.000000000  0.000000000  0.000000000  0.000000000 
         V36          V37          V38          V39          V40          V41 
 0.000000000  0.000000000  0.000000000  0.000000000  0.000000000  0.000000000 
         V42          V43          V44          V45          V46          V47 
 0.000000000  0.000000000  0.000000000  0.000000000  0.000000000  0.000000000 
         V48          V49          V50          V51          V52          V53 
-0.016306338  0.000000000  0.000000000  0.000000000  0.000000000  0.000000000 
         V54          V55          V56          V57          V58          V59 
 0.000000000  0.000000000  0.000000000  0.000000000  0.000000000  0.000000000 
         V60          V61          V62          V63          V64          V65 
 0.000000000  0.000000000  0.000000000  0.000000000  0.000000000  0.000000000 
         V66          V67          V68          V69          V70          V71 
 0.000000000  0.000000000  0.000000000  0.000000000  0.000000000  0.000000000 
         V72          V73          V74          V75          V76          V77 
 0.000000000  0.000000000  0.000000000  0.000000000  0.000000000  0.000000000 
         V78          V79          V80          V81          V82          V83 
 0.000000000  0.000000000  0.000000000  0.000000000  0.000000000  0.000000000 
         V84          V85          V86          V87          V88          V89 
 0.000000000  0.059730410  0.000000000  0.000000000  0.000000000  0.000000000 
         V90          V91          V92          V93          V94          V95 
 0.000000000  0.000000000  0.000000000  0.000000000  0.000000000  0.000000000 
         V96          V97          V98          V99         V100 
 0.000000000  0.000000000  0.000000000  0.000000000  0.000000000 

sparseSVM documentation built on May 2, 2019, 11:02 a.m.