Skip to content

The given key 'metric' was not present in the dictionary #3761

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

Closed
PeterPann23 opened this issue May 22, 2019 · 1 comment · Fixed by #3815
Closed

The given key 'metric' was not present in the dictionary #3761

PeterPann23 opened this issue May 22, 2019 · 1 comment · Fixed by #3815
Assignees
Labels
P0 Priority of the issue for triage purpose: IMPORTANT, needs to be fixed right away.

Comments

@PeterPann23
Copy link

System information

  • OS version/distro:
    Windows 10
    Windows 2012
    Windows 2019
  • .NET Version (eg., dotnet --info):
    Core 3.0 Version 3.0.100-preview5-011568
    Microsoft.ML.LightGbm Version 1.0.0.0, Culture=neutral
    Microsoft.ML Version 1.0.0.0

Issue

  • What did you do?
    Load csv file as and train model loading by all floats in single vector
    see code bellow

  • What happened?
    Get error The given key 'metric' was not present in the dictionary during the training

  • What did you expect?
    Not sure why I get the error, also I do not mention a key metric.

Source code / logs

The error:

[Source=LightGBMMulticlass; Training with LightGBM, Kind=Trace] Channel disposed. Elapsed 00:00:04.0970203
.57.erLeaf = 5059.0337420.
Error stack    at System.Collections.Generic.Dictionary`2.get_Item(TKey key)r_6_MinTicks_In_15Sec_B_ND.tsv
   at Microsoft.ML.Trainers.LightGbm.WrappedLightGbmTraining.Train(IChannel ch, IProgressChannel pch, Dictionary`2 param
eters, Dataset dtrain, Dataset dvalid, Int32 numIteration, Boolean verboseEval, Int32 earlyStoppingRound)
   at Microsoft.ML.Trainers.LightGbm.LightGbmTrainerBase`4.TrainCore(IChannel ch, IProgressChannel pch, Dataset dtrain,
CategoricalMetaData catMetaData, Dataset dvalid)
   at Microsoft.ML.Trainers.LightGbm.LightGbmTrainerBase`4.TrainModelCore(TrainContext context)
   at Microsoft.ML.Trainers.TrainerEstimatorBase`2.TrainTransformer(IDataView trainSet, IDataView validationSet, IPredic
tor initPredictor)
   at Microsoft.ML.Data.EstimatorChain`1.Fit(IDataView input)
   at Cats.DeepBookTrainer.Infrastructure.Trainer.ExecuteLightGbm(ITransformer& transformer, Nullable`1 maxIterations, N
ullable`1 maxThreads) 

Data Loading:

public static IDataView GetDataViewAsVector(MLContext mlContext, FileInfo trainingFile, int labelIndex=1, char[] separators = null, long? maxRows = null, bool makeBin=false)
{
    if (separators is null)
        separators = new[] { '|' };

    var loader = mlContext.Data.CreateTextLoader(options: new TextLoader.Options()
    {
        Columns = new[] {
            new TextLoader.Column(name:"Label", dataKind: DataKind.String, index: labelIndex),
            new TextLoader.Column(name:"RawFeatures",dataKind:DataKind.Single,minIndex:2,maxIndex:40732)
        },
        HasHeader = false,
        Separators = separators,
        UseThreads = false,
        MaxRows=maxRows
    });
    var dv = loader.Load(trainingFile.FullName);
    return dv;
}

Pipeline:

horizonDataset = mlContext.Data.TrainTestSplit(DataViewUtils.GetDataViewAsVector(mlContext, trainingFile, labelIndex: 1, separators: new[] {'|'}));

var options = new LightGbmMulticlassTrainer.Options
{
    LabelColumnName = "KeyColumn",
    FeatureColumnName = Features,
    Silent = false,
    Verbose = true,
    EvaluationMetric = LightGbmMulticlassTrainer.Options.EvaluateMetricType.Default,
    UseSoftmax       = true,
    NumberOfThreads  = 1,                
};

var featureColumns = Mapper.GetFieldNames();
var pipeline = mlContext.Transforms.Conversion.MapValueToKey(outputColumnName: "KeyColumn", inputColumnName: "Label")
        .Append(mlContext.Transforms.NormalizeMinMax(outputColumnName: "Features", inputColumnName: "RawFeatures"))
        .AppendCacheCheckpoint(mlContext)
        .Append(mlContext.MulticlassClassification.Trainers.LightGbm(options))
        .Append(mlContext.Transforms.CopyColumns(inputColumnName: "KeyColumn", outputColumnName: nameof(PredictedResult.PredictedLabelIndex)))

Line throwing the error
var model = pipeline.Fit(horizonDataset.TrainSet);

@ganik ganik added the P0 Priority of the issue for triage purpose: IMPORTANT, needs to be fixed right away. label May 23, 2019
@PeterPann23
Copy link
Author

Static constructor is always called, is it referencing another metric key in a another dictionary?
Capture

Is this related to the options specified, aka incompatible or missing, if so a exception should be raised

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P0 Priority of the issue for triage purpose: IMPORTANT, needs to be fixed right away.
Projects
None yet
3 participants