コード例 #1
0
ファイル: TestSnippet.cs プロジェクト: sdpython/csharpyml
            public IrisPrediction Predict(double sl, double sw, double pl, double pw)
            {
                var obs = new IrisObservation()
                {
                    Sepal_length = (float)sl,
                    Sepal_width  = (float)sw,
                    Petal_length = (float)pl,
                    Petal_width  = (float)pw,
                };

                return(_fct.Predict(obs));
            }
コード例 #2
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);
            }
        }