How to use MLP (Multilayer Perceptron) in R?

女生的网名这么多〃 提交于 2019-12-22 01:17:55

问题


I want to train my data using multilayer perceptron in R and see the evaluation result like 'auc score'. There is a package named "monmlp" in R, however I don't know how to use it correctly.

I wrote the following code

> mlp.model = monmlp.fit(x, y, hidden1=3, n.ensemble=15, monotone=1, bag=T)
** Ensemble 1 
** Bagging on
1 0.9206784 
** 0.9206784 

** Ensemble 2 
** Bagging on
1 0.8200886 
** 0.8200886 

** Ensemble 3 
** Bagging on
1 0.8278868 
** 0.8278868
.
.
.
** Ensemble 15 
** Bagging on
1 0.8186057 
** 0.8186057 

mlp.pred <- monmlp.predict(x = x, weights = mlp.model)

It is ok up to now, but what is next? How can I find auc score for example?

Thanks..


回答1:


As suggested by the Machine learning task view, you can use the ROCR package.

# Sample data
library(monmlp)
n <- 1000
k <- 7
x <- matrix( rnorm(k*n), nr=n )
w <- rnorm(k)
y <- ifelse( logistic( x %*% w ) + rnorm(n, sd = 0.2) > 1, 0, 1 )

# Fit the model and compute the predictions
r <- monmlp.fit(x, y, hidden1=3, n.ensemble=15, monotone=1, bag=TRUE)
z <- monmlp.predict(x = x, weights = r)

# Compute the AUC
library(ROCR)
plot( performance( prediction( z, y ), "tpr","fpr" ) )
performance( prediction( z, y ), "auc" )@y.values[[1]]


来源:https://stackoverflow.com/questions/16228954/how-to-use-mlp-multilayer-perceptron-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!