神经网络使用所有输入变量? [英] neural network using all input variables?

查看:398
本文介绍了神经网络使用所有输入变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是神经网络的新手,并且一直在尝试使用一些大数据集的算法.有没有一种方法可以将所有输入变量都包含到网络中而不必键入所有名称?例如,我有大约30个变量,希望将它们用作输入来预测输出.以下命令是否有快捷方式?

I am a newbie to neural networks and been trying out the algorithm with some big data sets. Is there a way to include all the input variables into the network without having to type all the names? For example I have around 30 variables which I'd like to use as input to predict the output. Is there a shortcut for the following command?

net <- neuralnet(Output~Var1+Var2+Var3+Var4+.....upto Var30, data, hidden=0)

我到处都看过,但是找不到解决方案.抱歉,这是一个基本问题!

I've looked everywhere but couldn't find the solution to this. Sorry if this is a basic question!

推荐答案

有3种方法可以在函数的公式部分插入变量:

There are 3 ways to insert variables in the formula part of a function:

首先,方法是使用.,它将包含data data.frame中的所有变量,而不包括响应变量(在这种情况下为变量Output):

First by using . which will include all of the variables in the data data.frame apart from the response variable (variable Output in this case):

net <- neuralnet(Output ~ ., data, hidden=0) #apart from Output all of the other variables in data are included

如果您的data.frame仅具有Output和另外30个变量,请使用此选项.

Use this if your data.frame has Output and another 30 variables only.

第二,如果要使用名称矢量来包含数据data.frame,可以尝试:

Second if you want to use a vector of names to include from the data data.frame you can try:

names <- c('var1','var2','var3') #choose the names you want
a <- as.formula(paste('Output ~ ' ,paste(names,collapse='+')))

> a
Output ~ var1 + var2 + var3 #this is what goes in the neuralnet function below

因此您可以使用:

net <- neuralnet( a , data, hidden=0) #use a in the function

如果您可以提供30个变量名称的向量,请使用此选项

Use this if you can provide a vector of the names of the 30 variables

第三只需使用函数中想要的列即可将data data.frame子集化,例如:

Third just subset the data data.frame using the columns you want in the function e.g.:

net <- neuralnet(Output ~ ., data=data[,1:31] , hidden=0)

使用它来(或方便使用的任何其他子集)并选择所需的30个变量以及Output变量.然后使用.包含所有内容.

Use this to (or any other subset that is convenient) and choose the 30 variables you need along with the Output variable. Then use . to include everything.

希望有帮助!

这篇关于神经网络使用所有输入变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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