dotnet / machinelearning

ML.NET is an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
9.01k stars 1.88k forks source link

Add Examples/Samples for ML.NET #140

Closed asthana86 closed 6 years ago

asthana86 commented 6 years ago

Why Examples? To simplify getting-started for ml.net add examples for different ML tasks like regression, binary and multi-class classification. In the future examples should also demonstrate how to use different transforms, transforms with hyper-parameters, learners and more. This will allow ML.NET users to have a great getting started experience OOTB and also help build models specific to their problem sets.

What should we do? There are a few kind of examples/samples required. 1. and 2. should be available as a part of the dotnet/machinelearning/samples location. For 3. we should find a place to host them separate to this repository.

1. First Touch with ML.NET:

2. ML.NET usage:

3. End-End samples

Thoughts?

dotChris90 commented 6 years ago

Awesome! Especially the thoughts about asp.net app. For the easy examples should not forget other languages : powershell, F#, VB.NET and Python? Python has an extrem nice .NET interface. Just to show : ML.NET for any language. ;)

voronoipotato commented 6 years ago
// Learn more about F# at http://fsharp.org
open Microsoft.ML
open Microsoft.ML.Runtime.Api
open Microsoft.ML.Trainers
open Microsoft.ML.Transforms
open System

//The first four properties are inputs, the label is what you are predicting which is set in training
type IrisData() =
    [<Column("0")>] [<DefaultValue>]
    val mutable public SepalLength: float32
    [<Column("1")>] [<DefaultValue>]
    val mutable public SepalWidth: float32
    [<Column("2")>] [<DefaultValue>] 
    val mutable public PetalLength:float32
    [<Column("3")>] [<DefaultValue>]
    val mutable public PetalWidth:float32
    [<Column("4")>] [<ColumnName("Label")>] [<DefaultValue>]
    val mutable public Label:string

//Result returned from the prediction operation
type IrisPrediction() =
    [<ColumnName("PredictedLabel")>] [<DefaultValue>]
    val mutable public PredictedLabel : string

[<EntryPoint>]
let main argv =
    //Create a pipeline
    let pipeline = new LearningPipeline()
    let dataPath = "iris-data.txt"
    //Loads CSV data
    pipeline.Add(new TextLoader<IrisData>(dataPath,separator = ",")) 
    //Transforms the label into an "enum" because only numbers can be processed during training
    pipeline.Add(new Transforms.Dictionarizer("Label"))
    //Transforms all features into one vector
    pipeline.Add(new Transforms.ColumnConcatenator("Features","SepalLength", "SepalWidth", "PetalLength", "PetalWidth"))
    //applies a learning algorithm
    pipeline.Add(new Trainers.StochasticDualCoordinateAscentClassifier())
    //Transforms the label back into the original text
    pipeline.Add(new Transforms.PredictedLabelColumnOriginalValueConverter(PredictedLabelColumn = "PredictedLabel"))
    //Train the model
    let model = pipeline.Train<IrisData, IrisPrediction>()

    //Initialize the data we hope to test
    let x = IrisData()
    x.SepalLength <- 3.3f
    x.SepalWidth <- 1.6f
    x.PetalLength <- 0.2f
    x.PetalWidth <- 5.1f

    //predict the label from the trained model
    let prediction = model.Predict(x)
    printfn "Predicted flower type is: %s"  prediction.PredictedLabel
    Console.ReadLine () |> ignore
    0 // return an integer exit code

I prefixed Transforms and Trainers because I thought the organization helped.

shauheen commented 6 years ago

This work was moved to its own proper repo here. Closing the issue.

DannyZaca84 commented 5 years ago

image

I'm having this problem and I can't find a solution

gethari commented 5 years ago

image

I'm having this problem and I can't find a solution

Any update on this ? I'm facing same thing too

jwood803 commented 5 years ago

@DannyZaca84 @hariharan618 The error looks like the training data may not have any data in it, from what I can tell.

leot42 commented 5 years ago

I ran into same issue in C#. With the error of:

Microsoft.ML.Data.TextLoader+BoundLoader

Unhandled Exception: System.InvalidOperationException: Training set has 0 instances, aborting training. at Microsoft.ML.Trainers.SdcaTrainerBase3.TrainCore(IChannel ch, RoleMappedData data, LinearModelParameters predictor, Int32 weightSetCount) at Microsoft.ML.Learners.StochasticTrainerBase2.TrainModelCore(TrainContext context) at Microsoft.ML.Training.TrainerEstimatorBase2.Fit(IDataView input) at Microsoft.ML.Data.EstimatorChain1.Fit(IDataView input) at mlTut2.Program.Main(String[] args) in C:\Users******\source\repos\ml.net-quickstart\mlTut2\Program.cs:line 64

After chasing my tail for several hours I noticed that in the Iris class I wrote the Label Property to have a type of float. He doesn't seem to have done the same but it may be noteworthy due to the fact that in both cases the training set is said to have 0 instances. In my case it seemed to have been due to an inability to parse a string as a float.