/// <summary> /// Predict a target using a tree regression model trained with the <see cref="LightGbmRegressorTrainer"/>. /// </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="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 Score output column indicating the predicted value.</returns> /// <example> /// <format type="text/markdown"> /// <![CDATA[ /// [!code-csharp[LightGBM](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Static/LightGBMRegression.cs)] /// ]]></format> /// </example> public static Scalar <float> LightGbm(this RegressionContext.RegressionTrainers ctx, Scalar <float> label, Vector <float> features, Scalar <float> weights = null, int?numLeaves = null, int?minDataPerLeaf = null, double?learningRate = null, int numBoostRound = LightGbmArguments.Defaults.NumBoostRound, Action <LightGbmArguments> advancedSettings = null, Action <LightGbmRegressionModelParameters> onFit = null) { CheckUserValues(label, features, weights, numLeaves, minDataPerLeaf, learningRate, numBoostRound, advancedSettings, onFit); var rec = new TrainerEstimatorReconciler.Regression( (env, labelName, featuresName, weightsName) => { var trainer = new LightGbmRegressorTrainer(env, labelName, featuresName, weightsName, numLeaves, minDataPerLeaf, learningRate, numBoostRound, advancedSettings); if (onFit != null) { return(trainer.WithOnFitDelegate(trans => onFit(trans.Model))); } return(trainer); }, label, features, weights); return(rec.Score); }
/// <summary> /// Predict a target using a tree regression model trained with the <see cref="LightGbmRegressorTrainer"/>. /// </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="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 Score output column indicating the predicted value.</returns> public static Scalar <float> LightGbm(this RegressionCatalog.RegressionTrainers catalog, Scalar <float> label, Vector <float> features, Scalar <float> weights, Options options, Action <LightGbmRegressionModelParameters> onFit = null) { CheckUserValues(label, features, weights, options, onFit); var rec = new TrainerEstimatorReconciler.Regression( (env, labelName, featuresName, weightsName) => { options.LabelColumnName = labelName; options.FeatureColumnName = featuresName; options.ExampleWeightColumnName = weightsName; var trainer = new LightGbmRegressorTrainer(env, options); if (onFit != null) { return(trainer.WithOnFitDelegate(trans => onFit(trans.Model))); } return(trainer); }, label, features, weights); return(rec.Score); }
/// <summary> /// Predict a target using a tree regression model trained with the <see cref="LightGbmRegressorTrainer"/>. /// </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="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 Score output column indicating the predicted value.</returns> /// <example> /// <format type="text/markdown"> /// <![CDATA[ /// [!code-csharp[LightGBM](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Static/LightGBMRegression.cs)] /// ]]></format> /// </example> public static Scalar <float> LightGbm(this RegressionCatalog.RegressionTrainers catalog, Scalar <float> label, Vector <float> features, Scalar <float> weights = null, int?numberOfLeaves = null, int?minimumExampleCountPerLeaf = null, double?learningRate = null, int numberOfIterations = Options.Defaults.NumberOfIterations, Action <LightGbmRegressionModelParameters> onFit = null) { CheckUserValues(label, features, weights, numberOfLeaves, minimumExampleCountPerLeaf, learningRate, numberOfIterations, onFit); var rec = new TrainerEstimatorReconciler.Regression( (env, labelName, featuresName, weightsName) => { var trainer = new LightGbmRegressorTrainer(env, labelName, featuresName, weightsName, numberOfLeaves, minimumExampleCountPerLeaf, learningRate, numberOfIterations); if (onFit != null) { return(trainer.WithOnFitDelegate(trans => onFit(trans.Model))); } return(trainer); }, label, features, weights); return(rec.Score); }