title: How can I perform novelty detection with ksvm in R?
body: <p>I am trying to implement a novelty detector using the kernlab library (ksvm function) in R. Here is a simple example of what I am trying to do:</p>
  
  <pre><code># Training data
  xxTrain &lt;- matrix(rnorm(2000), nrow=1000, ncol=2, byrow=TRUE)
  y &lt;- rep(1,1000)
  classifier &lt;- ksvm(xxTrain, y, type="one-svc", kernel="rbfdot", kpar="automatic")
  # Test data
  x1 &lt;- rnorm(1000)
  scale &lt;- c(rep(1,500), rep(10,100), rep(1,400))
  x2 &lt;- rnorm(1000)*scale
  xxTest &lt;- matrix(c(x1,x2), nrow=1000, ncol=2, byrow=TRUE)
  # Prediction
  p &lt;- predict(classifier, xxTest, type="response")
  # Visualization
  plot(x2, type='l')
  lines(x1, col="red")
  points(5*as.integer(p), type='l', col="blue")
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/iHugv.png" alt="enter image description here"></p>
  
  <p>The figure above is the result I get. The blue trace is the prediction, and it clearly shows a period where its consitently 0. But it does not match in time or width with the outlier in the black trace. There are 100 points (black line) which are of larger amplitude, and the output I get in the blue does not match with the black line.</p>
  
  <p>What am I doing wrong?</p>