I am practicing ML .Net recently. But I got this error System.ArgumentOutOfRangeException: 'Features column 'Feature' not found Arg_ParamName_Name'
when I separated the Data Preparation Model and Trained Model for future retrain purpose. I am trying some solution from online but still can't figure out what I am missing here.
When it was all in one Model, the prediction run pretty well.
How can I get rid of it?
This is my Training and Model build Fucntion :
IEstimator<ITransformer> dataPreparationEstimatorProductRecommender =
mlContextProductRecommender.Transforms.Text.FeaturizeText(outputColumnName: "CustomerCodeFeaturized", inputColumnName: "CustomerCode")
.Append(mlContextProductRecommender.Transforms.Text.FeaturizeText(outputColumnName: "ProductCodeFeaturized", inputColumnName: "ProductCode"))
.Append(mlContextProductRecommender.Transforms.Categorical.OneHotEncoding(outputColumnName: "MonthOneHot", inputColumnName: "MonthNo")
.Append(mlContextProductRecommender.Transforms.Categorical.OneHotEncoding(outputColumnName: "WeekOneHot", inputColumnName: "WeekNo"))
.Append(mlContextProductRecommender.Transforms.Concatenate("Features", new string[] { "CustomerCodeFeaturized", "ProductCodeFeaturized", "MonthOneHot", "WeekOneHot" })));
ITransformer trainingPipelineProductRecommender = dataPreparationEstimatorProductRecommender.Fit(dataProductRecommender);
mlContextProductRecommender.Model.Save(trainingPipelineProductRecommender, dataProductRecommender.Schema, filePath: modelPath + "Product_Recommender_Data_Preparation_Model.zip");
var trainerProductRecommender = mlContextProductRecommender.BinaryClassification.Trainers.FieldAwareFactorizationMachine(labelColumnName: "Label", featureColumnName: "Features");
IDataView transformedDataProductRecommender = trainingPipelineProductRecommender.Transform(dataProductRecommender);
FieldAwareFactorizationMachinePredictionTransformer predictionModelBuildProductRecommender = trainerProductRecommender.Fit(transformedDataProductRecommender);
mlContextProductRecommender.Model.Save(predictionModelBuildProductRecommender, transformedDataProductRecommender.Schema, filePath: modelPath + "Product_Recommender_Model.zip"
This is my Prediction Function :
ITransformer dataPreparationModelProductRecommender = mlContextProductRecommender.Model.Load(modelPath + "Product_Recommender_Data_Preparation_Model.zip", out DataViewSchema dataPreparationModelProductRecommenderSchema);
ITransformer predictionModelTrainedProductRecommender = mlContextProductRecommender.Model.Load(modelPath + "Product_Recommender_Model.zip", out DataViewSchema predictionModelTrainedProductRecommenderSchema);
PredictionEngine < TransformedModelInputRecommender, ModelOutputRecommender > predictionEngineProductRecommender = mlContextProductRecommender.Model.CreatePredictionEngine<TransformedModelInputRecommender, ModelOutputRecommender>(predictionModelTrainedProductRecommender);
var sampleDataRecommend = new ModelInputRecommender
{
customerCode = customerCode_input,
monthNo = Int32.Parse(month_input),
weekNo = Int32.Parse(week_input),
productCode = product,
pass = true
};
ModelInputRecommender[] sampleDatasRecommend = new ModelInputRecommender[] { sampleDataRecommend };
IDataView idata = mlContextProductRecommender.Data.LoadFromEnumerable<ModelInputRecommender>(sampleDatasRecommend);
IDataView transformedData = dataPreparationModelProductRecommender.Transform(idata);
var trans = mlContextProductRecommender.Data.CreateEnumerable<TransformedModelInputRecommender>(transformedData, true);
var lastinput = trans.FirstOrDefault();
ModelOutputRecommender resultProductRecommender = predictionEngineProductRecommender.Predict(lastinput);