/// <summary> /// Classification model selecting EnsembleLearner. /// Trains several models and selects the best subset of models for the ensemble. /// The selection of the best set of models is based on cross validation. /// http://www.cs.cornell.edu/~alexn/papers/shotgun.icml04.revised.rev2.pdf /// </summary> /// <param name="learners">Learners in the ensemble</param> /// <param name="crossValidation">Cross validation method</param> /// <param name="ensembleStrategy">Strategy on how to combine the models</param> /// <param name="ensembleSelection">Ensemble selection method used to find the beset subset of models</param> public ClassificationModelSelectingEnsembleLearner( IIndexedLearner <ProbabilityPrediction>[] learners, ICrossValidation <ProbabilityPrediction> crossValidation, IClassificationEnsembleStrategy ensembleStrategy, IClassificationEnsembleSelection ensembleSelection) : this(learners, crossValidation, () => ensembleStrategy, ensembleSelection) { }
/// <summary> /// Regression model selecting EnsembleLearner. /// Trains several models and selects the best subset of models for the ensemble. /// The selection of the best set of models is based on cross validation. /// http://www.cs.cornell.edu/~alexn/papers/shotgun.icml04.revised.rev2.pdf /// </summary> /// <param name="learners">Learners in the ensemble</param> /// <param name="crossValidation">Cross validation method</param> /// <param name="ensembleStrategy">Strategy on how to combine the models</param> /// <param name="ensembleSelection">Ensemble selection method used to find the beset subset of models</param> public RegressionModelSelectingEnsembleLearner( IIndexedLearner <double>[] learners, ICrossValidation <double> crossValidation, IRegressionEnsembleStrategy ensembleStrategy, IRegressionEnsembleSelection ensembleSelection) : this(learners, crossValidation, () => ensembleStrategy, ensembleSelection) { }
/// <summary> /// Stacking Classification Ensemble Learner. /// Combines several models into a single ensemble model using a top or meta level model to combine the models. /// The bottom level models generates output for the top level model using cross validation. /// </summary> /// <param name="learners">Learners in the ensemble</param> /// <param name="metaLearner">Meta learner or top level model for combining the ensemble models</param> /// <param name="crossValidation">Cross validation method</param> /// <param name="includeOriginalFeaturesForMetaLearner">True; the meta learner also receives the original features. /// False; the meta learner only receives the output of the ensemble models as features. Default is true</param> public ClassificationStackingEnsembleLearner( IIndexedLearner <ProbabilityPrediction>[] learners, ILearner <ProbabilityPrediction> metaLearner, ICrossValidation <ProbabilityPrediction> crossValidation, bool includeOriginalFeaturesForMetaLearner = true) : this(learners, (obs, targets) => metaLearner.Learn(obs, targets), crossValidation, includeOriginalFeaturesForMetaLearner) { }
/// <summary> /// Stacking Regression Ensemble Learner. /// Combines several models into a single ensemble model using a top or meta level model to combine the models. /// The bottom level models generates output for the top level model using cross validation. /// </summary> /// <param name="learners">Learners in the ensemble</param> /// <param name="metaLearner">Meta learner or top level model for combining the ensemble models</param> /// <param name="crossValidation">Cross validation method</param> /// <param name="includeOriginalFeaturesForMetaLearner">True; the meta learner also receives the original features. /// False; the meta learner only receives the output of the ensemble models as features. Default is true</param> public RegressionStackingEnsembleLearner( IIndexedLearner <double>[] learners, ILearner <double> metaLearner, ICrossValidation <double> crossValidation, bool includeOriginalFeaturesForMetaLearner = true) : this(learners, (obs, targets) => metaLearner.Learn(obs, targets), crossValidation, includeOriginalFeaturesForMetaLearner) { }
/// <summary> /// Classification model selecting EnsembleLearner. /// Trains several models and selects the best subset of models for the ensemble using greedy backward elimination. /// The selection of the best set of models is based on cross validation. /// http://www.cs.cornell.edu/~alexn/papers/shotgun.icml04.revised.rev2.pdf /// </summary> /// <param name="learners">Learners in the ensemble</param> /// <param name="numberOfModelsToSelect">Number of models to select</param> /// <param name="crossValidation">Cross validation method</param> /// <param name="ensembleStrategy">Strategy for ensembling models</param> /// <param name="metric">Metric to minimize</param> public ClassificationBackwardEliminationModelSelectingEnsembleLearner( IIndexedLearner <ProbabilityPrediction>[] learners, int numberOfModelsToSelect, ICrossValidation <ProbabilityPrediction> crossValidation, IClassificationEnsembleStrategy ensembleStrategy, IMetric <double, ProbabilityPrediction> metric) : base(learners, crossValidation, ensembleStrategy, new BackwardEliminationClassificationEnsembleSelection( metric, ensembleStrategy, numberOfModelsToSelect)) { }
/// <summary> /// Stacking Classification Ensemble Learner. /// Combines several models into a single ensemble model using a top or meta level model to combine the models. /// Combines several models into a single ensemble model using a top or meta level model to combine the models. /// </summary> /// <param name="learners">Learners in the ensemble</param> /// <param name="metaLearner">Meta learner or top level model for combining the ensemble models</param> /// <param name="crossValidation">Cross validation method</param> /// <param name="includeOriginalFeaturesForMetaLearner">True; the meta learner also receives the original features. /// False; the meta learner only receives the output of the ensemble models as features</param> public ClassificationStackingEnsembleLearner( IIndexedLearner <ProbabilityPrediction>[] learners, Func <F64Matrix, double[], IPredictorModel <ProbabilityPrediction> > metaLearner, ICrossValidation <ProbabilityPrediction> crossValidation, bool includeOriginalFeaturesForMetaLearner = true) { m_learners = learners ?? throw new ArgumentException(nameof(learners)); m_crossValidation = crossValidation ?? throw new ArgumentException(nameof(crossValidation)); m_metaLearner = metaLearner ?? throw new ArgumentException(nameof(metaLearner)); m_includeOriginalFeaturesForMetaLearner = includeOriginalFeaturesForMetaLearner; }
/// <summary> /// Regression model selecting EnsembleLearner. /// Trains several models and selects the best subset of models for the ensemble using backwards elimination. /// The selection of the best set of models is based on cross validation. /// http://www.cs.cornell.edu/~alexn/papers/shotgun.icml04.revised.rev2.pdf /// </summary> /// <param name="learners">Learners in the ensemble</param> /// <param name="numberOfModelsToSelect">Number of models to select</param> /// <param name="crossValidation">Cross validation method</param> /// <param name="ensembleStrategy">Strategy for ensembling models</param> /// <param name="metric">Metric to minimize</param> public RegressionBackwardEliminationModelSelectingEnsembleLearner( IIndexedLearner <double>[] learners, int numberOfModelsToSelect, ICrossValidation <double> crossValidation, IRegressionEnsembleStrategy ensembleStrategy, IMetric <double, double> metric) : base(learners, crossValidation, ensembleStrategy, new BackwardEliminationRegressionEnsembleSelection(metric, ensembleStrategy, numberOfModelsToSelect)) { }
/// <summary> /// Classification model selecting EnsembleLearner. /// Trains several models and selects the best subset of models for the ensemble. /// The selection of the best set of models is based on cross validation. /// http://www.cs.cornell.edu/~alexn/papers/shotgun.icml04.revised.rev2.pdf /// </summary> /// <param name="learners">Learners in the ensemble</param> /// <param name="crossValidation">Cross validation method</param> /// <param name="ensembleStrategy">Strategy on how to combine the models</param> /// <param name="ensembleSelection">Ensemble selection method used to find the beset subset of models</param> public ClassificationModelSelectingEnsembleLearner( IIndexedLearner <ProbabilityPrediction>[] learners, ICrossValidation <ProbabilityPrediction> crossValidation, Func <IClassificationEnsembleStrategy> ensembleStrategy, IClassificationEnsembleSelection ensembleSelection) { m_learners = learners ?? throw new ArgumentNullException(nameof(learners)); m_crossValidation = crossValidation ?? throw new ArgumentNullException(nameof(crossValidation)); m_ensembleStrategy = ensembleStrategy ?? throw new ArgumentNullException(nameof(ensembleStrategy)); m_ensembleSelection = ensembleSelection ?? throw new ArgumentNullException(nameof(ensembleSelection)); }
/// <summary> /// Regression model selecting EnsembleLearner. /// Trains several models and selects the best subset of models for the ensemble. /// The selection of the best set of models is based on cross validation. /// Trains several models and selects the best subset of models for the ensemble. /// http://www.cs.cornell.edu/~alexn/papers/shotgun.icml04.revised.rev2.pdf /// </summary> /// <param name="learners">Learners in the ensemble</param> /// <param name="crossValidation">Cross validation method</param> /// <param name="ensembleStrategy">Strategy on how to combine the models</param> /// <param name="ensembleSelection">Ensemble selection method used to find the beset subset of models</param> public RegressionModelSelectingEnsembleLearner( IIndexedLearner <double>[] learners, ICrossValidation <double> crossValidation, Func <IRegressionEnsembleStrategy> ensembleStrategy, IRegressionEnsembleSelection ensembleSelection) { m_learners = learners ?? throw new ArgumentNullException(nameof(learners)); m_crossValidation = crossValidation ?? throw new ArgumentNullException(nameof(crossValidation)); m_ensembleStrategy = ensembleStrategy ?? throw new ArgumentNullException(nameof(ensembleStrategy)); m_ensembleSelection = ensembleSelection ?? throw new ArgumentNullException(nameof(ensembleSelection)); }
/// <summary> /// Regression model selecting EnsembleLearner. /// Trains several models and selects the best subset of models for the ensemble using greedy forward selection. /// The selection of the best set of models is based on cross validation. /// http://www.cs.cornell.edu/~alexn/papers/shotgun.icml04.revised.rev2.pdf /// </summary> /// <param name="learners">Learners in the ensemble</param> /// <param name="numberOfModelsToSelect">Number of models to select</param> /// <param name="crossValidation">Cross validation method</param> /// <param name="ensembleStrategy">Strategy for ensembling models</param> /// <param name="metric">Metric to minimize</param> /// <param name="numberOfModelsFromStart">Number of models from start of the search. /// The top n models will be selected based in their solo performance</param> /// <param name="selectWithReplacement">If true the same model can be selected multiple times. /// This will correspond to weighting the models. If false each model can only be selected once. Default is true</param> public RegressionForwardSearchModelSelectingEnsembleLearner( IIndexedLearner <double>[] learners, int numberOfModelsToSelect, ICrossValidation <double> crossValidation, IRegressionEnsembleStrategy ensembleStrategy, IMetric <double, double> metric, int numberOfModelsFromStart = 1, bool selectWithReplacement = true) : base(learners, crossValidation, ensembleStrategy, new ForwardSearchRegressionEnsembleSelection(metric, ensembleStrategy, numberOfModelsToSelect, numberOfModelsFromStart, selectWithReplacement)) { }
/// <summary> /// Classification model selecting EnsembleLearner. /// Trains several models and selects the best subset of models for the ensemble using greedy forward selection. /// The selection of the best set of models is based on cross validation. /// http://www.cs.cornell.edu/~alexn/papers/shotgun.icml04.revised.rev2.pdf /// </summary> /// <param name="learners">Learners in the ensemble</param> /// <param name="numberOfModelsToSelect">Number of models to select</param> /// <param name="crossValidation">Cross validation method</param> /// <param name="ensembleStrategy">Strategy for ensembling models</param> /// <param name="metric">Metric to minimize</param> /// <param name="numberOfModelsFromStart">Number of models from start of the search. /// The top n models will be selected based in their solo performance</param> /// <param name="selectWithReplacement">If true the same model can be selected multiple times. /// This will correspond to weighting the models. If false each model can only be selected once. Default is true</param> public ClassificationForwardSearchModelSelectingEnsembleLearner( IIndexedLearner <ProbabilityPrediction>[] learners, int numberOfModelsToSelect, ICrossValidation <ProbabilityPrediction> crossValidation, IClassificationEnsembleStrategy ensembleStrategy, IMetric <double, ProbabilityPrediction> metric, int numberOfModelsFromStart = 1, bool selectWithReplacement = true) : base(learners, crossValidation, ensembleStrategy, new ForwardSearchClassificationEnsembleSelection( metric, ensembleStrategy, numberOfModelsToSelect, numberOfModelsFromStart, selectWithReplacement)) { }
/// <summary> /// Regression model selecting EnsembleLearner. /// Trains several models and selects the best subset of models for the ensemble using iterative random selection. /// The selection of the best set of models is based on cross validation. /// http://www.cs.cornell.edu/~alexn/papers/shotgun.icml04.revised.rev2.pdf /// </summary> /// <param name="learners">Learners in the ensemble</param> /// <param name="numberOfModelsToSelect">Number of models to select</param> /// <param name="crossValidation">Cross validation method</param> /// <param name="ensembleStrategy">Strategy for ensembling models</param> /// <param name="metric">Metric to minimize</param> /// <param name="iterations">Number of iterations to random select model combinations.</param> /// <param name="selectWithReplacement">If true the same model can be selected multiple times.</param> /// <param name="seed"></param> public RegressionRandomModelSelectingEnsembleLearner( IIndexedLearner <double>[] learners, int numberOfModelsToSelect, ICrossValidation <double> crossValidation, IRegressionEnsembleStrategy ensembleStrategy, IMetric <double, double> metric, int iterations = 50, bool selectWithReplacement = true, int seed = 42) : base(learners, crossValidation, ensembleStrategy, new RandomRegressionEnsembleSelection(metric, ensembleStrategy, numberOfModelsToSelect, iterations, selectWithReplacement, seed)) { }
/// <summary> /// Classification model selecting EnsembleLearner. /// Trains several models and selects the best subset of models for the ensemble using iterative random selection. /// The selection of the best set of models is based on cross validation. /// http://www.cs.cornell.edu/~alexn/papers/shotgun.icml04.revised.rev2.pdf /// </summary> /// <param name="learners">Learners in the ensemble</param> /// <param name="numberOfModelsToSelect">Number of models to select</param> /// <param name="crossValidation">Cross validation method</param> /// <param name="ensembleStrategy">Strategy for ensembling models</param> /// <param name="metric">Metric to minimize</param> /// <param name="iterations">Number of iterations to random select model combinations.</param> /// <param name="selectWithReplacement">If true the same model can be selected multiple times.</param> /// <param name="seed"></param> public ClassificationRandomModelSelectingEnsembleLearner( IIndexedLearner <ProbabilityPrediction>[] learners, int numberOfModelsToSelect, ICrossValidation <ProbabilityPrediction> crossValidation, IClassificationEnsembleStrategy ensembleStrategy, IMetric <double, ProbabilityPrediction> metric, int iterations = 50, bool selectWithReplacement = true, int seed = 42) : base(learners, crossValidation, ensembleStrategy, new RandomClassificationEnsembleSelection( metric, ensembleStrategy, numberOfModelsToSelect, iterations, selectWithReplacement, seed)) { }
/// <summary> /// Stacking Regression Ensemble Learner. /// Combines several models into a single ensemble model using a top or meta level model to combine the models. /// The bottom level models generates output for the top level model using cross validation. /// </summary> /// <param name="learners">Learners in the ensemble</param> /// <param name="metaLearner">Meta learner or top level model for combining the ensemble models</param> /// <param name="crossValidation">Cross validation method</param> /// <param name="includeOriginalFeaturesForMetaLearner">True; the meta learner also recieves the original features. /// False; the meta learner only recieves the output of the ensemble models as features</param> public RegressionStackingEnsembleLearner(IIndexedLearner <double>[] learners, Func <F64Matrix, double[], IPredictorModel <double> > metaLearner, ICrossValidation <double> crossValidation, bool includeOriginalFeaturesForMetaLearner = true) { if (learners == null) { throw new ArgumentException("learners"); } if (crossValidation == null) { throw new ArgumentException("crossValidation"); } if (metaLearner == null) { throw new ArgumentException("metaLearner"); } m_learners = learners; m_crossValidation = crossValidation; m_metaLearner = metaLearner; m_includeOriginalFeaturesForMetaLearner = includeOriginalFeaturesForMetaLearner; }
/// <summary> /// Regression model selecting EnsembleLearner. /// Trains several models and selects the best subset of models for the ensemble. /// The selection of the best set of models is based on cross validation. /// Trains several models and selects the best subset of models for the ensemble. /// http://www.cs.cornell.edu/~alexn/papers/shotgun.icml04.revised.rev2.pdf /// </summary> /// <param name="learners">Learners in the ensemble</param> /// <param name="crossValidation">Cross validation method</param> /// <param name="ensembleStrategy">Strategy on how to combine the models</param> /// <param name="ensembleSelection">Enemble selection method used to find the beset subset of models</param> public RegressionModelSelectingEnsembleLearner(IIndexedLearner <double>[] learners, ICrossValidation <double> crossValidation, Func <IRegressionEnsembleStrategy> ensembleStrategy, IRegressionEnsembleSelection ensembleSelection) { if (learners == null) { throw new ArgumentNullException("learners"); } if (crossValidation == null) { throw new ArgumentNullException("crossValidation"); } if (ensembleStrategy == null) { throw new ArgumentNullException("ensembleStrategy"); } if (ensembleSelection == null) { throw new ArgumentNullException("ensembleSelection"); } m_learners = learners; m_crossValidation = crossValidation; m_ensembleStrategy = ensembleStrategy; m_ensembleSelection = ensembleSelection; }
/// <summary> /// Classification model selecting EnsembleLearner. /// Trains several models and selects the best subset of models for the ensemble. /// The selection of the best set of models is based on cross validation. /// http://www.cs.cornell.edu/~alexn/papers/shotgun.icml04.revised.rev2.pdf /// </summary> /// <param name="learners">Learners in the ensemble</param> /// <param name="crossValidation">Cross validation method</param> /// <param name="ensembleStrategy">Strategy on how to combine the models</param> /// <param name="ensembleSelection">Ensemble selection method used to find the beset subset of models</param> public ClassificationModelSelectingEnsembleLearner(IIndexedLearner <ProbabilityPrediction>[] learners, ICrossValidation <ProbabilityPrediction> crossValidation, Func <IClassificationEnsembleStrategy> ensembleStrategy, IClassificationEnsembleSelection ensembleSelection) { if (learners == null) { throw new ArgumentNullException("learners"); } if (crossValidation == null) { throw new ArgumentNullException("crossValidation"); } if (ensembleStrategy == null) { throw new ArgumentNullException("ensembleStrategy"); } if (ensembleSelection == null) { throw new ArgumentNullException("ensembleSelection"); } m_learners = learners; m_crossValidation = crossValidation; m_ensembleStrategy = ensembleStrategy; m_ensembleSelection = ensembleSelection; }