在R中将分类变量转换为ANN(神经网络) [英] Converting categorical variables in R for ANN (neuralnet)

查看:610
本文介绍了在R中将分类变量转换为ANN(神经网络)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含客户信用详细信息的数据集.我必须使用Neuronet库在此数据集上构建神经网络模型.该数据集包含分类变量.我需要先转换这些变量,然后再运行它.有人可以帮我吗?

I have dataset which consists of credit details of customers. I have to build Neural Network model on this data set using the neuralnet library. This data set contains categorical variables. I need to transform these variables before running it. Can someone help me with this.

数据集中的变量:

checking_balance :< 0 DM,1-200 DM,未知,< 0 DM

checking_balance : < 0 DM, 1 - 200 DM, unknown, < 0 DM

目的:家具,教育,汽车

employment_duration :> 7年,1-4年,4-7年

employment_duration: > 7 years, 1 - 4 years, 4 - 7 years

credit_history :很好,很关键,很好

credit_history: very good, critical, good

months_loan_duration :6、48、12、42

months_loan_duration: 6, 48, 12, 42

谢谢..

推荐答案

要将分类变量用作输入,可以将其编码为一组布尔输入,每个布尔输入代表一个带有0或1的类别.例如,您的目的" '变量可以转换为三个布尔变量(家具,教育,汽车).

To use a categorical variable as input you can encode it as a set of boolean inputs, each representing one category with 0 or 1. For instance, your 'purpose' variable can be transformed into three boolean variables (furniture, education, cars).

您可以像这样自动生成带有类别标志的列:

You can generate columns with category flags automatically like this:

flags = data.frame(Reduce(cbind, 
     lapply(levels(d$purpose), function(x){(d$purpose == x)*1})
))
names(flags) = levels(d$purpose)
d = cbind(d, flags)

# Include the new columns as input variables
levelnames = paste(names(flags), collapse = " + ")
neuralnet(paste("output ~ ", levelnames), d)

这篇关于在R中将分类变量转换为ANN(神经网络)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆