title: how to solve mlr, rose and caret errors in r
body: <p>I'm working on is unbalanced, so I'm trying to balance the <code>dataset</code> and for this purpose I tried various techniques such as caret, mlr, ROSE but got error? </p>
  
  <p>str(mydata)</p>
  
  <pre><code>Classes ‘data.table’ and 'data.frame':  40596053 obs. of  8 variables:
   $ SessionID  : chr  "1" "1" "1" "1" ...
   $ Timestamp.x: chr  "2014-04-07T10:51:09.277Z" "2014-04-07T10:54:09.868Z" "2014-04-07T10:54:46.998Z" "2014-04-07T10:57:00.306Z" ...
   $ ItemID.x   : chr  "214536502" "214536500" "214536506" "214577561" ...
   $ Category   : chr  "0" "0" "0" "0" ...
   $ Timestamp.y: chr  NA NA NA NA ...
   $ ItemID.y   : chr  "0" "0" "0" "0" ...
   $ Price      : chr  NA NA NA NA ...
   $ Quantity   : chr  NA NA NA NA ...
   - attr(*, ".internal.selfref")=&lt;externalptr&gt; 
   - attr(*, "sorted")= chr "SessionID"
  </code></pre>
  
  <blockquote>
    <p>dput(head(mydata, 20))</p>
  </blockquote>
  
  <pre><code>structure(list(SessionID = c("1", "1", "1", "1", "10000001", 
  "10000001", "10000001", "10000001", "10000001", "10000002", "10000002", 
  "10000002", "10000002", "10000003", "10000003", "10000003", "10000004", 
  "10000004", "10000004", "10000004"), Timestamp.x = c("2014-04-07T10:51:09.277Z", 
  "2014-04-07T10:54:09.868Z", "2014-04-07T10:54:46.998Z", "2014-04-07T10:57:00.306Z", 
  "2014-09-08T10:35:38.841Z", "2014-09-08T10:40:20.143Z", "2014-09-08T10:40:36.704Z", 
  "2014-09-08T10:41:12.386Z", "2014-09-08T10:48:34.245Z", "2014-09-08T19:10:51.206Z", 
  "2014-09-08T19:13:31.104Z", "2014-09-08T19:14:54.518Z", "2014-09-08T19:33:38.355Z", 
  "2014-09-05T11:32:15.524Z", "2014-09-05T11:34:25.159Z", "2014-09-05T11:37:23.321Z", 
  "2014-09-05T13:14:45.867Z", "2014-09-05T13:14:45.867Z", "2014-09-05T13:55:18.886Z", 
  "2014-09-05T13:55:18.886Z"), ItemID.x = c("214536502", "214536500", 
  "214536506", "214577561", "214854230", "214556216", "214556212", 
  "214854230", "214854125", "214849322", "214838094", "214714721", 
  "214853711", "214853090", "214851326", "214853094", "214853090", 
  "214853090", "214851326", "214851326"), Category = c("0", "0", 
  "0", "0", "S", "S", "S", "S", "S", "S", "S", "S", "S", "3", "3", 
  "3", "3", "3", "3", "3"), Timestamp.y = c(NA, NA, NA, NA, NA, 
  NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "2014-09-05T14:07:33.845Z", 
  "2014-09-05T14:07:33.845Z", "2014-09-05T14:07:33.845Z", "2014-09-05T14:07:33.845Z"
  ), ItemID.y = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
  1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c("0", 
  "1"), class = "factor"), Price = c(NA, NA, NA, NA, NA, NA, NA, 
  NA, NA, NA, NA, NA, NA, NA, NA, NA, "4188", "1046", "4188", "1046"
  ), Quantity = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
  NA, NA, NA, NA, "1", "1", "1", "1")), .Names = c("SessionID", 
  "Timestamp.x", "ItemID.x", "Category", "Timestamp.y", "ItemID.y", 
  "Price", "Quantity"), sorted = "SessionID", class = c("data.table", 
  "data.frame"), row.names = c(NA, -20L), .internal.selfref = &lt;pointer: 0x0000000013950788&gt;)
  </code></pre>
  
  <p>using mlr</p>
  
  <pre><code>task = makeClassifTask(data = mydata, target = "ItemID.y") 
  Warning in makeTask(type = type, data = data, weights = weights, blocking = blocking,  :
    Provided data is not a pure data.frame but from class data.table, hence it will be converted.
  Error in (function (cn, x)  : 
    Unsupported feature type (character) in column 'SessionID'.
  </code></pre>
  
  <p>so I changed the type of <code>sessionID</code> from <code>char</code> to <code>num</code> but got same error with <code>Timestamp.x</code></p>
  
  <pre><code>Warning in makeTask(type = type, data = data, weights = weights, blocking = blocking,  :
    Provided data is not a pure data.frame but from class data.table, hence it will be converted.
  Error in (function (cn, x)  : 
    Unsupported feature type (chr) in column 'Timestamp.x'.
  </code></pre>
  
  <p>Then I changed the type of <code>Timestamp.x</code> from <code>char</code> to <code>date</code> but again got same error.</p>
  
  <pre><code>Warning in makeTask(type = type, data = data, weights = weights, blocking = blocking,  :
        Provided data is not a pure data.frame but from class data.table, hence it will be converted.
      Error in (function (cn, x)  : 
        Unsupported feature type (Date) in column 'Timestamp.x'.
  </code></pre>
  
  <p>I also tried caret and ROSE </p>
  
  <pre><code>library(caret) 
  &gt; x &lt;- matrix(mydata %&gt;% select(-ItemID.y)
  &gt; y &lt;- as.factor(mydata$ItemID.y)
  &gt; imbl_crt &lt;- downSample(x, y, yname = "ItemID.y")
  Error in `$&lt;-.data.frame`(`*tmp*`, .outcome, value = c(1L, 1L, 1L, 1L,  : 
    replacement has 40596053 rows, data has 7
  </code></pre>
  
  <h1>using ROSE</h1>
  
  <pre><code>&gt; library(ROSE)
  &gt; data_balanced_over &lt;- ovun.sample(mydata$ItemID.y ~ ., data = mydata, method = "over", N = 40596053) #balance dataset using ROSE 
  Error in (function (formula, data, method, subset, na.action, N, p = 0.5,  : 
    The response variable has only one class.
  </code></pre>
  
  <p>How I fixed one of these issues and balance a <code>dataset</code>? 
  Thanks</p>