Skip to content

update for ML.NET 0.3 and fix load problem #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions mlex.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open FSharp.Data
open Microsoft.ML

// 1. Get our data - could be from any source, in this case from a CSV file. This is completely decoupled from the ML library.
type SentimentData = CsvProvider< @"C:\Users\Isaac\Source\Repos\ml-test\data\imdb_labelled.txt", Separators="\t", HasHeaders=true, IgnoreErrors = true>
type SentimentData = CsvProvider< const (__SOURCE_DIRECTORY__ + @"\data\imdb_labelled.txt"), Separators="\t", HasHeaders=true, IgnoreErrors = true>
let imdbData = SentimentData.GetSample()


Expand All @@ -25,15 +25,13 @@ let imdbData = SentimentData.GetSample()


// We can easily work with multiple data sources and e.g. concatinate them.
let yelpData = SentimentData.Load @"C:\Users\Isaac\Source\Repos\ml-test\data\yelp_labelled.txt"
let amazonCells = SentimentData.Load @"C:\Users\Isaac\Source\Repos\ml-test\data\amazon_cells_labelled.txt"
let yelpData = SentimentData.Load (__SOURCE_DIRECTORY__ + @"\data\yelp_labelled.txt")
let amazonCells = SentimentData.Load (__SOURCE_DIRECTORY__ + @"\data\amazon_cells_labelled.txt")

let allData =
[ imdbData.Rows
yelpData.Rows
amazonCells.Rows ]
|> Seq.concat
|> Seq.toList
[ yield! imdbData.Rows
yield! yelpData.Rows
yield! amazonCells.Rows ]



Expand Down
14 changes: 10 additions & 4 deletions mlnet.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
#load @".paket\load\netstandard2.0\main.group.fsx"

open Microsoft.ML
open Microsoft.ML.Data
open Microsoft.ML.Runtime.Api
open Microsoft.ML.Transforms
open Microsoft.ML.Trainers
open System

let nativeDirectory = @"C:\Users\Isaac\.nuget\packages\microsoft.ml\0.1.0\runtimes\win-x64\native"
let nativeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\.nuget\packages\microsoft.ml\0.3.0\runtimes\win-x64\native"
Environment.SetEnvironmentVariable("Path", Environment.GetEnvironmentVariable("Path") + ";" + nativeDirectory)

let testDataPath = @"data\imdb_labelled.txt"
let testDataPath = __SOURCE_DIRECTORY__ + @"\data\imdb_labelled.txt"

type SentimentData() =
[<Column(ordinal = "0"); DefaultValue>]
Expand All @@ -22,8 +23,12 @@ type SentimentPrediction() =
[<ColumnName "PredictedLabel"; DefaultValue>]
val mutable Sentiment : bool

let _load =
[ typeof<Microsoft.ML.Runtime.Transforms.TextAnalytics>
typeof<Microsoft.ML.Runtime.FastTree.FastTree> ]

let pipeline = LearningPipeline()
pipeline.Add(TextLoader<SentimentData>(testDataPath, useHeader = false, separator = "tab"))
pipeline.Add(TextLoader(testDataPath).CreateFrom<SentimentData>(useHeader = false, separator = '\t'))
pipeline.Add(TextFeaturizer("Features", [| "SentimentText" |]))
pipeline.Add(FastTreeBinaryClassifier(NumLeaves = 5, NumTrees = 5, MinDocumentsInLeafs = 2))

Expand All @@ -36,4 +41,5 @@ let predictions =
|> model.Predict

predictions
|> Seq.iter(fun p -> printfn "%b" p.Sentiment)
|> Seq.iter(fun p -> printfn "%b" p.Sentiment)

10 changes: 0 additions & 10 deletions mlscript.fsx

This file was deleted.

1 change: 1 addition & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
source https://www.nuget.org/api/v2
frameworks: netstandard2.0, net461
generate_load_scripts: true
storage: none
nuget FSharp.Data prerelease
Expand Down
Loading