I have a Portugese bank data set that I got from the UCI Machine Learning Repository that is organized like so:
> 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
I am trying to use this data to create a neural network using either the nnet
package or neuralnet
(whichever is easier or ends up working). It seems like before I can create the network, I must first transform all of the categorical variables into binary decisions.
Is there a way that I can "one-hot" encode all of these columns all at once?
I tried to use the mltools
package:
data <- one_hot(bank_data)
but this gives the following error:
Error in
[.data.frame
(dt, , cols, with = FALSE) : unused argument (with = FALSE)