Variable Importance for caret loclda method












0















I am trying to compute the variable importance out of a caret 'loclda' model.



My training dataset contains 20 numeric predictors and 4 discrete outcome classes (2500 samples).



I built the model and computed the variable importance with the following commands:



# fit the model
control <- trainControl(
method="repeatedcv",
number=10,
repeats=3,
savePredictions='final',
summaryFunction=multiClassSummary,
returnData=F,
trim=T,
allowParallel=F
)

my_loclda_model <- train(MyClass ~ ., data=trainData, method='loclda', trControl=control, importance=T)

# compute variable importance
varImp(my_loclda_model)
Error : is.list(x) is not TRUE

traceback()
7: stop(msg, call. = FALSE, domain = NA)
6: stopifnot(is.list(x), is.list(val))
5: modifyList(data, lapply(data[, fc], as.numeric))
4: asNumeric(x)
3: filterVarImp(x_dat, y_dat, nonpara = nonpara, ...)
2: varImp.train(model_name)
1: varImp(model_name)


From caret user manual we can read the following:




For models that do not have corresponding varImp methods, see filterVarImp




Assuming loclda model does not have a varImp method, I tried to use the filterVarImp function directly from the final model:



str(my_loclda_model$finalModel)
List of 12
$ learn : num [1:2500, 1:20] -0.404 -0.336 -0.655 -0.618 -0.151 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:2500] "X2" "X3" "X5" "X6" ...
.. ..$ : chr [1:20] "indexA1" "indexF1" "index4" "index5" ...
$ grouping : Factor w/ 4 levels "group1","group2","group3",..: 1 5 2 5 1 1 3 4 3 1 ...
..- attr(*, "names")= chr [1:2500] "2" "3" "5" "6" ...
$ lev : chr [1:4] "group1" "group2" "group3" ...
$ weight.func :function (x)
$ k : num 3401
$ weighted.apriori: logi TRUE
$ call : language loclda(x = x, grouping = y, k = floor(param$k), importance = ..1)
$ xNames : chr [1:20] "indexA1" "indexF1" "index4" "index5" ...
$ problemType : chr "Classification"
$ tuneValue :'data.frame': 1 obs. of 1 variable:
..$ k: num 3401
$ obsLevels : atomic [1:4] group1 group2 group3 ...
..- attr(*, "ordered")= logi FALSE
$ param :List of 1
..$ importance: logi TRUE
- attr(*, "class")= chr "loclda"


imp_out <- filterVarImp(x=my_loclda_model$finalModel$learn, y=my_loclda_model$finalModel$grouping)

Error in data[, fc] : (subscript) logical subscript too long
traceback()
5: lapply(data[, fc], as.numeric)
4: stopifnot(is.list(x), is.list(val))
3: modifyList(data, lapply(data[, fc], as.numeric))
2: asNumeric(x)
1: filterVarImp(x = model_name$finalModel$learn, y = model_name$finalModel$grouping)


I don't understand. What x and y arguments should I pass to filterVarImp?



Thanks !



Note: the same problem also happened when using other methods (e.g. svmRadial, svmPoly, LogitBoost, regLogistic, ...).










share|improve this question





























    0















    I am trying to compute the variable importance out of a caret 'loclda' model.



    My training dataset contains 20 numeric predictors and 4 discrete outcome classes (2500 samples).



    I built the model and computed the variable importance with the following commands:



    # fit the model
    control <- trainControl(
    method="repeatedcv",
    number=10,
    repeats=3,
    savePredictions='final',
    summaryFunction=multiClassSummary,
    returnData=F,
    trim=T,
    allowParallel=F
    )

    my_loclda_model <- train(MyClass ~ ., data=trainData, method='loclda', trControl=control, importance=T)

    # compute variable importance
    varImp(my_loclda_model)
    Error : is.list(x) is not TRUE

    traceback()
    7: stop(msg, call. = FALSE, domain = NA)
    6: stopifnot(is.list(x), is.list(val))
    5: modifyList(data, lapply(data[, fc], as.numeric))
    4: asNumeric(x)
    3: filterVarImp(x_dat, y_dat, nonpara = nonpara, ...)
    2: varImp.train(model_name)
    1: varImp(model_name)


    From caret user manual we can read the following:




    For models that do not have corresponding varImp methods, see filterVarImp




    Assuming loclda model does not have a varImp method, I tried to use the filterVarImp function directly from the final model:



    str(my_loclda_model$finalModel)
    List of 12
    $ learn : num [1:2500, 1:20] -0.404 -0.336 -0.655 -0.618 -0.151 ...
    ..- attr(*, "dimnames")=List of 2
    .. ..$ : chr [1:2500] "X2" "X3" "X5" "X6" ...
    .. ..$ : chr [1:20] "indexA1" "indexF1" "index4" "index5" ...
    $ grouping : Factor w/ 4 levels "group1","group2","group3",..: 1 5 2 5 1 1 3 4 3 1 ...
    ..- attr(*, "names")= chr [1:2500] "2" "3" "5" "6" ...
    $ lev : chr [1:4] "group1" "group2" "group3" ...
    $ weight.func :function (x)
    $ k : num 3401
    $ weighted.apriori: logi TRUE
    $ call : language loclda(x = x, grouping = y, k = floor(param$k), importance = ..1)
    $ xNames : chr [1:20] "indexA1" "indexF1" "index4" "index5" ...
    $ problemType : chr "Classification"
    $ tuneValue :'data.frame': 1 obs. of 1 variable:
    ..$ k: num 3401
    $ obsLevels : atomic [1:4] group1 group2 group3 ...
    ..- attr(*, "ordered")= logi FALSE
    $ param :List of 1
    ..$ importance: logi TRUE
    - attr(*, "class")= chr "loclda"


    imp_out <- filterVarImp(x=my_loclda_model$finalModel$learn, y=my_loclda_model$finalModel$grouping)

    Error in data[, fc] : (subscript) logical subscript too long
    traceback()
    5: lapply(data[, fc], as.numeric)
    4: stopifnot(is.list(x), is.list(val))
    3: modifyList(data, lapply(data[, fc], as.numeric))
    2: asNumeric(x)
    1: filterVarImp(x = model_name$finalModel$learn, y = model_name$finalModel$grouping)


    I don't understand. What x and y arguments should I pass to filterVarImp?



    Thanks !



    Note: the same problem also happened when using other methods (e.g. svmRadial, svmPoly, LogitBoost, regLogistic, ...).










    share|improve this question



























      0












      0








      0








      I am trying to compute the variable importance out of a caret 'loclda' model.



      My training dataset contains 20 numeric predictors and 4 discrete outcome classes (2500 samples).



      I built the model and computed the variable importance with the following commands:



      # fit the model
      control <- trainControl(
      method="repeatedcv",
      number=10,
      repeats=3,
      savePredictions='final',
      summaryFunction=multiClassSummary,
      returnData=F,
      trim=T,
      allowParallel=F
      )

      my_loclda_model <- train(MyClass ~ ., data=trainData, method='loclda', trControl=control, importance=T)

      # compute variable importance
      varImp(my_loclda_model)
      Error : is.list(x) is not TRUE

      traceback()
      7: stop(msg, call. = FALSE, domain = NA)
      6: stopifnot(is.list(x), is.list(val))
      5: modifyList(data, lapply(data[, fc], as.numeric))
      4: asNumeric(x)
      3: filterVarImp(x_dat, y_dat, nonpara = nonpara, ...)
      2: varImp.train(model_name)
      1: varImp(model_name)


      From caret user manual we can read the following:




      For models that do not have corresponding varImp methods, see filterVarImp




      Assuming loclda model does not have a varImp method, I tried to use the filterVarImp function directly from the final model:



      str(my_loclda_model$finalModel)
      List of 12
      $ learn : num [1:2500, 1:20] -0.404 -0.336 -0.655 -0.618 -0.151 ...
      ..- attr(*, "dimnames")=List of 2
      .. ..$ : chr [1:2500] "X2" "X3" "X5" "X6" ...
      .. ..$ : chr [1:20] "indexA1" "indexF1" "index4" "index5" ...
      $ grouping : Factor w/ 4 levels "group1","group2","group3",..: 1 5 2 5 1 1 3 4 3 1 ...
      ..- attr(*, "names")= chr [1:2500] "2" "3" "5" "6" ...
      $ lev : chr [1:4] "group1" "group2" "group3" ...
      $ weight.func :function (x)
      $ k : num 3401
      $ weighted.apriori: logi TRUE
      $ call : language loclda(x = x, grouping = y, k = floor(param$k), importance = ..1)
      $ xNames : chr [1:20] "indexA1" "indexF1" "index4" "index5" ...
      $ problemType : chr "Classification"
      $ tuneValue :'data.frame': 1 obs. of 1 variable:
      ..$ k: num 3401
      $ obsLevels : atomic [1:4] group1 group2 group3 ...
      ..- attr(*, "ordered")= logi FALSE
      $ param :List of 1
      ..$ importance: logi TRUE
      - attr(*, "class")= chr "loclda"


      imp_out <- filterVarImp(x=my_loclda_model$finalModel$learn, y=my_loclda_model$finalModel$grouping)

      Error in data[, fc] : (subscript) logical subscript too long
      traceback()
      5: lapply(data[, fc], as.numeric)
      4: stopifnot(is.list(x), is.list(val))
      3: modifyList(data, lapply(data[, fc], as.numeric))
      2: asNumeric(x)
      1: filterVarImp(x = model_name$finalModel$learn, y = model_name$finalModel$grouping)


      I don't understand. What x and y arguments should I pass to filterVarImp?



      Thanks !



      Note: the same problem also happened when using other methods (e.g. svmRadial, svmPoly, LogitBoost, regLogistic, ...).










      share|improve this question
















      I am trying to compute the variable importance out of a caret 'loclda' model.



      My training dataset contains 20 numeric predictors and 4 discrete outcome classes (2500 samples).



      I built the model and computed the variable importance with the following commands:



      # fit the model
      control <- trainControl(
      method="repeatedcv",
      number=10,
      repeats=3,
      savePredictions='final',
      summaryFunction=multiClassSummary,
      returnData=F,
      trim=T,
      allowParallel=F
      )

      my_loclda_model <- train(MyClass ~ ., data=trainData, method='loclda', trControl=control, importance=T)

      # compute variable importance
      varImp(my_loclda_model)
      Error : is.list(x) is not TRUE

      traceback()
      7: stop(msg, call. = FALSE, domain = NA)
      6: stopifnot(is.list(x), is.list(val))
      5: modifyList(data, lapply(data[, fc], as.numeric))
      4: asNumeric(x)
      3: filterVarImp(x_dat, y_dat, nonpara = nonpara, ...)
      2: varImp.train(model_name)
      1: varImp(model_name)


      From caret user manual we can read the following:




      For models that do not have corresponding varImp methods, see filterVarImp




      Assuming loclda model does not have a varImp method, I tried to use the filterVarImp function directly from the final model:



      str(my_loclda_model$finalModel)
      List of 12
      $ learn : num [1:2500, 1:20] -0.404 -0.336 -0.655 -0.618 -0.151 ...
      ..- attr(*, "dimnames")=List of 2
      .. ..$ : chr [1:2500] "X2" "X3" "X5" "X6" ...
      .. ..$ : chr [1:20] "indexA1" "indexF1" "index4" "index5" ...
      $ grouping : Factor w/ 4 levels "group1","group2","group3",..: 1 5 2 5 1 1 3 4 3 1 ...
      ..- attr(*, "names")= chr [1:2500] "2" "3" "5" "6" ...
      $ lev : chr [1:4] "group1" "group2" "group3" ...
      $ weight.func :function (x)
      $ k : num 3401
      $ weighted.apriori: logi TRUE
      $ call : language loclda(x = x, grouping = y, k = floor(param$k), importance = ..1)
      $ xNames : chr [1:20] "indexA1" "indexF1" "index4" "index5" ...
      $ problemType : chr "Classification"
      $ tuneValue :'data.frame': 1 obs. of 1 variable:
      ..$ k: num 3401
      $ obsLevels : atomic [1:4] group1 group2 group3 ...
      ..- attr(*, "ordered")= logi FALSE
      $ param :List of 1
      ..$ importance: logi TRUE
      - attr(*, "class")= chr "loclda"


      imp_out <- filterVarImp(x=my_loclda_model$finalModel$learn, y=my_loclda_model$finalModel$grouping)

      Error in data[, fc] : (subscript) logical subscript too long
      traceback()
      5: lapply(data[, fc], as.numeric)
      4: stopifnot(is.list(x), is.list(val))
      3: modifyList(data, lapply(data[, fc], as.numeric))
      2: asNumeric(x)
      1: filterVarImp(x = model_name$finalModel$learn, y = model_name$finalModel$grouping)


      I don't understand. What x and y arguments should I pass to filterVarImp?



      Thanks !



      Note: the same problem also happened when using other methods (e.g. svmRadial, svmPoly, LogitBoost, regLogistic, ...).







      r r-caret






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 30 '18 at 11:45









      phiver

      13.2k92734




      13.2k92734










      asked Dec 30 '18 at 11:39









      user31888user31888

      1007




      1007
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Specifying x=as.data.frame(my_loclda_model$finalModel$learn) instead of a matrix seems to solve the problem, although the manual mentions that both matrix and data frame can be used.






          share|improve this answer























            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%2f53977285%2fvariable-importance-for-caret-loclda-method%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Specifying x=as.data.frame(my_loclda_model$finalModel$learn) instead of a matrix seems to solve the problem, although the manual mentions that both matrix and data frame can be used.






            share|improve this answer




























              0














              Specifying x=as.data.frame(my_loclda_model$finalModel$learn) instead of a matrix seems to solve the problem, although the manual mentions that both matrix and data frame can be used.






              share|improve this answer


























                0












                0








                0







                Specifying x=as.data.frame(my_loclda_model$finalModel$learn) instead of a matrix seems to solve the problem, although the manual mentions that both matrix and data frame can be used.






                share|improve this answer













                Specifying x=as.data.frame(my_loclda_model$finalModel$learn) instead of a matrix seems to solve the problem, although the manual mentions that both matrix and data frame can be used.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 30 '18 at 12:21









                user31888user31888

                1007




                1007






























                    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%2f53977285%2fvariable-importance-for-caret-loclda-method%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

                    Mossoró

                    Error while reading .h5 file using the rhdf5 package in R

                    Pushsharp Apns notification error: 'InvalidToken'