R - XGBoost: Error building DMatrix












12















I am having trouble using the XGBoost in R.
I am reading a CSV file with my data:



get_data = function()
{
#Loading Data
path = "dados_eye.csv"
data = read.csv(path)

#Dividing into two groups
train_porcentage = 0.05
train_lines = nrow(data)*train_porcentage
train = data[1:train_lines,]
test = data[train_lines:nrow(data),]
rownames(train) = c(1:nrow(train))
rownames(test) = c(1:nrow(test))

return (list("test" = test, "train" = train))
}


This function is Called my the main.R



lista_dados = get_data()
#machine = train_svm(lista_dados$train)
#machine = train_rf(lista_dados$train)
machine = train_xgt(lista_dados$train)


The problem is here in the train_xgt



train_xgt = function(train_data)
{
data_train = data.frame(train_data[,1:14])
label_train = data.frame(factor(train_data[,15]))

print(is.data.frame(data_train))
print(is.data.frame(label_train))

dtrain = xgb.DMatrix(data_train, label=label_train)
machine = xgboost(dtrain, num_class = 4 ,max.depth = 2,
eta = 1, nround = 2,nthread = 2,
objective = "binary:logistic")

return (machine)
}


This is the Error:




becchi@ubuntu:~/Documents/EEG_DATA/Dados_Eye$ Rscript main.R



[1] TRUE



[1] TRUE



Error in xgb.DMatrix(data_train, label = label_train) :

xgb.DMatrix: does not support to construct from list Calls: train_xgt
-> xgb.DMatrix Execution halted becchi@ubuntu:~/Documents/EEG_DATA/Dados_Eye$




As you can see, they are both DataFrames.



I dont know what I am doing wrong, please help!










share|improve this question


















  • 2





    what if you convert the data.frame input using data.matrix()? xgboost may not like the data.frame

    – Sam Firke
    Mar 13 '17 at 0:57
















12















I am having trouble using the XGBoost in R.
I am reading a CSV file with my data:



get_data = function()
{
#Loading Data
path = "dados_eye.csv"
data = read.csv(path)

#Dividing into two groups
train_porcentage = 0.05
train_lines = nrow(data)*train_porcentage
train = data[1:train_lines,]
test = data[train_lines:nrow(data),]
rownames(train) = c(1:nrow(train))
rownames(test) = c(1:nrow(test))

return (list("test" = test, "train" = train))
}


This function is Called my the main.R



lista_dados = get_data()
#machine = train_svm(lista_dados$train)
#machine = train_rf(lista_dados$train)
machine = train_xgt(lista_dados$train)


The problem is here in the train_xgt



train_xgt = function(train_data)
{
data_train = data.frame(train_data[,1:14])
label_train = data.frame(factor(train_data[,15]))

print(is.data.frame(data_train))
print(is.data.frame(label_train))

dtrain = xgb.DMatrix(data_train, label=label_train)
machine = xgboost(dtrain, num_class = 4 ,max.depth = 2,
eta = 1, nround = 2,nthread = 2,
objective = "binary:logistic")

return (machine)
}


This is the Error:




becchi@ubuntu:~/Documents/EEG_DATA/Dados_Eye$ Rscript main.R



[1] TRUE



[1] TRUE



Error in xgb.DMatrix(data_train, label = label_train) :

xgb.DMatrix: does not support to construct from list Calls: train_xgt
-> xgb.DMatrix Execution halted becchi@ubuntu:~/Documents/EEG_DATA/Dados_Eye$




As you can see, they are both DataFrames.



I dont know what I am doing wrong, please help!










share|improve this question


















  • 2





    what if you convert the data.frame input using data.matrix()? xgboost may not like the data.frame

    – Sam Firke
    Mar 13 '17 at 0:57














12












12








12








I am having trouble using the XGBoost in R.
I am reading a CSV file with my data:



get_data = function()
{
#Loading Data
path = "dados_eye.csv"
data = read.csv(path)

#Dividing into two groups
train_porcentage = 0.05
train_lines = nrow(data)*train_porcentage
train = data[1:train_lines,]
test = data[train_lines:nrow(data),]
rownames(train) = c(1:nrow(train))
rownames(test) = c(1:nrow(test))

return (list("test" = test, "train" = train))
}


This function is Called my the main.R



lista_dados = get_data()
#machine = train_svm(lista_dados$train)
#machine = train_rf(lista_dados$train)
machine = train_xgt(lista_dados$train)


The problem is here in the train_xgt



train_xgt = function(train_data)
{
data_train = data.frame(train_data[,1:14])
label_train = data.frame(factor(train_data[,15]))

print(is.data.frame(data_train))
print(is.data.frame(label_train))

dtrain = xgb.DMatrix(data_train, label=label_train)
machine = xgboost(dtrain, num_class = 4 ,max.depth = 2,
eta = 1, nround = 2,nthread = 2,
objective = "binary:logistic")

return (machine)
}


This is the Error:




becchi@ubuntu:~/Documents/EEG_DATA/Dados_Eye$ Rscript main.R



[1] TRUE



[1] TRUE



Error in xgb.DMatrix(data_train, label = label_train) :

xgb.DMatrix: does not support to construct from list Calls: train_xgt
-> xgb.DMatrix Execution halted becchi@ubuntu:~/Documents/EEG_DATA/Dados_Eye$




As you can see, they are both DataFrames.



I dont know what I am doing wrong, please help!










share|improve this question














I am having trouble using the XGBoost in R.
I am reading a CSV file with my data:



get_data = function()
{
#Loading Data
path = "dados_eye.csv"
data = read.csv(path)

#Dividing into two groups
train_porcentage = 0.05
train_lines = nrow(data)*train_porcentage
train = data[1:train_lines,]
test = data[train_lines:nrow(data),]
rownames(train) = c(1:nrow(train))
rownames(test) = c(1:nrow(test))

return (list("test" = test, "train" = train))
}


This function is Called my the main.R



lista_dados = get_data()
#machine = train_svm(lista_dados$train)
#machine = train_rf(lista_dados$train)
machine = train_xgt(lista_dados$train)


The problem is here in the train_xgt



train_xgt = function(train_data)
{
data_train = data.frame(train_data[,1:14])
label_train = data.frame(factor(train_data[,15]))

print(is.data.frame(data_train))
print(is.data.frame(label_train))

dtrain = xgb.DMatrix(data_train, label=label_train)
machine = xgboost(dtrain, num_class = 4 ,max.depth = 2,
eta = 1, nround = 2,nthread = 2,
objective = "binary:logistic")

return (machine)
}


This is the Error:




becchi@ubuntu:~/Documents/EEG_DATA/Dados_Eye$ Rscript main.R



[1] TRUE



[1] TRUE



Error in xgb.DMatrix(data_train, label = label_train) :

xgb.DMatrix: does not support to construct from list Calls: train_xgt
-> xgb.DMatrix Execution halted becchi@ubuntu:~/Documents/EEG_DATA/Dados_Eye$




As you can see, they are both DataFrames.



I dont know what I am doing wrong, please help!







r dataframe machine-learning xgboost






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 12 '17 at 3:37









Gabriel Chaves BecchiGabriel Chaves Becchi

86111




86111








  • 2





    what if you convert the data.frame input using data.matrix()? xgboost may not like the data.frame

    – Sam Firke
    Mar 13 '17 at 0:57














  • 2





    what if you convert the data.frame input using data.matrix()? xgboost may not like the data.frame

    – Sam Firke
    Mar 13 '17 at 0:57








2




2





what if you convert the data.frame input using data.matrix()? xgboost may not like the data.frame

– Sam Firke
Mar 13 '17 at 0:57





what if you convert the data.frame input using data.matrix()? xgboost may not like the data.frame

– Sam Firke
Mar 13 '17 at 0:57












3 Answers
3






active

oldest

votes


















12














Just convert data frame to matrix first using as.matrix() and then pass to xgb.Dmatrix().






share|improve this answer

































    1














    Check if all columns have numeric data in them- I think this could be because you have some column that has data stored as factors/ characters which it won't be able to convert to a matrix. if you have factor variables, you can use one-hot encoding to convert them into dummy variables.






    share|improve this answer































      1














      "As you can see, they are both DataFrames." -Gabriel Chaves Becchi



      A data frame is just a list of vectors. Might be why you're seeing "list".






      share|improve this answer
























      • This should have been a comment, not an answer. With a bit more rep, you will be able to post comments.

        – CloC
        Feb 13 at 0:57











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42743460%2fr-xgboost-error-building-dmatrix%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      12














      Just convert data frame to matrix first using as.matrix() and then pass to xgb.Dmatrix().






      share|improve this answer






























        12














        Just convert data frame to matrix first using as.matrix() and then pass to xgb.Dmatrix().






        share|improve this answer




























          12












          12








          12







          Just convert data frame to matrix first using as.matrix() and then pass to xgb.Dmatrix().






          share|improve this answer















          Just convert data frame to matrix first using as.matrix() and then pass to xgb.Dmatrix().







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 19 '18 at 21:37









          samadhi

          1,4491121




          1,4491121










          answered Jun 29 '17 at 7:02









          ad28ad28

          12913




          12913

























              1














              Check if all columns have numeric data in them- I think this could be because you have some column that has data stored as factors/ characters which it won't be able to convert to a matrix. if you have factor variables, you can use one-hot encoding to convert them into dummy variables.






              share|improve this answer




























                1














                Check if all columns have numeric data in them- I think this could be because you have some column that has data stored as factors/ characters which it won't be able to convert to a matrix. if you have factor variables, you can use one-hot encoding to convert them into dummy variables.






                share|improve this answer


























                  1












                  1








                  1







                  Check if all columns have numeric data in them- I think this could be because you have some column that has data stored as factors/ characters which it won't be able to convert to a matrix. if you have factor variables, you can use one-hot encoding to convert them into dummy variables.






                  share|improve this answer













                  Check if all columns have numeric data in them- I think this could be because you have some column that has data stored as factors/ characters which it won't be able to convert to a matrix. if you have factor variables, you can use one-hot encoding to convert them into dummy variables.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 14 '17 at 9:11









                  biabia

                  113




                  113























                      1














                      "As you can see, they are both DataFrames." -Gabriel Chaves Becchi



                      A data frame is just a list of vectors. Might be why you're seeing "list".






                      share|improve this answer
























                      • This should have been a comment, not an answer. With a bit more rep, you will be able to post comments.

                        – CloC
                        Feb 13 at 0:57
















                      1














                      "As you can see, they are both DataFrames." -Gabriel Chaves Becchi



                      A data frame is just a list of vectors. Might be why you're seeing "list".






                      share|improve this answer
























                      • This should have been a comment, not an answer. With a bit more rep, you will be able to post comments.

                        – CloC
                        Feb 13 at 0:57














                      1












                      1








                      1







                      "As you can see, they are both DataFrames." -Gabriel Chaves Becchi



                      A data frame is just a list of vectors. Might be why you're seeing "list".






                      share|improve this answer













                      "As you can see, they are both DataFrames." -Gabriel Chaves Becchi



                      A data frame is just a list of vectors. Might be why you're seeing "list".







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Feb 13 at 0:12









                      Nigel TufnelNigel Tufnel

                      111




                      111













                      • This should have been a comment, not an answer. With a bit more rep, you will be able to post comments.

                        – CloC
                        Feb 13 at 0:57



















                      • This should have been a comment, not an answer. With a bit more rep, you will be able to post comments.

                        – CloC
                        Feb 13 at 0:57

















                      This should have been a comment, not an answer. With a bit more rep, you will be able to post comments.

                      – CloC
                      Feb 13 at 0:57





                      This should have been a comment, not an answer. With a bit more rep, you will be able to post comments.

                      – CloC
                      Feb 13 at 0:57


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42743460%2fr-xgboost-error-building-dmatrix%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      MongoDB - Not Authorized To Execute Command

                      How to fix TextFormField cause rebuild widget in Flutter

                      Npm cannot find a required file even through it is in the searched directory