예제 #1
0
        public void TestEstimatorMulticlassLogisticRegression()
        {
            (IEstimator <ITransformer> pipe, IDataView dataView) = GetMultiClassPipeline();
            var trainer         = new MulticlassLogisticRegression(Env, "Label", "Features");
            var pipeWithTrainer = pipe.Append(trainer);

            TestEstimatorCore(pipeWithTrainer, dataView);

            var transformedDataView = pipe.Fit(dataView).Transform(dataView);
            var model = trainer.Fit(transformedDataView);

            trainer.Train(transformedDataView, model.Model);
            Done();
        }
예제 #2
0
 public Arguments()
 {
     BasePredictors = new[]
     {
         ComponentFactoryUtils.CreateFromFunction(
             env => {
             // Note that this illustrates a fundamnetal problem with the mixture of `ITrainer` and `ITrainerEstimator`
             // present in this class. The options to the estimator have no way of being communicated to the `ITrainer`
             // implementation, so there is a fundamnetal disconnect if someone chooses to ever use the *estimator* with
             // non-default column names. Unfortuantely no method of resolving this temporary strikes me as being any
             // less laborious than the proper fix, which is that this "meta" component should itself be a trainer
             // estimator, as opposed to a regular trainer.
             var trainerEstimator = new MulticlassLogisticRegression(env, LabelColumn, FeatureColumn);
             return(TrainerUtils.MapTrainerEstimatorToTrainer <MulticlassLogisticRegression,
                                                               MulticlassLogisticRegressionModelParameters, MulticlassLogisticRegressionModelParameters>(env, trainerEstimator));
         })
     };
 }
예제 #3
0
파일: debug.cs 프로젝트: sdpython/csharpyml
        public void Train(string dest)
        {
            using (var env = new ConsoleEnvironment(verbose: false))
            {
                var args = new TextLoader.Arguments()
                {
                    Separator = ",",
                    HasHeader = true,
                    Column    = new TextLoader.Column[] {
                        new TextLoader.Column("Label", DataKind.R4, 0),
                        new TextLoader.Column("Sepal_length", DataKind.R4, 1),
                        new TextLoader.Column("Sepal_width", DataKind.R4, 2),
                        new TextLoader.Column("Petal_length", DataKind.R4, 3),
                        new TextLoader.Column("Petal_width", DataKind.R4, 4),
                    }
                };

                var reader = new TextLoader(env, args);
                var concat = new ColumnConcatenatingEstimator(env,
                                                              "Features", "Sepal_length",
                                                              "Sepal_width", "Petal_length", "Petal_width");
                var km       = new MulticlassLogisticRegression(env, "Label", "Features");
                var pipeline = concat.Append(km);

                IDataView trainingDataView = reader.Read(new MultiFileSource(_dataset));
                var       model            = pipeline.Fit(trainingDataView);

                var obs = new IrisObservation()
                {
                    Sepal_length = 3.3f,
                    Sepal_width  = 1.6f,
                    Petal_length = 0.2f,
                    Petal_width  = 5.1f,
                };

                _fct = model.MakePredictionFunction <IrisObservation, IrisPrediction>(env);
                using (var stdest = File.OpenWrite(dest))
                    model.SaveTo(env, stdest);
            }
        }