Skip to content

Multi class predicted label shifted by one. #235

Closed

Description

@Ivanidzo4ka
public class Digit
{
    [Column("0")] public float Up;

    [Column("1")] public float Middle;

    [Column("2")] public float Bottom;

    [Column("3")] public float UpLeft;
    [Column("4")] public float BottomLeft;
    [Column("5")] public float TopRight;
    [Column("6")] public float BottomRight;

    [Column("7")] [ColumnName("Label")] public float Label;
}

public class DigitPrediction
{
    [ColumnName("PredictedLabel")]
    public uint ExpectedDigit;

    [ColumnName("Score")]
    public float[] Score;
}


var pipeline = new LearningPipeline();
var data = new Digit[]
{
    new Digit { Up = 1, Middle = 0, Bottom = 1, UpLeft = 1, BottomLeft = 1, TopRight = 1, BottomRight = 1, Label = 0 },
    new Digit { Up = 0, Middle = 0, Bottom = 0, UpLeft = 0, BottomLeft = 0, TopRight = 1, BottomRight = 1, Label = 1 },
    new Digit { Up = 1, Middle = 1, Bottom = 1, UpLeft = 0, BottomLeft = 1, TopRight = 1, BottomRight = 0, Label = 2 },
    new Digit { Up = 1, Middle = 1, Bottom = 1, UpLeft = 0, BottomLeft = 0, TopRight = 1, BottomRight = 1, Label = 3 },
    new Digit { Up = 0, Middle = 1, Bottom = 0, UpLeft = 1, BottomLeft = 1, TopRight = 1, BottomRight = 1, Label = 4 },
    new Digit { Up = 1, Middle = 1, Bottom = 1, UpLeft = 1, BottomLeft = 1, TopRight = 0, BottomRight = 1, Label = 5 },
    new Digit { Up = 1, Middle = 1, Bottom = 1, UpLeft = 1, BottomLeft = 1, TopRight = 0, BottomRight = 1, Label = 6 },
    new Digit { Up = 1, Middle = 0, Bottom = 0, UpLeft = 0, BottomLeft = 0, TopRight = 1, BottomRight = 1, Label = 7 },
    new Digit { Up = 1, Middle = 1, Bottom = 1, UpLeft = 1, BottomLeft = 1, TopRight = 1, BottomRight = 1, Label = 8 },
    new Digit { Up = 1, Middle = 1, Bottom = 1, UpLeft = 1, BottomLeft = 0, TopRight = 1, BottomRight = 1, Label = 9 }

};
pipeline.Add(CollectionDataSource.Create(data));
pipeline.Add(new ColumnConcatenator("Features", "Up", "Middle", "Bottom", "UpLeft", "BottomLeft", "TopRight", "BottomRight"));
pipeline.Add(new StochasticDualCoordinateAscentClassifier());
var model = pipeline.Train<Digit, DigitPrediction>();
var prediction = model.Predict(new Digit
{
    Up = 1,
    Middle = 1,
    Bottom = 1,
    UpLeft = 1,
    BottomLeft = 1,
    TopRight = 1,
    BottomRight = 1});

I have this wonderful test, but for ExpectedDigit is shifted by 1. I.e if it predict digit 9, it put 10 into expectedDigit

Activity

  1. Ivanidzo4ka commented on May 24, 2018

    @Ivanidzo4ka
    ContributorAuthor

    slightly related to #226.
    @yaeldekel @TomFinley any chance you know why it's +1?

  2. Ivanidzo4ka commented on May 24, 2018

    @Ivanidzo4ka
    ContributorAuthor

    same for clustering

  3. TomFinley commented on May 24, 2018

    @TomFinley
    Contributor

    Hi @Ivanidzo4ka ... The output is a key value, and it is important for various reasons that the default value of a key value be undefined, rather than any particular class. So if the "default" clustering were the first class.

    We probably ought to have a better story for this. Right now the API does not expose this sort of enumeration "well." A language like R has pretty deep support for this concept in the form of factors. I'm not sure how the API should expose this concept, but it's a fairly central one, so we ought to have a better story than just a uint being surfaced somewhere. (We have docs describing key values, but I wrote that more as code rather than user documentation.)

  4. Zruty0 commented on Dec 18, 2018

    @Zruty0
    Contributor

    This seems to be a documentation issue: we should document how we handle key types.

    And, by the way, this handling has actually changed along the way: as far as I remember, the key values are no longer off by 1, if you use schema comprehension to read the data via AsEnumerable<T>.

  5. shmoradims commented on Jun 7, 2019

    @shmoradims

    This is an old issue and seems to have been fixed in 1.0, as seen in this example.

  6. 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

No one assigned

    Labels

    documentationRelated to documentation of ML.NETenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions