dotnet / dotnet/machinelearning

AutoML + Can't create PredictionEngine because of type error

Open
#5,613 1 comment 0 reactions 0 assignees View on GitHub
area-AutoML Priority:2
Dominant language
C#
Stars
9.4k
Forks
2k
Avg merge
2d 20h
Merged PRs (30d)
11

Description

### System information

- **Windows 10.0.19042**:
- **.NET 3.1.11**:

### Issue

- **What did you do?**
I'm using AutoML to train and save a model. When I try to create a `PredictionEngine` it complains about the schema.
- **What happened?**
I successfully generated a model from a combination of bool, string, and float columns. When I recall that model and try and instantiate a PredictionEngine, the main string property causes an InvalidOperationException because it is expecting type `Vector` instead of `System.String`.
- **What did you expect?**
Like my other models that use strings, I expected that it would work fine with the strings.
### Source code / logs
```c#
public class FBResultData
{
[LoadColumn(0)]
public string EventValue { get; set; }
.......
[LoadColumn(14), ColumnName("Label")]
public bool NotificationSent { get; set; }
}
```
```c#
public IDataView LoadFBResultData(MLContext mlContext)
{

//loads data into a List
var data = GetFBData();

IDataView dataView = mlContext.Data.LoadFromEnumerable(data,
SchemaDefinition.Create(typeof(FBResultData), SchemaDefinition.Direction.Both));

return dataView;
}
```
```c#
public ContextAnalyzerService()
{

_fbContext = new MLContext();
_fbModel =
_fbContext.Model.Load(GetModel(ModelType.FBResult), out schema);

}

public FBResultDataPrediction AnalyzeFB(FBResultData result)
{
var res = new ContextResult();
//the line below produces an InvalidOperationException
var predictionFunction = _fbContext.Model.CreatePredictionEngine(_fbModel);
return sentiment;
}
```

Please paste or attach the code or logs or traces that would be helpful to diagnose the issue you are reporting.
![image](https://user-images.githubusercontent.com/5253107/107266085-070ac000-6a13-11eb-93d5-9b38e0788a22.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.