1 people like it.

Configure F# Interactive to use Microsoft.ML.Net

Updated to use the new "nuget:..." style references. At this time a workaround is needed to properly load some of the native libraries.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
45: 
46: 
47: 
48: 
49: 
50: 
51: 
52: 
53: 
54: 
55: 
56: 
57: 
58: 
59: 
60: 
61: 
62: 
63: 
64: 
65: 
66: 
67: 
68: 
69: 
70: 
71: 
72: 
73: 
74: 
75: 
76: 
77: 
78: 
79: 
80: 
81: 
82: 
83: 
84: 
85: 
86: 
87: 
88: 
89: 
//as of ML.Net 1.3
(* generate refs - shoud net most of the required libs

open System.IO

let includeSet = [ 
     "System.Collections.Immutable"
     "System.Runtime.CompilerServices.Unsafe"
     "System.Memory"
     "System.Numerics.Vector"
     "Microsoft.ML"
    ] 
let excludeSet = [
         //"LightGbm.2.2.3"
         "Mkl.Redist"
         "ML.OnnxRuntime"
    ]
let dirs = Directory.EnumerateDirectories(__SOURCE_DIRECTORY__ + @"\..\packages")
;;
dirs 
|> Seq.map (fun d->d.Replace(__SOURCE_DIRECTORY__+ @"\","")) 
|> Seq.filter(fun dir -> includeSet |> List.exists(fun y -> dir.Contains(y)))
|> Seq.filter(fun dir -> excludeSet |> List.exists(fun y -> dir.Contains(y)) |> not)
|> Seq.iter (printfn """#I @"%s\lib\netstandard2.0" """)
;;
let platform = @"*win-x64*"
let nativeDirs = Directory.EnumerateDirectories(__SOURCE_DIRECTORY__ + @"\..\packages",platform,SearchOption.AllDirectories)
;;
nativeDirs 
|> Seq.map (fun d->d.Replace(__SOURCE_DIRECTORY__+ @"\","")) 
|> Seq.iter (printfn """+ ";" + combine current @"%s\native" """)

*)
#r "netstandard"
#I @"..\packages\Microsoft.ML.1.3.1\lib\netstandard2.0" 
#I @"..\packages\Microsoft.ML.AutoML.0.15.1\lib\netstandard2.0" 
#I @"..\packages\Microsoft.ML.CpuMath.1.3.1\lib\netstandard2.0" 
#I @"..\packages\Microsoft.ML.DataView.1.3.1\lib\netstandard2.0" 
#I @"..\packages\Microsoft.ML.DnnImageFeaturizer.AlexNet.0.15.1\lib\netstandard2.0" 
#I @"..\packages\Microsoft.ML.Ensemble.0.15.1\lib\netstandard2.0" 
#I @"..\packages\Microsoft.ML.FastTree.1.3.1\lib\netstandard2.0" 
#I @"..\packages\Microsoft.ML.ImageAnalytics.1.3.1\lib\netstandard2.0" 
#I @"..\packages\Microsoft.ML.LightGbm.1.3.1\lib\netstandard2.0" 
#I @"..\packages\Microsoft.ML.Mkl.Components.1.3.1\lib\netstandard2.0" 
#I @"..\packages\Microsoft.ML.OnnxTransformer.1.3.1\lib\netstandard2.0" 
#I @"..\packages\Microsoft.ML.Recommender.0.15.1\lib\netstandard2.0" 
#I @"..\packages\Microsoft.ML.StaticPipe.0.14.0\lib\netstandard2.0" 
#I @"..\packages\Microsoft.ML.TimeSeries.1.3.1\lib\netstandard2.0" 
#I @"..\packages\System.Collections.Immutable.1.6.0-preview5.19224.8\lib\netstandard2.0" 
#I @"..\packages\System.Memory.4.5.3\lib\netstandard2.0" 
#I @"..\packages\System.Numerics.Vectors.4.6.0-preview5.19224.8\lib\netstandard2.0" 
#I @"..\packages\System.Runtime.CompilerServices.Unsafe.4.6.0-preview6.19259.10\lib\netstandard2.0"

#r "System.Collections.Immutable.dll"
#r "System.Runtime.CompilerServices.Unsafe.dll"
#r "Microsoft.ML.CpuMath.dll"
#r "Microsoft.ML.Core.dll"
#r "Microsoft.ML.DataView.dll"
#r "Microsoft.ML.Data.dll"
#r "Microsoft.ML.FastTree.dll"
#r "Microsoft.ML.LightGBM.dll"
#r "Microsoft.ML.StaticPipe.dll"
#r "System.Memory.dll"
#r "Microsoft.ML.Transforms.dll"
#r "Microsoft.ML.Ensemble.dll"
#r "Microsoft.ML.PCA.dll"
#r "Microsoft.ML.TimeSeries.dll"
#r "Microsoft.ML.AutoML"
#r "Microsoft.ML.StandardTrainers"

//need specific version otherwise fsi will bind to system version
#r @"..\packages\System.Numerics.Vectors.4.6.0-preview5.19224.8\lib\netstandard2.0\System.Numerics.Vectors.dll"

open System
let path = Environment.GetEnvironmentVariable("path")
let current = __SOURCE_DIRECTORY__
let combine a b = IO.Path.GetFullPath(IO.Path.Combine(a,b))

let path' = 
    path 
    + ";" + combine current @"..\packages\LightGBM.2.2.3\runtimes\win-x64\native" 
    + ";" + combine current @"..\packages\Microsoft.ML.1.3.1\runtimes\win-x64\native" 
    + ";" + combine current @"..\packages\Microsoft.ML.CpuMath.1.3.1\runtimes\win-x64\native" 
    + ";" + combine current @"..\packages\Microsoft.ML.FastTree.1.3.1\runtimes\win-x64\native" 
    + ";" + combine current @"..\packages\Microsoft.ML.Mkl.Components.1.3.1\runtimes\win-x64\native" 
    + ";" + combine current @"..\packages\Microsoft.ML.Mkl.Redist.1.3.1\runtimes\win-x64\native" 
    + ";" + combine current @"..\packages\Microsoft.ML.OnnxRuntime.0.5.0\runtimes\win-x64\native" 
    + ";" + combine current @"..\packages\Microsoft.ML.Recommender.0.15.1\runtimes\win-x64\native" 
Environment.SetEnvironmentVariable("path",path')
namespace System
val path : string

Full name: Script.path
type Environment =
  static member CommandLine : string
  static member CurrentDirectory : string with get, set
  static member Exit : exitCode:int -> unit
  static member ExitCode : int with get, set
  static member ExpandEnvironmentVariables : name:string -> string
  static member FailFast : message:string -> unit + 1 overload
  static member GetCommandLineArgs : unit -> string[]
  static member GetEnvironmentVariable : variable:string -> string + 1 overload
  static member GetEnvironmentVariables : unit -> IDictionary + 1 overload
  static member GetFolderPath : folder:SpecialFolder -> string + 1 overload
  ...
  nested type SpecialFolder
  nested type SpecialFolderOption

Full name: System.Environment
Environment.GetEnvironmentVariable(variable: string) : string
Environment.GetEnvironmentVariable(variable: string, target: EnvironmentVariableTarget) : string
val current : string

Full name: Script.current
val combine : a:string -> b:string -> string

Full name: Script.combine
val a : string
val b : string
namespace System.IO
type Path =
  static val DirectorySeparatorChar : char
  static val AltDirectorySeparatorChar : char
  static val VolumeSeparatorChar : char
  static val InvalidPathChars : char[]
  static val PathSeparator : char
  static member ChangeExtension : path:string * extension:string -> string
  static member Combine : [<ParamArray>] paths:string[] -> string + 3 overloads
  static member GetDirectoryName : path:string -> string
  static member GetExtension : path:string -> string
  static member GetFileName : path:string -> string
  ...

Full name: System.IO.Path
IO.Path.GetFullPath(path: string) : string
IO.Path.Combine([<ParamArray>] paths: string []) : string
IO.Path.Combine(path1: string, path2: string) : string
IO.Path.Combine(path1: string, path2: string, path3: string) : string
IO.Path.Combine(path1: string, path2: string, path3: string, path4: string) : string
val path' : string

Full name: Script.path'
Environment.SetEnvironmentVariable(variable: string, value: string) : unit
Environment.SetEnvironmentVariable(variable: string, value: string, target: EnvironmentVariableTarget) : unit

More information

Link:http://fssnip.net/7Wi
Posted:3 years ago
Author:Faisal Waris
Tags: machine learning , ml.net