title: My rows are mismatched in my SVM scripting code for Kaggle
body: <p>I am reviewing my <code>e1071</code> code for SVM for the Kaggle Titanic data. Last I knew, this part of it was working, but now I'm getting a rather strange error. When I try to build my data.frame so I can submit to kaggle, it seems my prediction is the size of my training set instead of the test set. </p>
  
  <p><strong>Problem</strong></p>
  
  <blockquote>
    <p>Error in data.frame(PassengerId = test$passengerid, Survived = prediction) : 
      arguments imply differing number of rows: 418, 714</p>
  </blockquote>
  
  <p>Obviously, they should both be 418 and I do not understand what is going wrong? </p>
  
  <p><strong>Details</strong></p>
  
  <p>Here is my script: </p>
  
  <pre><code>setwd("Path\\To\Data")
  train &lt;- read.csv("train.csv")
  test &lt;- read.csv("test.csv")
  
  library("e1071")
  bestModel = svm(Survived ~ Pclass + Sex + Age + Sex * Pclass, data = train, kernel = "linear", cost = 1)
  
  prediction &lt;- predict(bestModel, newData=test, type="response")
  prediction[prediction &gt;= 0.5] &lt;- 1
  prediction[prediction != 1] &lt;- 0
  prediction[is.na(prediction)] &lt;- 0
  </code></pre>
  
  <p>This is the line that gives me the error:</p>
  
  <pre><code>predictionSubmit &lt;- data.frame(PassengerId = test$passengerid, Survived = prediction)
  </code></pre>
  
  <p><strong>Attempts</strong> </p>
  
  <p>I have used <code>names(train)</code> and <code>names(test)</code> to verify my column variable names are the same. You can find the data <a href="https://www.kaggle.com/c/titanic/data?train.csv" rel="nofollow">here</a>. I know my prediction code can be optimized into one line, but that isn't the issue here. I would appreciate a second pair of eyes on this issue. I am thinking about using the <code>kernlab</code> library, but was wondering if there was a syntatical sugar issue I was neglecting here. Thanks for your suggestions and clues. </p>