Skip to content

Add Examples/Samples for ML.NET  #140

Closed

Description

@asthana86

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:
- Simple, getting started, Quick-Starts, F5-able in Visual Studio/VS Code and dot-net CLI
e.g. Taxi Fare, Sentiment Analysis, Iris etc.

2. ML.NET usage:
- How to use different features in ML.NET: CV vs. train-test, using different transforms, learners etc.

3. End-End samples
- Real world apps like ASP.NET apps(eshop), Cloud Native apps demonstrating how a productized,
real world sample app will look like with ML.NET

Thoughts?

Activity

  1. dotChris90 commented on May 14, 2018

    @dotChris90

    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. ;)

  2. added this to the 0518 milestone on May 14, 2018
  3. 1 remaining item

  4. modified the milestones: 0518, 0618 on May 29, 2018
  5. voronoipotato commented on May 31, 2018

    @voronoipotato
    // 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.

  6. shauheen commented on Jul 5, 2018

    @shauheen
    Contributor

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

  7. DannyZaca84 commented on Oct 31, 2018

    @DannyZaca84

    image

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

  8. gethari commented on Dec 24, 2018

    @gethari

    image

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

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

  9. jwood803 commented on Dec 25, 2018

    @jwood803
    Contributor

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

  10. leot42 commented on Jan 28, 2019

    @leot42

    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.

  11. ghost locked as resolved and limited conversation to collaborators on Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions