{
  "id": 10680,
  "title": "Simple R/svm/e1071 solution for top 100",
  "content": "<p>This may be a little premature, but...</p>\n<p>The following relatively simple svm approach may be of interest to some people who, like me, are relatively new to Kaggle. A variant of it placed me 83rd but the private leaderboard suggests it could have been closer to top 20 if I hadn't 'tuned' it further in the final week.</p>\n<p>The CV and public leaderboard scores were both close to 0.40. I'll return with the CV code once I know which of my 15 submissions placed where (I'm assuming we learn that at some stage?).</p>\n<p>My thanks to BreakfastPirate, Abhishek and all for their valuable forum posts. I'll be looking out for further advice on how people selected their best models for the final entries.</p>\n<p>R code:</p>\n<p><code>setwd(&quot;~/Documents/#RStudio/Africa Soil&quot;)</code></p>\n<p><code>library(e1071);&nbsp;library(prospectr)</code></p>\n<p><code># Data preparation; first derivative of half of spectra via SG (all the 'good stuff' seems to be in that half)</code></p>\n<p><code>myData &lt;- read.csv(&quot;training.csv&quot;, header = TRUE)</code></p>\n<p><code>sg21 &lt;- savitzkyGolay(myData[ , c(1800:3579)], p = 3, w = 21, m = 1)</code></p>\n<p><code>sg21 &lt;- data.frame(sg21)</code></p>\n\n<p><code># Final models (after much CV exploration of parameters)</code></p>\n<p><code>svm.Ca &lt;- svm(sg21, myData$Ca, cost = 50, gam = 0.00005, ep = 0.01)</code></p>\n<p><code>svm.SOC &lt;- svm(sg21, myData$SOC, cost = 40, gam = 0.00005, ep = 0.05)</code></p>\n<p><code>svm.pH &lt;- svm(sg21, myData$pH, cost = 30, gam = 0.0001, ep = 0.15)</code></p>\n<p><code>svm.P &lt;- svm(sg21, myData$P, cost = 10, gam = 0.0001, ep = 0.1)</code></p>\n<p><code>svm.Sand &lt;- svm(sg21, myData$Sand, cost = 5, gam = 0.0001, ep = 0.12)</code></p>\n\n<p><code># Read test data and make predictions</code></p>\n<p><code>testX &lt;- read.csv(&quot;sorted_test.csv&quot;, header = TRUE)</code></p>\n<p><code>test.sg21 &lt;- data.frame(savitzkyGolay(testX[, c(1800:3579)],</code><code>p = 3, w = 21, m = 1))</code></p>\n<p><code>sub &lt;- read.csv(&quot;sub Oct-04 sg21.csv&quot;, header = TRUE)</code></p>\n<p><code>sub$Ca &lt;- predict(svm.Ca, test.sg21)</code></p>\n<p><code>sub$SOC &lt;- predict(svm.SOC, test.sg21)</code></p>\n<p><code>sub$pH &lt;- predict(svm.pH, test.sg21)</code></p>\n<p><code>sub$P &lt;- predict(svm.P, test.sg21)</code></p>\n<p><code>sub$Sand &lt;- predict(svm.Sand, test.sg21)</code></p>\n<p><code>write.csv(sub, file = &quot;sub xxxxx.csv&quot;, row.names = FALSE)</code></p>",
  "comments": [],
  "comment_count": 0,
  "messages": [
    {
      "id": 56454,
      "postDate": "2014-10-22T08:13:40.457Z",
      "content": "<p>This may be a little premature, but...</p>\n<p>The following relatively simple svm approach may be of interest to some people who, like me, are relatively new to Kaggle. A variant of it placed me 83rd but the private leaderboard suggests it could have been closer to top 20 if I hadn't 'tuned' it further in the final week.</p>\n<p>The CV and public leaderboard scores were both close to 0.40. I'll return with the CV code once I know which of my 15 submissions placed where (I'm assuming we learn that at some stage?).</p>\n<p>My thanks to BreakfastPirate, Abhishek and all for their valuable forum posts. I'll be looking out for further advice on how people selected their best models for the final entries.</p>\n<p>R code:</p>\n<p><code>setwd(&quot;~/Documents/#RStudio/Africa Soil&quot;)</code></p>\n<p><code>library(e1071);&nbsp;library(prospectr)</code></p>\n<p><code># Data preparation; first derivative of half of spectra via SG (all the 'good stuff' seems to be in that half)</code></p>\n<p><code>myData &lt;- read.csv(&quot;training.csv&quot;, header = TRUE)</code></p>\n<p><code>sg21 &lt;- savitzkyGolay(myData[ , c(1800:3579)], p = 3, w = 21, m = 1)</code></p>\n<p><code>sg21 &lt;- data.frame(sg21)</code></p>\n\n<p><code># Final models (after much CV exploration of parameters)</code></p>\n<p><code>svm.Ca &lt;- svm(sg21, myData$Ca, cost = 50, gam = 0.00005, ep = 0.01)</code></p>\n<p><code>svm.SOC &lt;- svm(sg21, myData$SOC, cost = 40, gam = 0.00005, ep = 0.05)</code></p>\n<p><code>svm.pH &lt;- svm(sg21, myData$pH, cost = 30, gam = 0.0001, ep = 0.15)</code></p>\n<p><code>svm.P &lt;- svm(sg21, myData$P, cost = 10, gam = 0.0001, ep = 0.1)</code></p>\n<p><code>svm.Sand &lt;- svm(sg21, myData$Sand, cost = 5, gam = 0.0001, ep = 0.12)</code></p>\n\n<p><code># Read test data and make predictions</code></p>\n<p><code>testX &lt;- read.csv(&quot;sorted_test.csv&quot;, header = TRUE)</code></p>\n<p><code>test.sg21 &lt;- data.frame(savitzkyGolay(testX[, c(1800:3579)],</code><code>p = 3, w = 21, m = 1))</code></p>\n<p><code>sub &lt;- read.csv(&quot;sub Oct-04 sg21.csv&quot;, header = TRUE)</code></p>\n<p><code>sub$Ca &lt;- predict(svm.Ca, test.sg21)</code></p>\n<p><code>sub$SOC &lt;- predict(svm.SOC, test.sg21)</code></p>\n<p><code>sub$pH &lt;- predict(svm.pH, test.sg21)</code></p>\n<p><code>sub$P &lt;- predict(svm.P, test.sg21)</code></p>\n<p><code>sub$Sand &lt;- predict(svm.Sand, test.sg21)</code></p>\n<p><code>write.csv(sub, file = &quot;sub xxxxx.csv&quot;, row.names = FALSE)</code></p>",
      "votes": 5
    }
  ],
  "complete": true,
  "source": "live",
  "fetched_at": "2026-10-19T17:35:05Z",
  "competition_id": 3966,
  "competition_slug": "afsis-soil-properties",
  "team_id": 116236,
  "solution_url": "/competitions/afsis-soil-properties/writeups/lewis-simple-r-svm-e1071-solution-for-top-100"
}