コード例 #1
0
        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;
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }