/// <summary>
        /// FastTree <see cref="RankingCatalog"/>.
        /// Ranks a series of inputs based on their relevance, training a decision tree ranking model through the <see cref="FastTreeRankingTrainer"/>.
        /// </summary>
        /// <param name="catalog">The <see cref="RegressionCatalog"/>.</param>
        /// <param name="label">The label column.</param>
        /// <param name="features">The features column.</param>
        /// <param name="groupId">The groupId column.</param>
        /// <param name="weights">The optional weights column.</param>
        /// <param name="options">Algorithm advanced settings.</param>
        /// <param name="onFit">A delegate that is called every time the
        /// <see cref="Estimator{TInShape, TOutShape, TTransformer}.Fit(DataView{TInShape})"/> method is called on the
        /// <see cref="Estimator{TInShape, TOutShape, TTransformer}"/> instance created out of this. This delegate will receive
        /// the linear model that was trained. Note that this action cannot change the result in any way;
        /// it is only a way for the caller to be informed about what was learnt.</param>
        /// <returns>The Score output column indicating the predicted value.</returns>
        public static Scalar <float> FastTree <TVal>(this RankingCatalog.RankingTrainers catalog,
                                                     Scalar <float> label, Vector <float> features, Key <uint, TVal> groupId, Scalar <float> weights,
                                                     FastTreeRankingTrainer.Options options,
                                                     Action <FastTreeRankingModelParameters> onFit = null)
        {
            Contracts.CheckValueOrNull(options);
            CheckUserValues(label, features, weights, onFit);

            var rec = new TrainerEstimatorReconciler.Ranker <TVal>(
                (env, labelName, featuresName, groupIdName, weightsName) =>
            {
                options.LabelColumnName         = labelName;
                options.FeatureColumnName       = featuresName;
                options.RowGroupColumnName      = groupIdName;
                options.ExampleWeightColumnName = weightsName;

                var trainer = new FastTreeRankingTrainer(env, options);
                if (onFit != null)
                {
                    return(trainer.WithOnFitDelegate(trans => onFit(trans.Model)));
                }
                return(trainer);
            }, label, features, groupId, weights);

            return(rec.Score);
        }
Example #2
0
        /// <summary>
        /// Ranks a series of inputs based on their relevance, training a decision tree ranking model through the <see cref="LightGbmRankingTrainer"/>.
        /// </summary>
        /// <param name="catalog">The <see cref="RankingCatalog"/>.</param>
        /// <param name="label">The label column.</param>
        /// <param name="features">The features column.</param>
        /// <param name="groupId">The groupId column.</param>
        /// <param name="weights">The weights column.</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">Number of iterations.</param>
        /// <param name="onFit">A delegate that is called every time the
        /// <see cref="Estimator{TInShape, TOutShape, TTransformer}.Fit(DataView{TInShape})"/> method is called on the
        /// <see cref="Estimator{TInShape, TOutShape, TTransformer}"/> instance created out of this. This delegate will receive
        /// the linear model that was trained. Note that this action cannot change the result in any way;
        /// it is only a way for the caller to be informed about what was learnt.</param>
        /// <returns>The set of output columns including in order the predicted binary classification score (which will range
        /// from negative to positive infinity), the calibrated prediction (from 0 to 1), and the predicted label.</returns>
        public static Scalar <float> LightGbm <TVal>(this RankingCatalog.RankingTrainers catalog,
                                                     Scalar <float> label,
                                                     Vector <float> features,
                                                     Key <uint, TVal> groupId,
                                                     Scalar <float> weights         = null,
                                                     int?numberOfLeaves             = null,
                                                     int?minimumExampleCountPerLeaf = null,
                                                     double?learningRate            = null,
                                                     int numberOfIterations         = Options.Defaults.NumberOfIterations,
                                                     Action <LightGbmRankingModelParameters> onFit = null)
        {
            CheckUserValues(label, features, weights, numberOfLeaves, minimumExampleCountPerLeaf, learningRate, numberOfIterations, onFit);
            Contracts.CheckValue(groupId, nameof(groupId));

            var rec = new TrainerEstimatorReconciler.Ranker <TVal>(
                (env, labelName, featuresName, groupIdName, weightsName) =>
            {
                var trainer = new LightGbmRankingTrainer(env, labelName, featuresName, groupIdName, weightsName, numberOfLeaves,
                                                         minimumExampleCountPerLeaf, learningRate, numberOfIterations);

                if (onFit != null)
                {
                    return(trainer.WithOnFitDelegate(trans => onFit(trans.Model)));
                }
                return(trainer);
            }, label, features, groupId, weights);

            return(rec.Score);
        }
Example #3
0
        /// <summary>
        /// Ranks a series of inputs based on their relevance, training a decision tree ranking model through the <see cref="LightGbmRankingTrainer"/>.
        /// </summary>
        /// <param name="ctx">The <see cref="RankingContext"/>.</param>
        /// <param name="label">The label column.</param>
        /// <param name="features">The features column.</param>
        /// <param name="groupId">The groupId column.</param>
        /// <param name="weights">The weights column.</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">Algorithm advanced settings.</param>
        /// <param name="onFit">A delegate that is called every time the
        /// <see cref="Estimator{TInShape, TOutShape, TTransformer}.Fit(DataView{TInShape})"/> method is called on the
        /// <see cref="Estimator{TInShape, TOutShape, TTransformer}"/> instance created out of this. This delegate will receive
        /// the linear model that was trained. Note that this action cannot change the result in any way;
        /// it is only a way for the caller to be informed about what was learnt.</param>
        /// <returns>The set of output columns including in order the predicted binary classification score (which will range
        /// from negative to positive infinity), the calibrated prediction (from 0 to 1), and the predicted label.</returns>
        public static Scalar <float> LightGbm <TVal>(this RankingContext.RankingTrainers ctx,
                                                     Scalar <float> label, Vector <float> features, Key <uint, TVal> groupId, Scalar <float> weights = null,
                                                     int?numLeaves       = null,
                                                     int?minDataPerLeaf  = null,
                                                     double?learningRate = null,
                                                     int numBoostRound   = LightGbmArguments.Defaults.NumBoostRound,
                                                     Action <LightGbmArguments> advancedSettings   = null,
                                                     Action <LightGbmRankingModelParameters> onFit = null)
        {
            CheckUserValues(label, features, weights, numLeaves, minDataPerLeaf, learningRate, numBoostRound, advancedSettings, onFit);
            Contracts.CheckValue(groupId, nameof(groupId));

            var rec = new TrainerEstimatorReconciler.Ranker <TVal>(
                (env, labelName, featuresName, groupIdName, weightsName) =>
            {
                var trainer = new LightGbmRankingTrainer(env, labelName, featuresName, groupIdName, weightsName, numLeaves,
                                                         minDataPerLeaf, learningRate, numBoostRound, advancedSettings);

                if (onFit != null)
                {
                    return(trainer.WithOnFitDelegate(trans => onFit(trans.Model)));
                }
                return(trainer);
            }, label, features, groupId, weights);

            return(rec.Score);
        }
Example #4
0
        /// <summary>
        /// Ranks a series of inputs based on their relevance, training a decision tree ranking model through the <see cref="LightGbmRankingTrainer"/>.
        /// </summary>
        /// <param name="catalog">The <see cref="RankingCatalog"/>.</param>
        /// <param name="label">The label column.</param>
        /// <param name="features">The features column.</param>
        /// <param name="groupId">The groupId column.</param>
        /// <param name="weights">The weights column.</param>
        /// <param name="options">Algorithm advanced settings.</param>
        /// <param name="onFit">A delegate that is called every time the
        /// <see cref="Estimator{TInShape, TOutShape, TTransformer}.Fit(DataView{TInShape})"/> method is called on the
        /// <see cref="Estimator{TInShape, TOutShape, TTransformer}"/> instance created out of this. This delegate will receive
        /// the linear model that was trained. Note that this action cannot change the result in any way;
        /// it is only a way for the caller to be informed about what was learnt.</param>
        /// <returns>The set of output columns including in order the predicted binary classification score (which will range
        /// from negative to positive infinity), the calibrated prediction (from 0 to 1), and the predicted label.</returns>
        public static Scalar <float> LightGbm <TVal>(this RankingCatalog.RankingTrainers catalog,
                                                     Scalar <float> label, Vector <float> features, Key <uint, TVal> groupId, Scalar <float> weights,
                                                     Options options,
                                                     Action <LightGbmRankingModelParameters> onFit = null)
        {
            CheckUserValues(label, features, weights, options, onFit);
            Contracts.CheckValue(groupId, nameof(groupId));

            var rec = new TrainerEstimatorReconciler.Ranker <TVal>(
                (env, labelName, featuresName, groupIdName, weightsName) =>
            {
                options.LabelColumn   = labelName;
                options.FeatureColumn = featuresName;
                options.GroupIdColumn = groupIdName;
                options.WeightColumn  = weightsName != null ? Optional <string> .Explicit(weightsName) : Optional <string> .Implicit(DefaultColumnNames.Weight);

                var trainer = new LightGbmRankingTrainer(env, options);

                if (onFit != null)
                {
                    return(trainer.WithOnFitDelegate(trans => onFit(trans.Model)));
                }
                return(trainer);
            }, label, features, groupId, weights);

            return(rec.Score);
        }
        /// <summary>
        /// FastTree <see cref="RankingContext"/>.
        /// Ranks a series of inputs based on their relevance, training a decision tree ranking model through the <see cref="FastTreeRankingTrainer"/>.
        /// </summary>
        /// <param name="ctx">The <see cref="RegressionContext"/>.</param>
        /// <param name="label">The label column.</param>
        /// <param name="features">The features column.</param>
        /// <param name="groupId">The groupId column.</param>
        /// <param name="weights">The optional weights column.</param>
        /// <param name="numTrees">Total number of decision trees to create in the ensemble.</param>
        /// <param name="numLeaves">The maximum number of leaves per decision tree.</param>
        /// <param name="minDatapointsInLeaves">The minimal number of datapoints allowed in a leaf of a regression tree, out of the subsampled data.</param>
        /// <param name="learningRate">The learning rate.</param>
        /// <param name="advancedSettings">Algorithm advanced settings.</param>
        /// <param name="onFit">A delegate that is called every time the
        /// <see cref="Estimator{TInShape, TOutShape, TTransformer}.Fit(DataView{TInShape})"/> method is called on the
        /// <see cref="Estimator{TInShape, TOutShape, TTransformer}"/> instance created out of this. This delegate will receive
        /// the linear model that was trained. Note that this action cannot change the result in any way;
        /// it is only a way for the caller to be informed about what was learnt.</param>
        /// <returns>The Score output column indicating the predicted value.</returns>
        public static Scalar <float> FastTree <TVal>(this RankingContext.RankingTrainers ctx,
                                                     Scalar <float> label, Vector <float> features, Key <uint, TVal> groupId, Scalar <float> weights = null,
                                                     int numLeaves             = Defaults.NumLeaves,
                                                     int numTrees              = Defaults.NumTrees,
                                                     int minDatapointsInLeaves = Defaults.MinDocumentsInLeaves,
                                                     double learningRate       = Defaults.LearningRates,
                                                     Action <FastTreeRankingTrainer.Arguments> advancedSettings = null,
                                                     Action <FastTreeRankingModelParameters> onFit = null)
        {
            CheckUserValues(label, features, weights, numLeaves, numTrees, minDatapointsInLeaves, learningRate, advancedSettings, onFit);

            var rec = new TrainerEstimatorReconciler.Ranker <TVal>(
                (env, labelName, featuresName, groupIdName, weightsName) =>
            {
                var trainer = new FastTreeRankingTrainer(env, labelName, featuresName, groupIdName, weightsName, numLeaves,
                                                         numTrees, minDatapointsInLeaves, learningRate, advancedSettings);
                if (onFit != null)
                {
                    return(trainer.WithOnFitDelegate(trans => onFit(trans.Model)));
                }
                return(trainer);
            }, label, features, groupId, weights);

            return(rec.Score);
        }
        /// <summary>
        /// FastTree <see cref="RankingCatalog"/>.
        /// Ranks a series of inputs based on their relevance, training a decision tree ranking model through the <see cref="FastTreeRankingTrainer"/>.
        /// </summary>
        /// <param name="catalog">The <see cref="RegressionCatalog"/>.</param>
        /// <param name="label">The label column.</param>
        /// <param name="features">The features column.</param>
        /// <param name="groupId">The groupId column.</param>
        /// <param name="weights">The optional weights column.</param>
        /// <param name="numberOfTrees">Total number of decision trees to create in the ensemble.</param>
        /// <param name="numberOfLeaves">The maximum number of leaves per decision tree.</param>
        /// <param name="minimumExampleCountPerLeaf">The minimal number of data points allowed in a leaf of a regression tree, out of the subsampled data.</param>
        /// <param name="learningRate">The learning rate.</param>
        /// <param name="onFit">A delegate that is called every time the
        /// <see cref="Estimator{TInShape, TOutShape, TTransformer}.Fit(DataView{TInShape})"/> method is called on the
        /// <see cref="Estimator{TInShape, TOutShape, TTransformer}"/> instance created out of this. This delegate will receive
        /// the linear model that was trained. Note that this action cannot change the result in any way;
        /// it is only a way for the caller to be informed about what was learnt.</param>
        /// <returns>The Score output column indicating the predicted value.</returns>
        public static Scalar <float> FastTree <TVal>(this RankingCatalog.RankingTrainers catalog,
                                                     Scalar <float> label, Vector <float> features, Key <uint, TVal> groupId, Scalar <float> weights = null,
                                                     int numberOfLeaves             = Defaults.NumberOfLeaves,
                                                     int numberOfTrees              = Defaults.NumberOfTrees,
                                                     int minimumExampleCountPerLeaf = Defaults.MinimumExampleCountPerLeaf,
                                                     double learningRate            = Defaults.LearningRate,
                                                     Action <FastTreeRankingModelParameters> onFit = null)
        {
            CheckUserValues(label, features, weights, numberOfLeaves, numberOfTrees, minimumExampleCountPerLeaf, learningRate, onFit);

            var rec = new TrainerEstimatorReconciler.Ranker <TVal>(
                (env, labelName, featuresName, groupIdName, weightsName) =>
            {
                var trainer = new FastTreeRankingTrainer(env, labelName, featuresName, groupIdName, weightsName, numberOfLeaves,
                                                         numberOfTrees, minimumExampleCountPerLeaf, learningRate);
                if (onFit != null)
                {
                    return(trainer.WithOnFitDelegate(trans => onFit(trans.Model)));
                }
                return(trainer);
            }, label, features, groupId, weights);

            return(rec.Score);
        }