dotnet / machinelearning

ML.NET is an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
9.05k stars 1.89k forks source link

How to use and pass runtime created class in .Model.CreatePredictionEngine(Of TRow, TDst)(loadedModel) #4559

Closed jigarhshah17 closed 4 years ago

jigarhshah17 commented 4 years ago

i have created class and its field with assign value at run time and want to pass it in (of TRow) Model.CreatePredictionEngine(Of TRow, TDst)(loadedModel)

gvashishtha commented 4 years ago

@jigarhshah17 I think your question was addressed in Gitter, please reopen if it was not addressed.

jigarhshah17 commented 4 years ago

Not solved i have created one class on run time and now i want to add attribute to field created in run time like like <Microsoft.ML.Data.ColumnName("Pressure")> so my final class in run time would be Imports Microsoft.ML.Data

Public Class PressureData

<LoadColumn(1)>
<Microsoft.ML.Data.ColumnName("Pressure")>
Public Pressure As Single

<LoadColumn(2)>
<Microsoft.ML.Data.ColumnName("PressureOnPumpDischarge")>
Public PressureOnPumpDischarge As Single

<LoadColumn(3)>
<Microsoft.ML.Data.ColumnName("TankLevel")>
Public TankLevel As Single

<LoadColumn(4)>
<Microsoft.ML.Data.ColumnName("NoOfUnderLoadingTruck")>
Public NoOfUnderLoadingTruck As Single

end class

so how to do it?

currently when i pass run time created class to createModel.CreatePredictionEngine(Of TRow, TDst)(loadedModel) then it will generate error and show me that Pressure column not find in input schema so in my view run time created class not mapped with model input schema so need to set attribute so it will map . so tell me am it right or wrong.

exception System.ArgumentOutOfRangeException: Could not find input column 'Pressure' Parameter name: inputSchema at Microsoft.ML.Data.OneToOneTransformerBase.CheckInput(DataViewSchema inputSchema, Int32 col, Int32& srcCol) at Microsoft.ML.Data.OneToOneTransformerBase.OneToOneMapperBase..ctor(IHost host, OneToOneTransformerBase parent, DataViewSchema inputSchema) at Microsoft.ML.Transforms.ColumnCopyingTransformer.Mapper..ctor(ColumnCopyingTransformer parent, DataViewSchema inputSchema, ValueTuple2[] columns) at Microsoft.ML.Transforms.ColumnCopyingTransformer.MakeRowMapper(DataViewSchema inputSchema) at Microsoft.ML.Data.RowToRowTransformerBase.Microsoft.ML.ITransformer.GetRowToRowMapper(DataViewSchema inputSchema) at Microsoft.ML.Data.TransformerChain1.Microsoft.ML.ITransformer.GetRowToRowMapper(DataViewSchema inputSchema) at Microsoft.ML.Data.TransformerChain1.Microsoft.ML.ITransformer.GetRowToRowMapper(DataViewSchema inputSchema) at Microsoft.ML.PredictionEngineBase2..ctor(IHostEnvironment env, ITransformer transformer, Boolean ignoreMissingColumns, SchemaDefinition inputSchemaDefinition, SchemaDefinition outputSchemaDefinition) at Microsoft.ML.PredictionEngineExtensions.CreatePredictionEngine[TSrc,TDst](ITransformer transformer, IHostEnvironment env, Boolean ignoreMissingColumns, SchemaDefinition inputSchemaDefinition, SchemaDefinition outputSchemaDefinition)

jigarhshah17 commented 4 years ago

@jigarhshah17 I think your question was addressed in Gitter, please reopen if it was not addressed.

https://github.com/dotnet/machinelearning/issues/4559#issuecomment-564409635