dotnet / dotnet/machinelearning-samples
No sample for ProjectToPrincipalComponents() available: How to use it with SchemaDefinition? (System.ArgumentOutOfRangeException: 'Schema mismatch for input column')
- Dominant language
- PowerShell
- Stars
- 4.7k
- Forks
- 2.7k
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 1
Description
I am trying to transform a dataview by calculating a PCA using the method ProjectToPrincipalComponents.
Each object is defined as following:
```
public class thisItem
{
public int itemName { get; set; }
[ColumnName("Prices")]
public double[] Prices { get; set; }
}
```
Then I have a list:
```
List allItems = new();
```
I want to read this list in ML.NET:
```
var mlContext = new MLContext();
int numberOfFeatures = allItems.FirstOrDefault().Prices.Count();
SchemaDefinition schemaDef = SchemaDefinition.Create(typeof(thisItem)), SchemaDefinition.Direction.Both);
PrimitiveDataViewType itemType = ((VectorDataViewType)schemaDef["Prices"].ColumnType).ItemType;
schemaDef["Prices"].ColumnType = new VectorDataViewType(itemType, numberOfFeatures);
IDataView dataView = mlContext.Data.LoadFromEnumerable(allItems, schemaDef);
Microsoft.ML.Transforms.PrincipalComponentAnalyzer pipeline = mlContext.Transforms.ProjectToPrincipalComponents
(outputColumnName: "Prices", inputColumnName: "Prices", rank: 10, seed: 1);
ITransformer datatransf = pipeline.Fit(dataView);
```
As soon as it runs the last line, I get the error: **System.ArgumentOutOfRangeException: 'Schema mismatch for input column 'Prices': expected known-size vector of Single of two or more items, got Vector (Parameter 'inputSchema')'**
What could be wrong? I've been on this for hours, read all documentation and all github examples I found seem to be out of date.
Contributor guide
Assessment
This issue has not been assessed yet.