public MLModel(MLFeature[] features, string modelName) { this.modelName = modelName; DataSetClass = MLHelper.GenerateDataSetClass(features, modelName, $"{modelName}Namespace"); LabelClass = MLHelper.GenerateLabelClass($"{modelName}Label", $"{modelName}LabelNamespace"); this.features = features; }
public object Predict(object example) { var predictionEngine = MLHelper.GetPredictionEngine(TypesGenerator, Model); var methodInfo = predictionEngine.GetType().GetMethod("Predict", new[] { DataSetClass.ClassType }); var prediction = MLHelper.Predict(predictionEngine, DataSetClass, example); return(prediction); }
public TransformerChain <Microsoft.ML.Transforms.KeyToValueMappingTransformer> Train(MLDataRow[] dataSetRows, string labelFieldName) { this.labelFieldName = labelFieldName; List <object> generatedDataSet = CreateDataSet(dataSetRows); TypesGenerator = MLHelper.CreateTypesGenarator(DataSetClass, LabelClass); IDataView trainingDataView = MLHelper.GetDataView(TypesGenerator, generatedDataSet); trainingDataView.Schema.ToList().Add(new DataViewSchema.Column()); Model = Train(trainingDataView, labelFieldName); return(Model); }