Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of <see cref="LightGbmMulticlassTrainer"/>
 /// </summary>
 /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="labelColumn">The name of The label column.</param>
 /// <param name="featureColumn">The name of the feature column.</param>
 /// <param name="weights">The name for the column containing the initial weight.</param>
 /// <param name="numLeaves">The number of leaves to use.</param>
 /// <param name="numBoostRound">Number of iterations.</param>
 /// <param name="minDataPerLeaf">The minimal number of documents allowed in a leaf of the tree, out of the subsampled data.</param>
 /// <param name="learningRate">The learning rate.</param>
 internal LightGbmMulticlassTrainer(IHostEnvironment env,
                                    string labelColumn   = DefaultColumnNames.Label,
                                    string featureColumn = DefaultColumnNames.Features,
                                    string weights       = null,
                                    int?numLeaves        = null,
                                    int?minDataPerLeaf   = null,
                                    double?learningRate  = null,
                                    int numBoostRound    = LightGBM.Options.Defaults.NumBoostRound)
     : base(env, LoadNameValue, TrainerUtils.MakeU4ScalarColumn(labelColumn), featureColumn, weights, null, numLeaves, minDataPerLeaf, learningRate, numBoostRound)
 {
     _numClass = -1;
 }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of <see cref="LightGbmMulticlassClassificationTrainer"/>
 /// </summary>
 /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="labelColumnName">The name of The label column.</param>
 /// <param name="featureColumnName">The name of the feature column.</param>
 /// <param name="exampleWeightColumnName">The name of the example weight column (optional).</param>
 /// <param name="numberOfLeaves">The number of leaves to use.</param>
 /// <param name="minimumExampleCountPerLeaf">The minimal number of data points allowed in a leaf of the tree, out of the subsampled data.</param>
 /// <param name="learningRate">The learning rate.</param>
 /// <param name="numberOfIterations">The number of iterations to use.</param>
 internal LightGbmMulticlassClassificationTrainer(IHostEnvironment env,
                                                  string labelColumnName         = DefaultColumnNames.Label,
                                                  string featureColumnName       = DefaultColumnNames.Features,
                                                  string exampleWeightColumnName = null,
                                                  int?numberOfLeaves             = null,
                                                  int?minimumExampleCountPerLeaf = null,
                                                  double?learningRate            = null,
                                                  int numberOfIterations         = Trainers.LightGbm.Options.Defaults.NumberOfIterations)
     : base(env, LoadNameValue, TrainerUtils.MakeU4ScalarColumn(labelColumnName), featureColumnName, exampleWeightColumnName, null, numberOfLeaves, minimumExampleCountPerLeaf, learningRate, numberOfIterations)
 {
     _numClass = -1;
 }
 /// <summary>
 /// Initializes a new instance of <see cref="LightGbmMulticlassTrainer"/>
 /// </summary>
 /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="labelColumn">The name of the label column.</param>
 /// <param name="featureColumn">The name of the feature column.</param>
 /// <param name="weightColumn">The name for the column containing the initial weight.</param>
 /// <param name="numLeaves">The number of leaves to use.</param>
 /// <param name="numBoostRound">Number of iterations.</param>
 /// <param name="minDataPerLeaf">The minimal number of documents allowed in a leaf of the tree, out of the subsampled data.</param>
 /// <param name="learningRate">The learning rate.</param>
 /// <param name="advancedSettings">A delegate to set more settings.
 /// The settings here will override the ones provided in the direct signature,
 /// if both are present and have different values.
 /// The columns names, however need to be provided directly, not through the <paramref name="advancedSettings"/>.</param>
 public LightGbmMulticlassTrainer(IHostEnvironment env,
                                  string labelColumn,
                                  string featureColumn,
                                  string weightColumn = null,
                                  int?numLeaves       = null,
                                  int?minDataPerLeaf  = null,
                                  double?learningRate = null,
                                  int numBoostRound   = LightGbmArguments.Defaults.NumBoostRound,
                                  Action <LightGbmArguments> advancedSettings = null)
     : base(env, LoadNameValue, TrainerUtils.MakeU4ScalarColumn(labelColumn), featureColumn, weightColumn, null, numLeaves, minDataPerLeaf, learningRate, numBoostRound, advancedSettings)
 {
     _numClass = -1;
 }
        /// <summary>
        /// Initializes a new instance of <see cref="MulticlassLogisticRegression"/>
        /// </summary>
        /// <param name="env">The environment to use.</param>
        /// <param name="labelColumn">The name of the label column.</param>
        /// <param name="featureColumn">The name of the feature column.</param>
        /// <param name="weights">The name for the example weight column.</param>
        /// <param name="enforceNoNegativity">Enforce non-negative weights.</param>
        /// <param name="l1Weight">Weight of L1 regularizer term.</param>
        /// <param name="l2Weight">Weight of L2 regularizer term.</param>
        /// <param name="memorySize">Memory size for <see cref="LogisticRegression"/>. Low=faster, less accurate.</param>
        /// <param name="optimizationTolerance">Threshold for optimizer convergence.</param>
        internal MulticlassLogisticRegression(IHostEnvironment env,
                                              string labelColumn          = DefaultColumnNames.Label,
                                              string featureColumn        = DefaultColumnNames.Features,
                                              string weights              = null,
                                              float l1Weight              = Options.Defaults.L1Weight,
                                              float l2Weight              = Options.Defaults.L2Weight,
                                              float optimizationTolerance = Options.Defaults.OptTol,
                                              int memorySize              = Options.Defaults.MemorySize,
                                              bool enforceNoNegativity    = Options.Defaults.EnforceNonNegativity)
            : base(env, featureColumn, TrainerUtils.MakeU4ScalarColumn(labelColumn), weights, l1Weight, l2Weight, optimizationTolerance, memorySize, enforceNoNegativity)
        {
            Host.CheckNonEmpty(featureColumn, nameof(featureColumn));
            Host.CheckNonEmpty(labelColumn, nameof(labelColumn));

            ShowTrainingStats = Args.ShowTrainingStats;
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of <see cref="MulticlassLogisticRegression"/>
        /// </summary>
        /// <param name="env">The environment to use.</param>
        /// <param name="labelColumn">The name of the label column.</param>
        /// <param name="featureColumn">The name of the feature column.</param>
        /// <param name="weightColumn">The name for the example weight column.</param>
        /// <param name="enforceNoNegativity">Enforce non-negative weights.</param>
        /// <param name="l1Weight">Weight of L1 regularizer term.</param>
        /// <param name="l2Weight">Weight of L2 regularizer term.</param>
        /// <param name="memorySize">Memory size for <see cref="LogisticRegression"/>. Lower=faster, less accurate.</param>
        /// <param name="optimizationTolerance">Threshold for optimizer convergence.</param>
        /// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
        public MulticlassLogisticRegression(IHostEnvironment env, string featureColumn, string labelColumn,
                                            string weightColumn                 = null,
                                            float l1Weight                      = Arguments.Defaults.L1Weight,
                                            float l2Weight                      = Arguments.Defaults.L2Weight,
                                            float optimizationTolerance         = Arguments.Defaults.OptTol,
                                            int memorySize                      = Arguments.Defaults.MemorySize,
                                            bool enforceNoNegativity            = Arguments.Defaults.EnforceNonNegativity,
                                            Action <Arguments> advancedSettings = null)
            : base(env, featureColumn, TrainerUtils.MakeU4ScalarColumn(labelColumn), weightColumn, advancedSettings,
                   l1Weight, l2Weight, optimizationTolerance, memorySize, enforceNoNegativity)
        {
            Host.CheckNonEmpty(featureColumn, nameof(featureColumn));
            Host.CheckNonEmpty(labelColumn, nameof(labelColumn));

            ShowTrainingStats = Args.ShowTrainingStats;
        }
 /// <summary>
 /// Initializes a new instance of <see cref="MulticlassLogisticRegression"/>
 /// </summary>
 internal MulticlassLogisticRegression(IHostEnvironment env, Options options)
     : base(env, options, TrainerUtils.MakeU4ScalarColumn(options.LabelColumn))
 {
     ShowTrainingStats = Args.ShowTrainingStats;
 }
Esempio n. 7
0
 internal LightGbmMulticlassTrainer(IHostEnvironment env, Options options)
     : base(env, LoadNameValue, options, TrainerUtils.MakeU4ScalarColumn(options.LabelColumnName))
 {
     Contracts.CheckUserArg(options.Sigmoid > 0, nameof(Options.Sigmoid), "must be > 0.");
     _numClass = -1;
 }
        private protected LightGbmTrainerBase(IHostEnvironment env, string name, Options options, SchemaShape.Column label)
            : base(Contracts.CheckRef(env, nameof(env)).Register(name), TrainerUtils.MakeR4VecFeature(options.FeatureColumnName), label,
                   TrainerUtils.MakeR4ScalarWeightColumn(options.ExampleWeightColumnName), TrainerUtils.MakeU4ScalarColumn(options.RowGroupColumnName))
        {
            Host.CheckValue(options, nameof(options));

            LightGbmTrainerOptions = options;
            InitParallelTraining();
        }
        private protected LightGbmTrainerBase(IHostEnvironment env,
                                              string name,
                                              SchemaShape.Column labelColumn,
                                              string featureColumnName,
                                              string exampleWeightColumnName,
                                              string rowGroupColumnName,
                                              int?numberOfLeaves,
                                              int?minimumExampleCountPerLeaf,
                                              double?learningRate,
                                              int numberOfIterations)
            : base(Contracts.CheckRef(env, nameof(env)).Register(name), TrainerUtils.MakeR4VecFeature(featureColumnName),
                   labelColumn, TrainerUtils.MakeR4ScalarWeightColumn(exampleWeightColumnName), TrainerUtils.MakeU4ScalarColumn(rowGroupColumnName))
        {
            LightGbmTrainerOptions = new Options();

            LightGbmTrainerOptions.NumberOfLeaves             = numberOfLeaves;
            LightGbmTrainerOptions.MinimumExampleCountPerLeaf = minimumExampleCountPerLeaf;
            LightGbmTrainerOptions.LearningRate       = learningRate;
            LightGbmTrainerOptions.NumberOfIterations = numberOfIterations;

            LightGbmTrainerOptions.LabelColumnName         = labelColumn.Name;
            LightGbmTrainerOptions.FeatureColumnName       = featureColumnName;
            LightGbmTrainerOptions.ExampleWeightColumnName = exampleWeightColumnName;
            LightGbmTrainerOptions.RowGroupColumnName      = rowGroupColumnName;

            InitParallelTraining();
        }
Esempio n. 10
0
        private protected LightGbmTrainerBase(IHostEnvironment env,
                                              string name,
                                              SchemaShape.Column label,
                                              string featureColumn,
                                              string weightColumn,
                                              string groupIdColumn,
                                              int?numLeaves,
                                              int?minDataPerLeaf,
                                              double?learningRate,
                                              int numBoostRound)
            : base(Contracts.CheckRef(env, nameof(env)).Register(name), TrainerUtils.MakeR4VecFeature(featureColumn), label, TrainerUtils.MakeR4ScalarWeightColumn(weightColumn), TrainerUtils.MakeU4ScalarColumn(groupIdColumn))
        {
            Args = new Options();

            Args.NumLeaves      = numLeaves;
            Args.MinDataPerLeaf = minDataPerLeaf;
            Args.LearningRate   = learningRate;
            Args.NumBoostRound  = numBoostRound;

            Args.LabelColumn   = label.Name;
            Args.FeatureColumn = featureColumn;

            if (weightColumn != null)
            {
                Args.WeightColumn = Optional <string> .Explicit(weightColumn);
            }

            if (groupIdColumn != null)
            {
                Args.GroupIdColumn = Optional <string> .Explicit(groupIdColumn);
            }

            InitParallelTraining();
        }
Esempio n. 11
0
 internal LightGbmMulticlassClassificationTrainer(IHostEnvironment env, Options options)
     : base(env, LoadNameValue, options, TrainerUtils.MakeU4ScalarColumn(options.LabelColumnName))
 {
     _numClass = -1;
 }
        private protected LightGbmTrainerBase(IHostEnvironment env,
                                              string name,
                                              SchemaShape.Column label,
                                              string featureColumn,
                                              string weightColumn,
                                              string groupIdColumn,
                                              int?numLeaves,
                                              int?minDataPerLeaf,
                                              double?learningRate,
                                              int numBoostRound)
            : base(Contracts.CheckRef(env, nameof(env)).Register(name), TrainerUtils.MakeR4VecFeature(featureColumn), label, TrainerUtils.MakeR4ScalarWeightColumn(weightColumn), TrainerUtils.MakeU4ScalarColumn(groupIdColumn))
        {
            LightGbmTrainerOptions = new Options();

            LightGbmTrainerOptions.NumLeaves      = numLeaves;
            LightGbmTrainerOptions.MinDataPerLeaf = minDataPerLeaf;
            LightGbmTrainerOptions.LearningRate   = learningRate;
            LightGbmTrainerOptions.NumBoostRound  = numBoostRound;

            LightGbmTrainerOptions.LabelColumnName         = label.Name;
            LightGbmTrainerOptions.FeatureColumnName       = featureColumn;
            LightGbmTrainerOptions.ExampleWeightColumnName = weightColumn;
            LightGbmTrainerOptions.RowGroupColumnName      = groupIdColumn;

            InitParallelTraining();
        }