{
  "id": 2805,
  "title": "[R] Caret - searching for parameters without fitting final model",
  "url": "/competitions/MerckActivity/discussion/2805",
  "author_name": "",
  "post_date": "2012-10-03T21:24:58.037Z",
  "votes": 4,
  "comment_count": 4,
  "views": 6847,
  "content": "<p>Hi. I use caret to find optimal parameters, but sometimes I don't need final model - especially if some other parameter is intentionally small to make the search faster. I guess I may not be alone. I finally got angry at all that wasted&nbsp;time and money,&nbsp;sometimes\r\n the final fitting took longer than all of cross-validation.</p>\r\n<p>I made a quick fix by modyfing the file train.default.R by adding a very simple and crude if. The original version is 5.15-044</p>\r\n<p>Now you can disable the creation of a final model by setting trainBest to false in train, example:</p>\r\n<p>model &lt;- train(train, activities, method = &quot;rf&quot;, trControl = fitControl, metric = 'Rsquared', tuneGrid = RFGrid, trainBest = FALSE, trace = 0, ntree = 75)</p>\r\n<p>finalModel and preProcess in result = NA with this option.</p>\r\n<p>Install by &quot;install.packages(&quot;caret_modified_by_pawzaw.tar.gz&quot;)&quot;.</p>\r\n<p>Without trainBest set to FALSE caret behaves as original.</p>",
  "messages": [
    {
      "id": "15150",
      "postDate": "10/03/2012 21:24:58",
      "content": "<p>Hi. I use caret to find optimal parameters, but sometimes I don't need final model - especially if some other parameter is intentionally small to make the search faster. I guess I may not be alone. I finally got angry at all that wasted&nbsp;time and money,&nbsp;sometimes\r\n the final fitting took longer than all of cross-validation.</p>\r\n<p>I made a quick fix by modyfing the file train.default.R by adding a very simple and crude if. The original version is 5.15-044</p>\r\n<p>Now you can disable the creation of a final model by setting trainBest to false in train, example:</p>\r\n<p>model &lt;- train(train, activities, method = &quot;rf&quot;, trControl = fitControl, metric = 'Rsquared', tuneGrid = RFGrid, trainBest = FALSE, trace = 0, ntree = 75)</p>\r\n<p>finalModel and preProcess in result = NA with this option.</p>\r\n<p>Install by &quot;install.packages(&quot;caret_modified_by_pawzaw.tar.gz&quot;)&quot;.</p>\r\n<p>Without trainBest set to FALSE caret behaves as original.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "15251",
      "postDate": "10/07/2012 17:37:23",
      "content": "<p>I think Max has done a great job with caret. It's helpful to have a consistent interface on top of a great many models. He's very accepting of patches (even informal ones) if you sent this his way.</p>\r\n<p>However, I think it's more aimed at real-life work instead of competition silliness. We used it for our first few contests and it was a solid asset. When you really start ensembling though, it's not quite there. Max had started working on a followup package,\r\n but I believe his day job got in the way:</p>\r\n<p>http://r-forge.r-project.org/projects/fusebox/</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "15252",
      "postDate": "10/07/2012 18:06:15",
      "content": "<p>Yes, caret is a great package. </p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "15635",
      "postDate": "10/15/2012 18:35:17",
      "content": "<p>[quote=pawzaw;15150]</p>\r\n<p>Hi. I use caret to find optimal parameters, but sometimes I don't need final model - especially if some other parameter is intentionally small to make the search faster. I guess I may not be alone. I finally got angry at all that wasted&nbsp;time and money,&nbsp;sometimes\r\n the final fitting took longer than all of cross-validation.</p>\r\n<p>I made a quick fix by modyfing the file train.default.R by adding a very simple and crude if. The original version is 5.15-044</p>\r\n<p>Now you can disable the creation of a final model by setting trainBest to false in train, example:</p>\r\n<p>model</p>\r\n<p>finalModel and preProcess in result = NA with this option.</p>\r\n<p>Install by &quot;install.packages(&quot;caret_modified_by_pawzaw.tar.gz&quot;)&quot;.</p>\r\n<p>Without trainBest set to FALSE caret behaves as original.</p>\r\n<p>[/quote]</p>\r\n<p>&nbsp;</p>\r\n<p>It's funny, I've sometimes had the OPPOSITE problem! &nbsp;I want to fit the final model in caret with NO cross validation. &nbsp;It provides a nice standardized interface and &quot;predict&quot; functions.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "20025",
      "postDate": "02/04/2013 18:31:54",
      "content": "<p>You can also use the &quot;custom&quot; method to do this. &nbsp;You have to manually pass a list to train control with the following parameters:</p>\r\n<p>parameters = &nbsp;grid of tuning parameters</p>\r\n<p>model = function to fit the model</p>\r\n<p>prediciton = prediciton function (value for regression, classes for classificaiton)</p>\r\n<p>probability = probability prediction function for classification models</p>\r\n<p>sort = &nbsp;function to sort tuning parameters from least to most complex, for breaking ties</p>\r\n<p>The &quot;model&quot; function must have an argument called &quot;last.&quot; &nbsp;When that argument is TRUE, caret is fitting the final model, and you can use an &quot;if&quot; statement to return NULL.</p>\r\n<p>This requires a little work on your part to manage the model fitting and prediction functions, but allows you to do this without patching caret. &nbsp;<a href=\"http://caret.r-forge.r-project.org/training.html\">You can read more here</a> (towards the end).</p>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 15251,
      "author_name": "biasvariance",
      "author_url": "",
      "post_date": "10/07/2012 17:37:23",
      "content": "<p>I think Max has done a great job with caret. It's helpful to have a consistent interface on top of a great many models. He's very accepting of patches (even informal ones) if you sent this his way.</p>\r\n<p>However, I think it's more aimed at real-life work instead of competition silliness. We used it for our first few contests and it was a solid asset. When you really start ensembling though, it's not quite there. Max had started working on a followup package,\r\n but I believe his day job got in the way:</p>\r\n<p>http://r-forge.r-project.org/projects/fusebox/</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 15252,
      "author_name": "rkirana",
      "author_url": "",
      "post_date": "10/07/2012 18:06:15",
      "content": "<p>Yes, caret is a great package. </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 15635,
      "author_name": "zachmayer",
      "author_url": "",
      "post_date": "10/15/2012 18:35:17",
      "content": "<p>[quote=pawzaw;15150]</p>\r\n<p>Hi. I use caret to find optimal parameters, but sometimes I don't need final model - especially if some other parameter is intentionally small to make the search faster. I guess I may not be alone. I finally got angry at all that wasted&nbsp;time and money,&nbsp;sometimes\r\n the final fitting took longer than all of cross-validation.</p>\r\n<p>I made a quick fix by modyfing the file train.default.R by adding a very simple and crude if. The original version is 5.15-044</p>\r\n<p>Now you can disable the creation of a final model by setting trainBest to false in train, example:</p>\r\n<p>model</p>\r\n<p>finalModel and preProcess in result = NA with this option.</p>\r\n<p>Install by &quot;install.packages(&quot;caret_modified_by_pawzaw.tar.gz&quot;)&quot;.</p>\r\n<p>Without trainBest set to FALSE caret behaves as original.</p>\r\n<p>[/quote]</p>\r\n<p>&nbsp;</p>\r\n<p>It's funny, I've sometimes had the OPPOSITE problem! &nbsp;I want to fit the final model in caret with NO cross validation. &nbsp;It provides a nice standardized interface and &quot;predict&quot; functions.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 20025,
      "author_name": "zachmayer",
      "author_url": "",
      "post_date": "02/04/2013 18:31:54",
      "content": "<p>You can also use the &quot;custom&quot; method to do this. &nbsp;You have to manually pass a list to train control with the following parameters:</p>\r\n<p>parameters = &nbsp;grid of tuning parameters</p>\r\n<p>model = function to fit the model</p>\r\n<p>prediciton = prediciton function (value for regression, classes for classificaiton)</p>\r\n<p>probability = probability prediction function for classification models</p>\r\n<p>sort = &nbsp;function to sort tuning parameters from least to most complex, for breaking ties</p>\r\n<p>The &quot;model&quot; function must have an argument called &quot;last.&quot; &nbsp;When that argument is TRUE, caret is fitting the final model, and you can use an &quot;if&quot; statement to return NULL.</p>\r\n<p>This requires a little work on your part to manage the model fitting and prediction functions, but allows you to do this without patching caret. &nbsp;<a href=\"http://caret.r-forge.r-project.org/training.html\">You can read more here</a> (towards the end).</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "15150": "",
    "15251": "",
    "15252": "",
    "15635": "",
    "20025": ""
  },
  "source": "meta"
}