/// <summary> /// Predict a target using a linear regression model trained with the <see cref="Microsoft.ML.Runtime.Learners.LogisticRegression"/> trainer. /// </summary> /// <param name="ctx">The regression context trainer object.</param> /// <param name="label">The label, or dependent variable.</param> /// <param name="features">The features, or independent variables.</param> /// <param name="weights">The optional example weights.</param> /// <param name="enoforceNoNegativity">Enforce non-negative weights.</param> /// <param name="l1Weight">Weight of L1 regularization term.</param> /// <param name="l2Weight">Weight of L2 regularization term.</param> /// <param name="memorySize">Memory size for <see cref="Microsoft.ML.Runtime.Learners.LogisticRegression"/>. Low=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> /// <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 predicted output.</returns> public static Scalar <float> PoissonRegression(this RegressionContext.RegressionTrainers ctx, Scalar <float> label, Vector <float> features, Scalar <float> weights = null, float l1Weight = Arguments.Defaults.L1Weight, float l2Weight = Arguments.Defaults.L2Weight, float optimizationTolerance = Arguments.Defaults.OptTol, int memorySize = Arguments.Defaults.MemorySize, bool enoforceNoNegativity = Arguments.Defaults.EnforceNonNegativity, Action <Arguments> advancedSettings = null, Action <PoissonRegressionModelParameters> onFit = null) { LbfgsStaticUtils.ValidateParams(label, features, weights, l1Weight, l2Weight, optimizationTolerance, memorySize, enoforceNoNegativity, advancedSettings, onFit); var rec = new TrainerEstimatorReconciler.Regression( (env, labelName, featuresName, weightsName) => { var trainer = new PoissonRegression(env, labelName, featuresName, weightsName, l1Weight, l2Weight, optimizationTolerance, memorySize, enoforceNoNegativity); if (onFit != null) { return(trainer.WithOnFitDelegate(trans => onFit(trans.Model))); } return(trainer); }, label, features, weights); return(rec.Score); }
/// <summary> /// Predict a target using a linear binary classification model trained with the <see cref="Microsoft.ML.Trainers.LogisticRegression"/> trainer. /// </summary> /// <param name="catalog">The binary classification catalog trainer object.</param> /// <param name="label">The label, or dependent variable.</param> /// <param name="features">The features, or independent variables.</param> /// <param name="weights">The optional example weights.</param> /// <param name="enforceNonNegativity">Enforce non-negative weights.</param> /// <param name="l1Regularization">Weight of L1 regularization term.</param> /// <param name="l2Regularization">Weight of L2 regularization term.</param> /// <param name="historySize">Memory size for <see cref="Microsoft.ML.Trainers.LogisticRegression"/>. Low=faster, less accurate.</param> /// <param name="optimizationTolerance">Threshold for optimizer convergence.</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 predicted output.</returns> public static (Scalar <float> score, Scalar <float> probability, Scalar <bool> predictedLabel) LogisticRegressionBinaryClassifier(this BinaryClassificationCatalog.BinaryClassificationTrainers catalog, Scalar <bool> label, Vector <float> features, Scalar <float> weights = null, float l1Regularization = Options.Defaults.L1Regularization, float l2Regularization = Options.Defaults.L2Regularization, float optimizationTolerance = Options.Defaults.OptimizationTolerance, int historySize = Options.Defaults.HistorySize, bool enforceNonNegativity = Options.Defaults.EnforceNonNegativity, Action <CalibratedModelParametersBase <LinearBinaryModelParameters, PlattCalibrator> > onFit = null) { LbfgsStaticUtils.ValidateParams(label, features, weights, l1Regularization, l2Regularization, optimizationTolerance, historySize, enforceNonNegativity, onFit); var rec = new TrainerEstimatorReconciler.BinaryClassifier( (env, labelName, featuresName, weightsName) => { var trainer = new LogisticRegression(env, labelName, featuresName, weightsName, l1Regularization, l2Regularization, optimizationTolerance, historySize, enforceNonNegativity); if (onFit != null) { return(trainer.WithOnFitDelegate(trans => onFit(trans.Model))); } return(trainer); }, label, features, weights); return(rec.Output); }
/// <summary> /// Predict a target using a linear binary classification model trained with the <see cref="Microsoft.ML.Runtime.Learners.LogisticRegression"/> trainer. /// </summary> /// <param name="ctx">The binary classificaiton context trainer object.</param> /// <param name="label">The label, or dependent variable.</param> /// <param name="features">The features, or independent variables.</param> /// <param name="weights">The optional example weights.</param> /// <param name="enoforceNoNegativity">Enforce non-negative weights.</param> /// <param name="l1Weight">Weight of L1 regularization term.</param> /// <param name="l2Weight">Weight of L2 regularization term.</param> /// <param name="memorySize">Memory size for <see cref="Microsoft.ML.Runtime.Learners.LogisticRegression"/>. Low=faster, less accurate.</param> /// <param name="optimizationTolerance">Threshold for optimizer convergence.</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> /// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param> /// <returns>The predicted output.</returns> public static (Scalar <float> score, Scalar <float> probability, Scalar <bool> predictedLabel) LogisticRegressionBinaryClassifier(this BinaryClassificationContext.BinaryClassificationTrainers ctx, Scalar <bool> label, Vector <float> features, Scalar <float> weights = null, float l1Weight = Arguments.Defaults.L1Weight, float l2Weight = Arguments.Defaults.L2Weight, float optimizationTolerance = Arguments.Defaults.OptTol, int memorySize = Arguments.Defaults.MemorySize, bool enoforceNoNegativity = Arguments.Defaults.EnforceNonNegativity, Action <Arguments> advancedSettings = null, Action <ParameterMixingCalibratedPredictor> onFit = null) { LbfgsStaticUtils.ValidateParams(label, features, weights, l1Weight, l2Weight, optimizationTolerance, memorySize, enoforceNoNegativity, advancedSettings, onFit); var rec = new TrainerEstimatorReconciler.BinaryClassifier( (env, labelName, featuresName, weightsName) => { var trainer = new LogisticRegression(env, labelName, featuresName, weightsName, l1Weight, l2Weight, optimizationTolerance, memorySize, enoforceNoNegativity, advancedSettings); if (onFit != null) { return(trainer.WithOnFitDelegate(trans => onFit(trans.Model))); } return(trainer); }, label, features, weights); return(rec.Output); }
/// <summary> /// Predict a target using a linear regression model trained with the <see cref="Microsoft.ML.Trainers.LogisticRegression"/> trainer. /// </summary> /// <param name="catalog">The regression catalog trainer object.</param> /// <param name="label">The label, or dependent variable.</param> /// <param name="features">The features, or independent variables.</param> /// <param name="weights">The optional example weights.</param> /// <param name="enforceNonNegativity">Enforce non-negative weights.</param> /// <param name="l1Regularization">Weight of L1 regularization term.</param> /// <param name="l2Regularization">Weight of L2 regularization term.</param> /// <param name="historySize">Memory size for <see cref="Microsoft.ML.Trainers.LogisticRegression"/>. Low=faster, less accurate.</param> /// <param name="optimizationTolerance">Threshold for optimizer convergence.</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 predicted output.</returns> public static Scalar <float> PoissonRegression(this RegressionCatalog.RegressionTrainers catalog, Scalar <float> label, Vector <float> features, Scalar <float> weights = null, float l1Regularization = Options.Defaults.L1Regularization, float l2Regularization = Options.Defaults.L2Regularization, float optimizationTolerance = Options.Defaults.OptimizationTolerance, int historySize = Options.Defaults.HistorySize, bool enforceNonNegativity = Options.Defaults.EnforceNonNegativity, Action <PoissonRegressionModelParameters> onFit = null) { LbfgsStaticUtils.ValidateParams(label, features, weights, l1Regularization, l2Regularization, optimizationTolerance, historySize, enforceNonNegativity, onFit); var rec = new TrainerEstimatorReconciler.Regression( (env, labelName, featuresName, weightsName) => { var trainer = new PoissonRegression(env, labelName, featuresName, weightsName, l1Regularization, l2Regularization, optimizationTolerance, historySize, enforceNonNegativity); if (onFit != null) { return(trainer.WithOnFitDelegate(trans => onFit(trans.Model))); } return(trainer); }, label, features, weights); return(rec.Score); }