/// <summary> /// Predict a target using a linear multiclass classification model trained with the <see cref="Microsoft.ML.Learners.MulticlassLogisticRegression"/> trainer. /// </summary> /// <param name="catalog">The <see cref="MulticlassClassificationCatalog.MulticlassClassificationTrainers"/>.</param> /// <param name="labelColumn">The labelColumn, or dependent variable.</param> /// <param name="featureColumn">The features, or independent variables.</param> /// <param name="weights">The optional example weights.</param> /// <param name="enforceNoNegativity">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.Learners.LogisticRegression"/>. Low=faster, less accurate.</param> /// <param name="optimizationTolerance">Threshold for optimizer convergence.</param> public static MulticlassLogisticRegression LogisticRegression(this MulticlassClassificationCatalog.MulticlassClassificationTrainers catalog, string labelColumn = DefaultColumnNames.Label, string featureColumn = DefaultColumnNames.Features, string weights = null, float l1Weight = LROptions.Defaults.L1Weight, float l2Weight = LROptions.Defaults.L2Weight, float optimizationTolerance = LROptions.Defaults.OptTol, int memorySize = LROptions.Defaults.MemorySize, bool enforceNoNegativity = LROptions.Defaults.EnforceNonNegativity) { Contracts.CheckValue(catalog, nameof(catalog)); var env = CatalogUtils.GetEnvironment(catalog); return(new MulticlassLogisticRegression(env, labelColumn, featureColumn, weights, l1Weight, l2Weight, optimizationTolerance, memorySize, enforceNoNegativity)); }
/// <summary> /// Predicts a target using a linear multiclass classification model trained with the <see cref="Pkpd"/>. /// </summary> /// <remarks> /// <para> /// In the Pairwise coupling (PKPD) strategy, a binary classification algorithm is used to train one classifier for each pair of classes. /// Prediction is then performed by running these binary classifiers, and computing a score for each class by counting how many of the binary /// classifiers predicted it. The prediction is the class with the highest score. /// </para> /// </remarks> /// <param name="catalog">The <see cref="MulticlassClassificationCatalog.MulticlassClassificationTrainers"/>.</param> /// <param name="binaryEstimator">An instance of a binary <see cref="ITrainerEstimator{TTransformer, TPredictor}"/> used as the base trainer.</param> /// <param name="calibrator">The calibrator. If a calibrator is not explicitely provided, it will default to <see cref="PlattCalibratorTrainer"/></param> /// <param name="labelColumn">The name of the label colum.</param> /// <param name="imputeMissingLabelsAsNegative">Whether to treat missing labels as having negative labels, instead of keeping them missing.</param> /// <param name="maxCalibrationExamples">Number of instances to train the calibrator.</param> /// <typeparam name="TModel">The type of the model. This type parameter will usually be inferred automatically from <paramref name="binaryEstimator"/>.</typeparam> public static Pkpd PairwiseCoupling <TModel>(this MulticlassClassificationCatalog.MulticlassClassificationTrainers catalog, ITrainerEstimator <ISingleFeaturePredictionTransformer <TModel>, TModel> binaryEstimator, string labelColumn = DefaultColumnNames.Label, bool imputeMissingLabelsAsNegative = false, IEstimator <ISingleFeaturePredictionTransformer <ICalibrator> > calibrator = null, int maxCalibrationExamples = 1_000_000_000) where TModel : class { Contracts.CheckValue(catalog, nameof(catalog)); var env = CatalogUtils.GetEnvironment(catalog); if (!(binaryEstimator is ITrainerEstimator <ISingleFeaturePredictionTransformer <IPredictorProducing <float> >, IPredictorProducing <float> > est)) { throw env.ExceptParam(nameof(binaryEstimator), "Trainer estimator does not appear to produce the right kind of model."); } return(new Pkpd(env, est, labelColumn, imputeMissingLabelsAsNegative, GetCalibratorTrainerOrThrow(env, calibrator), maxCalibrationExamples)); }
/// <summary> /// Performs image classification using transfer learning. /// Usage of this API requires additional NuGet dependencies on TensorFlow redist, see linked document /// for more information. /// <format type="text/markdown"> /// <![CDATA[ /// [!include[io](~/../docs/samples/docs/api-reference/tensorflow-usage.md)] /// ]]> /// </format> /// </summary> /// <param name="catalog">Catalog</param> /// <param name="options">An <see cref="ImageClassificationTrainer.Options"/> object specifying advanced /// options for <see cref="ImageClassificationTrainer"/>.</param> public static ImageClassificationTrainer ImageClassification( this MulticlassClassificationCatalog.MulticlassClassificationTrainers catalog, ImageClassificationTrainer.Options options) => new ImageClassificationTrainer(CatalogUtils.GetEnvironment(catalog), options);