Ejemplo n.º 1
0
        public void New_ReconfigurablePrediction()
        {
            var dataPath     = GetDataPath(SentimentDataPath);
            var testDataPath = GetDataPath(SentimentTestPath);

            using (var env = new LocalEnvironment(seed: 1, conc: 1))
            {
                var dataReader = new TextLoader(env, MakeSentimentTextLoaderArgs());

                var data     = dataReader.Read(new MultiFileSource(dataPath));
                var testData = dataReader.Read(new MultiFileSource(testDataPath));

                // Pipeline.
                var pipeline = new TextTransform(env, "SentimentText", "Features")
                               .Fit(data);

                var trainer = new LinearClassificationTrainer(env, new LinearClassificationTrainer.Arguments {
                    NumThreads = 1
                }, "Features", "Label");
                var trainData = pipeline.Transform(data);
                var model     = trainer.Fit(trainData);

                var scoredTest = model.Transform(pipeline.Transform(testData));
                var metrics    = new MyBinaryClassifierEvaluator(env, new BinaryClassifierEvaluator.Arguments()).Evaluate(scoredTest, "Label", "Probability");

                var newModel      = new BinaryPredictionTransformer <IPredictorProducing <float> >(env, model.Model, trainData.Schema, model.FeatureColumn, threshold: 0.01f, thresholdColumn: DefaultColumnNames.Probability);
                var newScoredTest = newModel.Transform(pipeline.Transform(testData));
                var newMetrics    = new MyBinaryClassifierEvaluator(env, new BinaryClassifierEvaluator.Arguments {
                    Threshold = 0.01f, UseRawScoreThreshold = false
                }).Evaluate(newScoredTest, "Label", "Probability");
            }
        }