0
$\begingroup$

I have a data frame, and I am only interested in the numerical variables (variable class is double):

Example

A    B    C    D    E
0.13 2.22 3.44 3.30 6.54
3.55 4.23 0.43 5.33 3.55
...

I want to build a linear regression xgboost model, so I converted the data frame to a dense matrix.

I took out all categorical variables from my data, and am left with the five variables of interest. But I can't seem to be able to use the dense matrix, despite it being a type of input that xgboost accepts. See here. I am instead getting this error:

Error

"Error in xgb.DMatrix(train_mat[, -n], label = train_mat[, n]) : [23:57:13] amalgamation/../dmlc-core/src/io/local_filesys.cc:66: LocalFileSystem.GetPathInfo 2007 Error:No such file or directory".

Code

train_mat <- as.matrix(subset(train, select = -c(Genre, Publisher, Rank, Name, Platform)))

lm.boosted <- xgb.train(data = train_mat, booster= "gblinear", max_depth=3, nthread=1, nrounds = 2, eval_metric="error", eval_metric= "rmse", objective= "reg:linear")

I tried to convert to a xgb.DMatrix, but I am not clear on what it's asking for to do the conversion.

train_mat <- xgb.DMatrix(data = train_mat, label= train$Global_Sales)

How do I input data into xgboost?

$\endgroup$

2 Answers 2

0
$\begingroup$

Following this example:

Suppose the last column in train_mat is the label that needs to be predicted, i.e. Global_Sales, then you construct the xgb.DMatrix as:

n <- ncol(train_mat)    # or if not the last, the position of the label column
dtrain <- xgb.DMatrix(train_mat[,-n], label=train_mat[,n])

To train the model, simply pass dtrain to the data parameter:

lm.boosted <- xgb.train(data = dtrain, booster= "gblinear", max_depth=3, nthread=1, nrounds = 2, eval_metric="error", eval_metric= "rmse", objective= "reg:linear")
$\endgroup$
3
  • $\begingroup$ Global_Sales is the last column in train_mat. But sorry, I get the following error: "Error in xgb.DMatrix(train_mat[, -n], label = train_mat[, n]) : [23:57:13] amalgamation/../dmlc-core/src/io/local_filesys.cc:66: LocalFileSystem.GetPathInfo 2007 Error:No such file or directory". I can run the example in the link you posted, so there must be something wrong with the matrix I am creating for my model. $\endgroup$
    – cocanut
    Sep 25, 2017 at 3:59
  • $\begingroup$ The error looks mysterious to me. Are you able to read the data in? OR when running in console, does train_mat load? $\endgroup$
    – Psidom
    Sep 25, 2017 at 14:52
  • $\begingroup$ Yeah, I am able to interact with the data fully in Rstudio. Train mat loads in console as well. If nothing else, I'll get in touch with the xgboost people. $\endgroup$
    – cocanut
    Sep 25, 2017 at 17:36
0
$\begingroup$

I got some help from the xgboost issues page on Github; thread here.

Made the following change to resolve the error:

train_mat <- data.matrix(subset(train, select = -c(Genre, Publisher, Rank, Name, Platform)))
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.