pred: Wrapper on learning algoritmhs for regression and...

View source: R/mlearn.R

predR Documentation

Wrapper on learning algoritmhs for regression and classification

Description

Wrapper on learning algoritmhs

Usage

pred(algo = "svm", X, Y, X.ts, classi = TRUE, to.scale = FALSE, ...)

Arguments

algo:

learning algoritmh: "lin": linear, "rf": randomForest, "svm": e1071 , "lazy": lazy, "gbm": gbm, "gam": gam, "nb": e1071, "lasso": lars, "mboost": mboost, "py.keras_regr","py.ridge_regr","py.rf_regr","py.piperf_regr","py.lasso_regr", "py.keras_regr","py.pls_regr","py.enet_regr","py.gb_regr","py.knn_regr","py.pipeknn_regr","py.ab_regr": sklearn regressors "py.sgd_class", "py.rf_class","py.gb_class","py.piperf_class", "py.gp_class","py.nb_class", "py.ab_class","py.knn_class","py.lsvm_class": sklearn classifiers

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

Details

The sklearn predictors require the installation of reticulate and the scikit-learn package

Value

if classi=FALSE predicted test output; if classi=TRUE a list with

  • pred: predicted class

  • prob: posteriori probability

Author(s)

Gianluca Bontempi gbonte@ulb.ac.be

References

https://tinyurl.com/sfmlh

Examples

## 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)


gbonte/gbcode documentation built on Aug. 30, 2024, 1:11 a.m.