title: How to test your tuned SVM model on a new data-set using machine learning and Caret Package in R?
body: <p>Guys!</p>
  
  <p>I am a newbie in machine learning methods and have a question about it. I try to use <strong>Caret</strong> package in <strong>R</strong> to start this method and work with my dataset. </p>
  
  <p>I have a training dataset (Dataset1) with mutation information regarding my gene of interest let's say <strong>Gene A</strong>. </p>
  
  <p>In <strong>Dataset1</strong>, I have the information regarding the mutation of <strong>Gene A</strong> in the form of <strong>Mut</strong> or <strong>Not-Mut</strong>. I used the <strong>Dataset1</strong> with <strong>SVM model</strong> to predict the output (I chose SVM because it was more accurate than LVQ or GBM).
  So, in my first step, I divided my dataset into training and test groups because I've had information as a test and train set in the dataset. then I've done the cross validation with 10 fold.
  I tuned my model and assessed the performance of the model using the test dataset (using ROC curve).
  Everything goes fine till this step.</p>
  
  <p>I have another dataset. <strong>Dataset2</strong> which doesn't have mutation information regarding <strong>Gene A</strong>.
  What I want to do now is to use my <strong>tuned SVM model</strong> from the <strong>Dataset1</strong> on the <strong>Dataset2</strong> to see if it could give me mutation information regarding <strong>Gene A</strong> in the <strong>Dataset 2</strong> in a form of <strong>Mut/Not-Mut</strong>. I've gone through <strong>Caret</strong> package guide but I couldn't get it. I am stuck here and don't know what to do. </p>
  
  <p>I am not sure if I chose a right approach.Any suggestions or help would really be appreciated.</p>
  
  <p>Here is my code till I tuned my model from the first dataset.</p>
  
  <p>Selecting training and test models from the first dataset:</p>
  
  <pre><code>M_train &lt;- Dataset1[Dataset1$Case=='train',-1] #creating train feature data frame
  
  M_test &lt;- Dataset1[Dataset1$Case=='test',-1] #creating test feature data frame
  
  y=as.factor(M_train$Class) # Target variable for training
  
  
  ctrl &lt;- trainControl(method="repeatedcv", # 10fold cross validation
                       repeats=5, # do 5 repititions of cv
                       summaryFunction=twoClassSummary, # Use AUC to pick the best model
                       classProbs=TRUE)
  
  
  #Use the expand.grid to specify the search space 
  #Note that the default search grid selects 3 values of each tuning parameter
  
  grid &lt;- expand.grid(interaction.depth = seq(1,4,by=2), #tree depths from 1 to 4
                      n.trees=seq(10,100,by=10), # let iterations go from 10 to 100
                      shrinkage=c(0.01,0.1), # Try 2 values fornlearning rate 
                      n.minobsinnode = 20)
  
  
  # Set up for parallel processing
  #set.seed(1951)
  registerDoParallel(4,cores=2)
  
  
  #Train and Tune the SVM
  svm.tune &lt;- train(x=M_train,
                    y= M_train$Class,
                    method = "svmRadial",
                    tuneLength = 9, # 9 values of the cost function
                    preProc = c("center","scale"),
                    metric="ROC",
                    trControl=ctrl) # same as for gbm above
  
  #Finally, assess the performance of the model using the test data set.
  
  #Make predictions on the test data with the SVM Model
  svm.pred &lt;- predict(svm.tune,M_test)
  
  confusionMatrix(svm.pred,M_test$Class)
  
  svm.probs &lt;- predict(svm.tune,M_test,type="prob") # Gen probs for ROC
  
  svm.ROC &lt;- roc(predictor=svm.probs$mut,
                 response=as.factor(M_test$Class),
                 levels=y))
  
  plot(svm.ROC,main="ROC for SVM built with GA selected features")
  </code></pre>
  
  <p>So, here is where I stuck, how can I use svm.tune model to predict the mutation of <strong>Gene A</strong> in <strong>Dataset2</strong>?</p>
  
  <p>Thanks in advance,</p>