示例#1
0
        public void SetupBreastCancerPipeline()
        {
            _breastCancerExample = new BreastCancerData()
            {
                Features = new[] { 5f, 1f, 1f, 1f, 2f, 1f, 3f, 1f, 1f }
            };

            string breastCancerDataPath = GetBenchmarkDataPath("breast-cancer.txt");

            var env = new MLContext(seed: 1);

            // Create text loader.
            var options = new TextLoader.Options()
            {
                Columns = new[]
                {
                    new TextLoader.Column("Label", DataKind.Boolean, 0),
                    new TextLoader.Column("Features", DataKind.Single, new[] { new TextLoader.Range(1, 9) })
                },
                HasHeader = false,
            };
            var loader = new TextLoader(env, options: options);

            IDataView data = loader.Load(breastCancerDataPath);

            var pipeline = env.BinaryClassification.Trainers.SdcaNonCalibrated(
                new SdcaNonCalibratedBinaryTrainer.Options {
                NumberOfThreads = 1, ConvergenceTolerance = 1e-2f,
            });

            var model = pipeline.Fit(data);

            _breastCancerModel = env.Model.CreatePredictionEngine <BreastCancerData, BreastCancerPrediction>(model);
        }
        public void SetupBreastCancerPipeline()
        {
            _breastCancerExample = new BreastCancerData()
            {
                Features = new[] { 5f, 1f, 1f, 1f, 2f, 1f, 3f, 1f, 1f }
            };

            string _breastCancerDataPath = BaseTestClass.GetDataPath("breast-cancer.txt");

            var env    = new MLContext(seed: 1, conc: 1);
            var reader = new TextLoader(env, columns: new[]
            {
                new TextLoader.Column("Label", DataKind.BL, 0),
                new TextLoader.Column("Features", DataKind.R4, new[] { new TextLoader.Range(1, 9) })
            },
                                        hasHeader: false
                                        );

            IDataView data = reader.Read(_breastCancerDataPath);

            var pipeline = env.BinaryClassification.Trainers.StochasticDualCoordinateAscent(
                new SdcaBinaryTrainer.Options {
                NumThreads = 1, ConvergenceTolerance = 1e-2f,
            });

            var model = pipeline.Fit(data);

            _breastCancerModel = model.CreatePredictionEngine <BreastCancerData, BreastCancerPrediction>(env);
        }
示例#3
0
        public void SetupBreastCancerPipeline()
        {
            _breastCancerExample = new BreastCancerData()
            {
                Features = new[] { 5f, 1f, 1f, 1f, 2f, 1f, 3f, 1f, 1f }
            };

            string _breastCancerDataPath = Program.GetInvariantCultureDataPath("breast-cancer.txt");

            var env    = new MLContext(seed: 1, conc: 1);
            var reader = new TextLoader(env, columns: new[]
            {
                new TextLoader.Column("Label", DataKind.BL, 0),
                new TextLoader.Column("Features", DataKind.R4, new[] { new TextLoader.Range(1, 9) })
            },
                                        hasHeader: false
                                        );

            IDataView data = reader.Read(_breastCancerDataPath);

            var pipeline = new SdcaBinaryTrainer(env, "Label", "Features", advancedSettings: (s) => { s.NumThreads = 1; s.ConvergenceTolerance = 1e-2f; });

            var model = pipeline.Fit(data);

            _breastCancerModel = model.CreatePredictionEngine <BreastCancerData, BreastCancerPrediction>(env);
        }
        public void SetupBreastCancerPipeline()
        {
            _breastCancerExample = new BreastCancerData()
            {
                Features = new[] { 5f, 1f, 1f, 1f, 2f, 1f, 3f, 1f, 1f }
            };

            string _breastCancerDataPath = Program.GetInvariantCultureDataPath("breast-cancer.txt");

            using (var env = new ConsoleEnvironment(seed: 1, conc: 1, verbose: false, sensitivity: MessageSensitivity.None, outWriter: EmptyWriter.Instance))
            {
                var reader = new TextLoader(env,
                                            new TextLoader.Arguments()
                {
                    Separator = "\t",
                    HasHeader = false,
                    Column    = new[]
                    {
                        new TextLoader.Column("Label", DataKind.BL, 0),
                        new TextLoader.Column("Features", DataKind.R4, new[] { new TextLoader.Range(1, 9) })
                    }
                });

                IDataView data = reader.Read(_breastCancerDataPath);

                var pipeline = new LinearClassificationTrainer(env, "Features", "Label", advancedSettings: (s) => { s.NumThreads = 1; s.ConvergenceTolerance = 1e-2f; });

                var model = pipeline.Fit(data);

                _breastCancerModel = model.MakePredictionFunction <BreastCancerData, BreastCancerPrediction>(env);
            }
        }
示例#5
0
        public void SetupBreastCancerPipeline()
        {
            _breastCancerExample = new BreastCancerData()
            {
                Features = new[] { 5f, 1f, 1f, 1f, 2f, 1f, 3f, 1f, 1f }
            };

            string _breastCancerDataPath = Program.GetInvariantCultureDataPath("breast-cancer.txt");

            var pipeline = new LearningPipeline();

            pipeline.Add(new TextLoader(_breastCancerDataPath).CreateFrom <BreastCancerData>(useHeader: false, separator: '\t'));
            pipeline.Add(new StochasticDualCoordinateAscentBinaryClassifier()
            {
                NumThreads = 1, ConvergenceTolerance = 1e-2f
            });

            _breastCancerModel = pipeline.Train <BreastCancerData, BreastCancerPrediction>();
        }