/// <summary> /// FastTree <see cref="RegressionCatalog"/> extension method. /// Predicts a target using a decision tree regression model trained with the <see cref="FastTreeRegressionTrainer"/>. /// </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 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> /// <example> /// <format type="text/markdown"> /// <![CDATA[ /// [!code-csharp[FastTree](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Static/FastTreeRegression.cs)] /// ]]></format> /// </example> public static Scalar <float> FastTree(this RegressionCatalog.RegressionTrainers catalog, Scalar <float> label, Vector <float> features, Scalar <float> weights, FastTreeRegressionTrainer.Options options, Action <FastTreeRegressionModelParameters> onFit = null) { Contracts.CheckValueOrNull(options); CheckUserValues(label, features, weights, onFit); var rec = new TrainerEstimatorReconciler.Regression( (env, labelName, featuresName, weightsName) => { options.LabelColumnName = labelName; options.FeatureColumnName = featuresName; options.ExampleWeightColumnName = weightsName; var trainer = new FastTreeRegressionTrainer(env, options); if (onFit != null) { return(trainer.WithOnFitDelegate(trans => onFit(trans.Model))); } return(trainer); }, label, features, weights); return(rec.Score); }
public void FastTreeRegressorEstimator() { using (var env = new LocalEnvironment(seed: 1, conc: 1)) { // "loader=Text{col=Label:R4:11 col=Features:R4:0-10 sep=; header+}" var reader = new TextLoader(env, new TextLoader.Arguments() { Separator = ";", HasHeader = true, Column = new[] { new TextLoader.Column("Label", DataKind.R4, 11), new TextLoader.Column("Features", DataKind.R4, new [] { new TextLoader.Range(0, 10) }) } }); var data = reader.Read(new MultiFileSource(GetDataPath(TestDatasets.generatedRegressionDatasetmacro.trainFilename))); // Pipeline. var pipeline = new FastTreeRegressionTrainer(env, "Label", "Features", advancedSettings: s => { s.NumTrees = 10; s.NumThreads = 1; s.NumLeaves = 5; }); TestEstimatorCore(pipeline, data); } }
/// <summary> /// FastTree <see cref="RegressionContext"/> extension method. /// Predicts a target using a decision tree regression model trained with the <see cref="FastTreeRegressionTrainer"/>. /// </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 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> /// <example> /// <format type="text/markdown"> /// <![CDATA[ /// [!code-csharp[FastTree](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Static/FastTreeRegression.cs)] /// ]]></format> /// </example> public static Scalar <float> FastTree(this RegressionContext.RegressionTrainers ctx, Scalar <float> label, Vector <float> features, Scalar <float> weights = null, int numLeaves = Defaults.NumLeaves, int numTrees = Defaults.NumTrees, int minDatapointsInLeaves = Defaults.MinDocumentsInLeaves, double learningRate = Defaults.LearningRates, Action <FastTreeRegressionTrainer.Arguments> advancedSettings = null, Action <FastTreeRegressionModelParameters> onFit = null) { CheckUserValues(label, features, weights, numLeaves, numTrees, minDatapointsInLeaves, learningRate, advancedSettings, onFit); var rec = new TrainerEstimatorReconciler.Regression( (env, labelName, featuresName, weightsName) => { var trainer = new FastTreeRegressionTrainer(env, labelName, featuresName, weightsName, numLeaves, numTrees, minDatapointsInLeaves, learningRate, advancedSettings); if (onFit != null) { return(trainer.WithOnFitDelegate(trans => onFit(trans.Model))); } return(trainer); }, label, features, weights); return(rec.Score); }
///<param name="scoreTracker"></param> /// <param name="resultType">1: L1, 2: L2. Otherwise, return all.</param> public RegressionTest(ScoreTracker scoreTracker, int?resultType = null) : base(scoreTracker) { _labels = FastTreeRegressionTrainer.GetDatasetRegressionLabels(scoreTracker.Dataset); Contracts.Check(scoreTracker.Dataset.NumDocs == _labels.Length, "Mismatch between dataset and labels"); _resultType = resultType; }
public void FastTreeRegressorEstimator() { // Pipeline. var pipeline = new FastTreeRegressionTrainer(Env, "Label", "Features", advancedSettings: s => { s.NumTrees = 10; s.NumThreads = 1; s.NumLeaves = 5; }); TestEstimatorCore(pipeline, GetRegressionPipeline()); Done(); }
public void FastTreeRegressorEstimator() { var dataView = GetRegressionPipeline(); var trainer = new FastTreeRegressionTrainer(Env, "Label", "Features", advancedSettings: s => { s.NumTrees = 10; s.NumThreads = 1; s.NumLeaves = 5; }); TestEstimatorCore(trainer, dataView); var model = trainer.Train(dataView, dataView); Done(); }
/// <summary> /// FastTree <see cref="RegressionCatalog"/> extension method. /// Predicts a target using a decision tree regression model trained with the <see cref="FastTreeRegressionTrainer"/>. /// </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 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> /// <example> /// <format type="text/markdown"> /// <![CDATA[ /// [!code-csharp[FastTree](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Static/FastTreeRegression.cs)] /// ]]></format> /// </example> public static Scalar <float> FastTree(this RegressionCatalog.RegressionTrainers catalog, Scalar <float> label, Vector <float> features, Scalar <float> weights = null, int numberOfLeaves = Defaults.NumberOfLeaves, int numberOfTrees = Defaults.NumberOfTrees, int minimumExampleCountPerLeaf = Defaults.MinimumExampleCountPerLeaf, double learningRate = Defaults.LearningRate, Action <FastTreeRegressionModelParameters> onFit = null) { CheckUserValues(label, features, weights, numberOfLeaves, numberOfTrees, minimumExampleCountPerLeaf, learningRate, onFit); var rec = new TrainerEstimatorReconciler.Regression( (env, labelName, featuresName, weightsName) => { var trainer = new FastTreeRegressionTrainer(env, labelName, featuresName, weightsName, numberOfLeaves, numberOfTrees, minimumExampleCountPerLeaf, learningRate); if (onFit != null) { return(trainer.WithOnFitDelegate(trans => onFit(trans.Model))); } return(trainer); }, label, features, weights); return(rec.Score); }