Skip to content
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

No sample for ProjectToPrincipalComponents() available: How to use it with SchemaDefinition? (System.ArgumentOutOfRangeException: 'Schema mismatch for input column') #974

Open
lucas-albs opened this issue Dec 9, 2022 · 0 comments

Comments

@lucas-albs
Copy link

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<thisItem> 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<Double, 17> (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.

@lucas-albs lucas-albs changed the title How to use ProjectToPrincipalComponents with SchemaDefinition? (System.ArgumentOutOfRangeException: 'Schema mismatch for input column') No sample for ProjectToPrincipalComponents() available: How to use it with SchemaDefinition? (System.ArgumentOutOfRangeException: 'Schema mismatch for input column') Dec 9, 2022
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

1 participant