Skip to content

LogisticRegression example using MNIST #327

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
matnatx opened this issue Mar 22, 2019 · 3 comments
Closed

LogisticRegression example using MNIST #327

matnatx opened this issue Mar 22, 2019 · 3 comments

Comments

@matnatx
Copy link

matnatx commented Mar 22, 2019

I am trying to change MNIST example that uses the StochasticDualCoordinateAscent to use LogisticRegression instead but get the following exception thrown:

Schema mismatch for label column '': expected Key, got R4
Parameter name: labelCol

Does anyone know what this means and how I can fix this?

I only changed:

var trainer = mLContext.MulticlassClassification.Trainers.StochasticDualCoordinateAscent(labelColumnName: "Number", featureColumnName: DefaultColumnNames.Features);

To:

var trainer = mLContext.MulticlassClassification.Trainers.LogisticRegression(labelColumnName: "Number", featureColumnName: DefaultColumnNames.Features);

Thanks!

@prathyusha12345
Copy link
Contributor

@matnatx The issue is we need to convert/map label column "Number" to a key using MapValueToKey() method during transformation so that the values of label column "Number" are converted into Numerical values and stored in key. (refer to this Microsoft documentation to know details of this API here

Ex:  var dataProcessPipeline = mLContext.Transforms.Concatenate(DefaultColumnNames.Features, nameof(InputData.PixelValues)).AppendCacheCheckpoint(mLContext)
                    .Append(mLContext.Transforms.Conversion.MapValueToKey(outputColumnName: "keyName", inputColumnName: "Number"));

we need to use the name of key as LabelColumnName in the training algorithm.

var trainer = mLContext.MulticlassClassification.Trainers.LogisticRegression(labelColumnName: "keyName", featureColumnName: DefaultColumnNames.Features);

After appending the trainer to pipeLine you can convert back the key to label column.

var trainingPipeline = dataProcessPipeline.Append(trainer).Append(mLContext.Transforms.Conversion.MapKeyToValue("keyName"));

In SDCA trainer the mapping is done automatically. But for all other MultiClassClassification trainers we need to do explicit mapping of label.

For more details please see the issues dotnet/machinelearning#2656, dotnet/machinelearning#2628, dotnet/machinelearning#3060 related to this.

Please try the above code and Let me know if you still face any issue, ok?

Adding @CESARDELATORRE for reference.

@matnatx
Copy link
Author

matnatx commented Mar 25, 2019

The suggested code works!

Many Thanks.

@matnatx matnatx closed this as completed Mar 25, 2019
@ambishaw
Copy link

ambishaw commented Sep 5, 2021

@prathyusha12345 Thank you very much! This was very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants