My_predict: Use the model generated by "LogReg" to predict new test data

Description Usage Arguments Value Examples

View source: R/My_predict.R

Description

Use the model generated by "LogReg" to predict new test data

Usage

1
My_predict(fit, newx)

Arguments

fit

the model generated by "LogReg".

newx

input matrix, of dimension n (sample number) by p (variable number); each row is an observation vector.

Value

the prediction for every row of test data newx. And the label will be the same as that of training data.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
### install and library package
#devtools::install_github("hobbitish1028/Logistic")
library(Logistic)

### Generate training data
sigma<-4
set.seed(123)
n<-1e4
p<-1e2
mu1<-rnorm(p)
mu2<-rnorm(p)
X1<-matrix(mu1+rnorm(n*p,0,sigma),n,p,byrow = TRUE)
X2<-matrix(mu2+rnorm(n*p,0,sigma),n,p,byrow = TRUE)

### Train data
X<-rbind(X1,X2)
y<-rep(c(1,0),each=n)


### Test data
test_x<-rbind( matrix(mu1+rnorm(n*p,0,sigma),n,p,byrow = TRUE), 
              matrix(mu2+rnorm(n*p,0,sigma),n,p,byrow = TRUE)  )
test_y<-rep(c(1,0),each=n)

### Fit model
fit<-Logreg(X,y)

### Make prediction on test data
pred0<-My_predict(fit,newx = test_x)

hobbitish1028/Logistic documentation built on Nov. 26, 2019, 8:58 a.m.