pred | R Documentation |
Wrapper on learning algoritmhs
pred(algo = "svm", X, Y, X.ts, classi = TRUE, to.scale = FALSE, ...)
algo: |
learning algoritmh: |
X: |
training input |
Y: |
training output |
X.ts: |
test input |
classi: |
TRUE for classification, FALSE for regression |
...: |
parameters of the learning algoritmh from the original package |
The sklearn predictors require the installation of reticulate and the scikit-learn package
if classi=FALSE
predicted test output; if classi=TRUE
a list with
pred
: predicted class
prob
: posteriori probability
Gianluca Bontempi gbonte@ulb.ac.be
## regression example
library(randomForest)
n=4
N=1000
X=array(rnorm(N*n),c(N,n))
Y=X[,1]*X[,2]+rnorm(N,sd=0.1)
Itr=sample(N,round(N/2))
Its=setdiff(1:N,Itr)
Xtr=X[Itr,]
Ytr=Y[Itr]
Xts=X[Its,]
Yts=Y[Its]
Yhat=pred("rf",Xtr,Ytr,Xts,ntree=1000, classi=FALSE)
e=Yts-Yhat
## normalized mean squared error
NMSE=mean(e^2)/var(Yts)
print(NMSE)
## classification example
n=4
N=1000
X=array(rnorm(N*n),c(N,n))
Y=numeric(N)
Y[which(X[,1]*X[,2]+rnorm(N,sd=0.1)>0)]<-1
Y=factor(Y)
Itr=sample(N,round(N/2))
Its=setdiff(1:N,Itr)
Xtr=X[Itr,]
Ytr=Y[Itr]
Xts=X[Its,]
Yts=Y[Its]
Yhat=pred("lda",Xtr,Ytr,Xts,classi=TRUE)$pred
e=as.numeric(Yts!=Yhat)
## misclassification error
MISCL=sum(e)
print(MISCL/N)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.