Skip to content

Instantly share code, notes, and snippets.

@lmatt-bit
Created November 10, 2015 14:27
Show Gist options
  • Select an option

  • Save lmatt-bit/eb3b4aa02f0d8e8a5cba to your computer and use it in GitHub Desktop.

Select an option

Save lmatt-bit/eb3b4aa02f0d8e8a5cba to your computer and use it in GitHub Desktop.
randomForest in FSharp with RProvider. The data is from the digit recongizer of Kaggle.
open RProvider.utils
R.install_packages("randomForest") |> ignore
open System
open Deedle
open RDotNet
open RProvider
open RProvider.``base``
open RProvider.stats
open RProvider.randomForest
open RProvider.graphics
Console.WriteLine("start loading")
let train = Frame.ReadCsv("../../../train_example.csv", true)
Console.WriteLine("Finish loading")
let test = Frame.ReadCsv("../../../test_example.csv", true)
let train_feature_names = train.ColumnKeys |> Seq.skip 1
let paramDict = new System.Collections.Generic.Dictionary<string, obj>();
paramDict.["x"] <- train.Columns.[train_feature_names]
paramDict.["y"] <- R.as_factor(train.Columns.["label"])
paramDict.["xtest"] <- test
paramDict.["ntree"] <- 25
let rf = R.randomForest(paramDict)
rf.AsList().["test"].AsList().["predicted"].AsInteger() |> R.plot |> ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment