Generates prediction for logistic regression. Note that one can either input a 'logisticr' object or a matrix of beta coefficients.

# S3 method for logisticr
predict(object, X, y = NULL, ...)

Arguments

object

'logisticr' object or matrix of betas

X

matrix or data frame of (new) observations

y

optional, matrix or vector of response values 0,1

...

additional arguments

Value

predictions and loss metrics

Examples

library(dplyr) X = dplyr::select(iris, -Species) y = dplyr::select(iris, Species) y$Species = ifelse(y$Species == 'setosa', 1, 0) logisticr(X, y)
#> #> Call: logisticr(X = X, y = y) #> #> Iterations: #> [1] 18 #> #> Tuning parameters: #> lam alpha #> [1,] NaN NaN #> #> MSE: #> [1] 7.707778e-14 #> #> logloss: #> [1] 6.64746e-06 #> #> misclassification: #> [1] 0 #> #> Coefficients: #> [,1] #> intercept -12.11317 #> 6.99937 #> 6.01011 #> -12.38368 #> -13.25003
fitted = logisticr(X, y, lam = 0.1, penalty = 'ridge', method = 'MM') predict(fitted, X)
#> $fitted.values #> [,1] #> [1,] 9.979380e-01 #> [2,] 9.958168e-01 #> [3,] 9.980736e-01 #> [4,] 9.956320e-01 #> [5,] 9.983305e-01 #> [6,] 9.950147e-01 #> [7,] 9.977821e-01 #> [8,] 9.967161e-01 #> [9,] 9.961641e-01 #> [10,] 9.956784e-01 #> [11,] 9.975318e-01 #> [12,] 9.957662e-01 #> [13,] 9.966058e-01 #> [14,] 9.990841e-01 #> [15,] 9.993589e-01 #> [16,] 9.987270e-01 #> [17,] 9.987881e-01 #> [18,] 9.975810e-01 #> [19,] 9.942065e-01 #> [20,] 9.978771e-01 #> [21,] 9.918963e-01 #> [22,] 9.970735e-01 #> [23,] 9.996682e-01 #> [24,] 9.868058e-01 #> [25,] 9.878336e-01 #> [26,] 9.911080e-01 #> [27,] 9.935732e-01 #> [28,] 9.969137e-01 #> [29,] 9.974533e-01 #> [30,] 9.944400e-01 #> [31,] 9.931389e-01 #> [32,] 9.944935e-01 #> [33,] 9.990018e-01 #> [34,] 9.991883e-01 #> [35,] 9.949322e-01 #> [36,] 9.984305e-01 #> [37,] 9.982343e-01 #> [38,] 9.986460e-01 #> [39,] 9.977076e-01 #> [40,] 9.965491e-01 #> [41,] 9.983841e-01 #> [42,] 9.912802e-01 #> [43,] 9.983403e-01 #> [44,] 9.924795e-01 #> [45,] 9.897958e-01 #> [46,] 9.953314e-01 #> [47,] 9.974225e-01 #> [48,] 9.973890e-01 #> [49,] 9.976513e-01 #> [50,] 9.972901e-01 #> [51,] 1.406893e-04 #> [52,] 3.283189e-04 #> [53,] 5.274717e-05 #> [54,] 9.703731e-04 #> [55,] 1.147410e-04 #> [56,] 3.353494e-04 #> [57,] 1.701406e-04 #> [58,] 2.889798e-02 #> [59,] 1.767472e-04 #> [60,] 2.609878e-03 #> [61,] 7.241129e-03 #> [62,] 8.820357e-04 #> [63,] 1.040100e-03 #> [64,] 1.355076e-04 #> [65,] 9.974813e-03 #> [66,] 4.023688e-04 #> [67,] 3.537073e-04 #> [68,] 1.808654e-03 #> [69,] 7.193084e-05 #> [70,] 2.501355e-03 #> [71,] 8.996024e-05 #> [72,] 1.615623e-03 #> [73,] 2.693127e-05 #> [74,] 1.587390e-04 #> [75,] 5.653528e-04 #> [76,] 3.597360e-04 #> [77,] 5.707762e-05 #> [78,] 2.524603e-05 #> [79,] 2.465854e-04 #> [80,] 1.341034e-02 #> [81,] 3.185580e-03 #> [82,] 5.317770e-03 #> [83,] 2.666370e-03 #> [84,] 1.812181e-05 #> [85,] 3.907093e-04 #> [86,] 4.717670e-04 #> [87,] 1.183959e-04 #> [88,] 1.579460e-04 #> [89,] 2.008200e-03 #> [90,] 1.340668e-03 #> [91,] 4.483339e-04 #> [92,] 2.270731e-04 #> [93,] 1.592743e-03 #> [94,] 2.351704e-02 #> [95,] 8.679953e-04 #> [96,] 1.573671e-03 #> [97,] 1.141115e-03 #> [98,] 6.244815e-04 #> [99,] 7.250525e-02 #> [100,] 1.383319e-03 #> [101,] 4.015710e-07 #> [102,] 1.238589e-05 #> [103,] 4.487640e-07 #> [104,] 2.661100e-06 #> [105,] 7.347915e-07 #> [106,] 2.925253e-08 #> [107,] 1.620528e-04 #> [108,] 1.352518e-07 #> [109,] 5.618021e-07 #> [110,] 2.924772e-07 #> [111,] 1.672989e-05 #> [112,] 4.521819e-06 #> [113,] 2.151474e-06 #> [114,] 1.144105e-05 #> [115,] 6.541792e-06 #> [116,] 5.353872e-06 #> [117,] 4.037167e-06 #> [118,] 6.070909e-08 #> [119,] 3.652173e-09 #> [120,] 1.349944e-05 #> [121,] 1.010940e-06 #> [122,] 2.785204e-05 #> [123,] 1.657822e-08 #> [124,] 2.303028e-05 #> [125,] 1.808108e-06 #> [126,] 6.690851e-07 #> [127,] 4.056452e-05 #> [128,] 4.133637e-05 #> [129,] 1.332522e-06 #> [130,] 1.354813e-06 #> [131,] 1.895386e-07 #> [132,] 2.192502e-07 #> [133,] 1.135464e-06 #> [134,] 2.153448e-05 #> [135,] 3.431428e-06 #> [136,] 1.189595e-07 #> [137,] 2.287782e-06 #> [138,] 4.988396e-06 #> [139,] 6.193075e-05 #> [140,] 3.430557e-06 #> [141,] 1.153847e-06 #> [142,] 7.215581e-06 #> [143,] 1.238589e-05 #> [144,] 5.228754e-07 #> [145,] 9.532810e-07 #> [146,] 4.756158e-06 #> [147,] 9.960712e-06 #> [148,] 8.491475e-06 #> [149,] 5.734123e-06 #> [150,] 2.247119e-05 #> #> $class #> [,1] #> [1,] 1 #> [2,] 1 #> [3,] 1 #> [4,] 1 #> [5,] 1 #> [6,] 1 #> [7,] 1 #> [8,] 1 #> [9,] 1 #> [10,] 1 #> [11,] 1 #> [12,] 1 #> [13,] 1 #> [14,] 1 #> [15,] 1 #> [16,] 1 #> [17,] 1 #> [18,] 1 #> [19,] 1 #> [20,] 1 #> [21,] 1 #> [22,] 1 #> [23,] 1 #> [24,] 1 #> [25,] 1 #> [26,] 1 #> [27,] 1 #> [28,] 1 #> [29,] 1 #> [30,] 1 #> [31,] 1 #> [32,] 1 #> [33,] 1 #> [34,] 1 #> [35,] 1 #> [36,] 1 #> [37,] 1 #> [38,] 1 #> [39,] 1 #> [40,] 1 #> [41,] 1 #> [42,] 1 #> [43,] 1 #> [44,] 1 #> [45,] 1 #> [46,] 1 #> [47,] 1 #> [48,] 1 #> [49,] 1 #> [50,] 1 #> [51,] 0 #> [52,] 0 #> [53,] 0 #> [54,] 0 #> [55,] 0 #> [56,] 0 #> [57,] 0 #> [58,] 0 #> [59,] 0 #> [60,] 0 #> [61,] 0 #> [62,] 0 #> [63,] 0 #> [64,] 0 #> [65,] 0 #> [66,] 0 #> [67,] 0 #> [68,] 0 #> [69,] 0 #> [70,] 0 #> [71,] 0 #> [72,] 0 #> [73,] 0 #> [74,] 0 #> [75,] 0 #> [76,] 0 #> [77,] 0 #> [78,] 0 #> [79,] 0 #> [80,] 0 #> [81,] 0 #> [82,] 0 #> [83,] 0 #> [84,] 0 #> [85,] 0 #> [86,] 0 #> [87,] 0 #> [88,] 0 #> [89,] 0 #> [90,] 0 #> [91,] 0 #> [92,] 0 #> [93,] 0 #> [94,] 0 #> [95,] 0 #> [96,] 0 #> [97,] 0 #> [98,] 0 #> [99,] 0 #> [100,] 0 #> [101,] 0 #> [102,] 0 #> [103,] 0 #> [104,] 0 #> [105,] 0 #> [106,] 0 #> [107,] 0 #> [108,] 0 #> [109,] 0 #> [110,] 0 #> [111,] 0 #> [112,] 0 #> [113,] 0 #> [114,] 0 #> [115,] 0 #> [116,] 0 #> [117,] 0 #> [118,] 0 #> [119,] 0 #> [120,] 0 #> [121,] 0 #> [122,] 0 #> [123,] 0 #> [124,] 0 #> [125,] 0 #> [126,] 0 #> [127,] 0 #> [128,] 0 #> [129,] 0 #> [130,] 0 #> [131,] 0 #> [132,] 0 #> [133,] 0 #> [134,] 0 #> [135,] 0 #> [136,] 0 #> [137,] 0 #> [138,] 0 #> [139,] 0 #> [140,] 0 #> [141,] 0 #> [142,] 0 #> [143,] 0 #> [144,] 0 #> [145,] 0 #> [146,] 0 #> [147,] 0 #> [148,] 0 #> [149,] 0 #> [150,] 0 #> #> $MSE #> NULL #> #> $log.loss #> NULL #> #> $misclassification #> NULL #>