One-hot一次编码多列分类变量

时间:2017-10-26 20:17:26

标签: r neural-network one-hot-encoding

我有一个从UCI机器学习库获得的葡萄牙银行数据集,其组织如下:

> head(bank_data)
             age       job marital   education default housing loan   contact month day_of_week       duration      campaign        pdays
1  1.53301567694 housemaid married    basic.4y      no      no   no telephone   may         mon  0.01047129616 -0.5659151042 0.1954115279
2  1.62897345569  services married high.school unknown      no   no telephone   may         mon -0.42149539806 -0.5659151042 0.1954115279
3 -0.29018211937  services married high.school      no     yes   no telephone   may         mon -0.12451829578 -0.5659151042 0.1954115279
4 -0.00230878311    admin. married    basic.6y      no      no   no telephone   may         mon -0.41378170709 -0.5659151042 0.1954115279
5  1.53301567694  services married high.school      no      no  yes telephone   may         mon  0.18788618843 -0.5659151042 0.1954115279
6  0.47748011065  services married    basic.9y unknown      no   no telephone   may         mon -0.23250996934 -0.5659151042 0.1954115279
       previous    poutcome emp.var.rate cons.price.idx cons.conf.idx    euribor3m  nr.employed targetVar
1 -0.3494900415 nonexistent 0.6480843991    0.722713697  0.8864358006 0.7124512301 0.3316758805        no
2 -0.3494900415 nonexistent 0.6480843991    0.722713697  0.8864358006 0.7124512301 0.3316758805        no
3 -0.3494900415 nonexistent 0.6480843991    0.722713697  0.8864358006 0.7124512301 0.3316758805        no
4 -0.3494900415 nonexistent 0.6480843991    0.722713697  0.8864358006 0.7124512301 0.3316758805        no
5 -0.3494900415 nonexistent 0.6480843991    0.722713697  0.8864358006 0.7124512301 0.3316758805        no
6 -0.3494900415 nonexistent 0.6480843991    0.722713697  0.8864358006 0.7124512301 0.3316758805        no

我正在尝试使用此数据创建一个神经网络,使用nnet包或neuralnet(更容易或最终工作)。在我创建网络之前,我必须首先将所有分类变量转换为二元决策。

有没有一种方法可以“一次性”对所有这些列进行一次性编码?

我尝试使用mltools包:

data <- one_hot(bank_data)

但是这会出现以下错误:

  

[.data.frame中的错误(dt ,, cols,= = FALSE):未使用的参数   (有= FALSE)

0 个答案:

没有答案