Skip to content

Commit 3389f1d

Browse files
authored
Docs 2nd pass for NaiveBayes, KMeans, OVA, Pairwise and OnnxTransformer (dotnet#3387)
* docs for NaiveBayes, KMeans, OVA, Pairwise * fix spaces * fix doc * fix build * fix comments * fix comments * fix comments * fix for Kmeans * fix comments * fix comment * fix build * Fix io table and add OnnxTransform docs * fix docs for ONNX
1 parent 6f3d95a commit 3389f1d

File tree

9 files changed

+175
-126
lines changed

9 files changed

+175
-126
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### Input and Output Columns
2+
The input features column data must be <xref:System.Single>. No label column needed. This trainer outputs the following columns:
3+
4+
| Output Column Name | Column Type | Description|
5+
| -- | -- | -- |
6+
| `Score` | <xref:System.Single> | The unbounded score that was calculated by the trainer to determine the prediction.|
7+
| `PredictedLabel` | <xref:System.Int32> | The cluster id predicted by the trainer.|

src/Microsoft.ML.KMeansClustering/KMeansPlusPlusTrainer.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,38 @@
2626

2727
namespace Microsoft.ML.Trainers
2828
{
29-
/// <include file='./doc.xml' path='doc/members/member[@name="KMeans++"]/*' />
29+
/// <summary>
30+
/// The <see cref="IEstimator{TTransformer}"/> for training a KMeans clusterer
31+
/// </summary>
32+
/// <remarks>
33+
/// <format type="text/markdown"><![CDATA[
34+
/// To create this trainer, use [KMeansTrainer](xref:Microsoft.ML.Trainers.KMeansTrainer).
35+
///
36+
/// [!include[io](~/../docs/samples/docs/api-reference/io-columns-clustering.md)]
37+
///
38+
/// ### Trainer Characteristics
39+
/// | | |
40+
/// | -- | -- |
41+
/// | Machine learning task | Clustering |
42+
/// | Is normalization required? | Yes |
43+
/// | Is caching required? | Yes |
44+
/// | Required NuGet in addition to Microsoft.ML | None |
45+
///
46+
/// ### Training Algorithm Details
47+
/// K-means is a popular clustering algorithm. With K-means, the data is clustered into a specified
48+
/// number of clusters in order to minimize the within-cluster sum of squares.
49+
/// K-means++ improves upon K-means by using the [Yinyang K-Means](https://research.microsoft.com/apps/pubs/default.aspx?id=252149)
50+
/// method for choosing the initial cluster centers.
51+
/// K-Means++ accelerates K-Means up to an order of magnitude while producing exactly the same clustering results(modulo floating point precision issues).
52+
/// K-Means++ observes that there is a lot of redundancy across iterations in the KMeans algorithms and most points do not change their clusters during an iteration.
53+
/// It uses various bounding techniques to identify this redundancy and eliminate many distance computations and optimize centroid computations.
54+
/// For more information on K-means, and K-means++ see:
55+
/// [K-means](https://en.wikipedia.org/wiki/K-means_clustering)
56+
/// [K-means++](https://en.wikipedia.org/wiki/K-means%2b%2b)
57+
/// ]]>
58+
/// </format>
59+
/// </remarks>
60+
/// <seealso cref="Microsoft.ML.Trainers.KMeansTrainer" />
3061
public class KMeansTrainer : TrainerEstimatorBase<ClusteringPredictionTransformer<KMeansModelParameters>, KMeansModelParameters>
3162
{
3263
internal const string LoadNameValue = "KMeansPlusPlus";
@@ -50,6 +81,10 @@ internal static class Defaults
5081
public const int NumberOfClusters = 5;
5182
}
5283

84+
/// <summary>
85+
/// Options for the <see cref="KMeansTrainer"/> as used in
86+
/// [KMeansTrainer(Options)](xref:"Microsoft.ML.KMeansClusteringExtensions.KMeans(Microsoft.ML.ClusteringCatalog.ClusteringTrainers,Microsoft.ML.Trainers.KMeansTrainer.Options)".
87+
/// </summary>
5388
public sealed class Options : UnsupervisedTrainerInputBaseWithWeight
5489
{
5590
/// <summary>

src/Microsoft.ML.KMeansClustering/doc.xml

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/Microsoft.ML.OnnxTransformer/OnnxCatalog.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ public static class OnnxCatalog
2323
/// <param name="modelFile">The path of the file containing the ONNX model.</param>
2424
/// <param name="gpuDeviceId">Optional GPU device ID to run execution on, <see langword="null" /> to run on CPU.</param>
2525
/// <param name="fallbackToCpu">If GPU error, raise exception or fallback to CPU.</param>
26+
/// <example>
27+
/// <format type="text/markdown">
28+
/// <![CDATA[
29+
/// [!code-csharp[ApplyOnnxModel](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/ApplyOnnxModel.cs)]
30+
/// ]]>
31+
/// </format>
32+
/// </example>
2633
public static OnnxScoringEstimator ApplyOnnxModel(this TransformsCatalog catalog,
2734
string modelFile,
2835
int? gpuDeviceId = null,

src/Microsoft.ML.OnnxTransformer/OnnxTransform.cs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,33 @@
3333
namespace Microsoft.ML.Transforms.Onnx
3434
{
3535
/// <summary>
36-
/// <p>A transform for scoring ONNX models in the ML.NET framework.</p>
37-
/// <format type="text/markdown">
38-
/// <![CDATA[
39-
/// [!code-csharp[MF](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Dynamic/OnnxTransform.cs)]
40-
/// ]]>
41-
/// </format>
36+
/// <see cref="IEstimator{TTransformer}"/> for scoring ONNX models in the ML.NET framework.
4237
/// </summary>
4338
/// <remarks>
44-
/// <p>Supports inferencing of models in ONNX 1.2 and 1.3 format (opset 7, 8 and 9), using the
45-
/// <a href='https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime/'>Microsoft.ML.OnnxRuntime</a> library.
46-
/// </p>
47-
/// <p>Models are scored on CPU by default. If GPU execution is needed (optional), use the
48-
/// NuGet package available at
49-
/// <a href='https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime.Gpu/'>Microsoft.ML.OnnxRuntime.Gpu</a>
50-
/// and download
51-
/// <a href='https://developer.nvidia.com/cuda-downloads'>CUDA 9.1 Toolkit</a>
52-
/// and
53-
/// <a href='https://developer.nvidia.com/cudnn'>cuDNN</a>.
54-
/// Set parameter 'gpuDeviceId' to a valid non-negative integer. Typical device ID values are 0 or 1.
55-
/// </p>
56-
/// <p>The inputs and outputs of the ONNX models must be Tensor type. Sequence and Maps are not yet supported.</p>
57-
/// <p>OnnxRuntime currently works on Windows and Ubuntu 16.04 Linux 64-bit platforms. Mac OS to be supported soon.</p>
58-
/// <p>Visit https://github.com/onnx/models to see a list of readily available models to get started with.</p>
59-
/// <p>Refer to http://onnx.ai' for more information about ONNX.</p>
39+
/// <format type="text/markdown"><![CDATA[
40+
///
41+
/// ### Estimator Characteristics
42+
/// | | |
43+
/// | -- | -- |
44+
/// | Does this estimator need to look at the data to train its parameters? | No |
45+
/// | Input column data type | Known-sized vector of <xref:System.Single> or <xref:System.Double> types. |
46+
/// | Output column data type | The same data type as the input column |
47+
///
48+
/// Supports inferencing of models in ONNX 1.2 and 1.3 format (opset 7, 8 and 9), using the
49+
/// [Microsoft.ML.OnnxRuntime](https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime/) library.
50+
/// Models are scored on CPU by default. If GPU execution is needed (optional), use the
51+
/// NuGet package available at [Microsoft.ML.OnnxRuntime.Gpu](https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime.Gpu/)
52+
/// and download [CUDA 9.1 Toolkit](https://developer.nvidia.com/cuda-downloads) and [cuDNN](https://developer.nvidia.com/cudnn).
53+
/// Set parameter 'gpuDeviceId' to a valid non-negative integer. Typical device ID values are 0 or 1.
54+
/// The inputs and outputs of the ONNX models must be Tensor type. Sequence and Maps are not yet supported.
55+
/// OnnxRuntime currently works on Windows and Ubuntu 16.04 Linux 64-bit platforms. Mac OS to be supported soon.
56+
/// Visit [ONNX Models](https://github.com/onnx/models) to see a list of readily available models to get started with.
57+
/// Refer to [ONNX](http://onnx.ai) for more information.
58+
///
59+
/// To create this estimator use the following:
60+
/// [ApplyOnnxModel](xref:Microsoft.ML.OnnxCatalog.ApplyOnnxModel*)
61+
/// ]]>
62+
/// </format>
6063
/// </remarks>
6164
public sealed class OnnxTransformer : RowToRowTransformerBase
6265
{

src/Microsoft.ML.StandardTrainers/Standard/MulticlassClassification/MulticlassNaiveBayesTrainer.cs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,38 @@
2727
namespace Microsoft.ML.Trainers
2828
{
2929
/// <summary>
30-
/// Naive Bayes classifier is based on Bayes' theorem. It assumes independence among the presence of features
31-
/// in a class even though they may be dependent on each other. It is a multi-class trainer that accepts
32-
/// binary feature values of type float, i.e., feature values are either true or false, specifically a
33-
/// feature value greater than zero is treated as true.
30+
/// The <see cref="IEstimator{TTransformer}"/> for training a multiclass Naive Bayes predictor that supports binary feature values.
3431
/// </summary>
32+
/// <remarks>
33+
/// <format type="text/markdown"><![CDATA[
34+
/// To create this trainer, use [NaiveBayes](xref:Microsoft.ML.StandardTrainersCatalog.NaiveBayes(Microsoft.ML.MulticlassClassificationCatalog.MulticlassClassificationTrainers,System.String,System.String)).
35+
///
36+
/// [!include[io](~/../docs/samples/docs/api-reference/io-columns-multiclass-classification.md)]
37+
///
38+
/// ### Trainer Characteristics
39+
/// | | |
40+
/// | -- | -- |
41+
/// | Machine learning task | Multiclass classification |
42+
/// | Is normalization required? | Yes |
43+
/// | Is caching required? | No |
44+
/// | Required NuGet in addition to Microsoft.ML | None |
45+
///
46+
/// ### Training Algorithm Details
47+
/// [Naive Bayes](https://en.wikipedia.org/wiki/Naive_Bayes_classifier)
48+
/// is a probabilistic classifier that can be used for multiclass problems.
49+
/// Using Bayes' theorem, the conditional probability for a sample belonging to a class
50+
/// can be calculated based on the sample count for each feature combination groups.
51+
/// However, Naive Bayes Classifier is feasible only if the number of features and
52+
/// the values each feature can take is relatively small.
53+
/// It assumes independence among the presence of features in a class even though
54+
/// they may be dependent on each other.
55+
/// This multi-class trainer accepts "binary" feature values of type float:
56+
/// feature values that are greater than zero are treated as true and feature values
57+
/// that are less or equal to 0 are treated as false.
58+
/// ]]>
59+
/// </format>
60+
/// </remarks>
61+
/// <seealso cref="StandardTrainersCatalog.NaiveBayes(Microsoft.ML.MulticlassClassificationCatalog.MulticlassClassificationTrainers,System.String,System.String)"/>
3562
public sealed class NaiveBayesMulticlassTrainer : TrainerEstimatorBase<MulticlassPredictionTransformer<NaiveBayesMulticlassModelParameters>, NaiveBayesMulticlassModelParameters>
3663
{
3764
internal const string LoadName = "MultiClassNaiveBayes";

src/Microsoft.ML.StandardTrainers/Standard/MulticlassClassification/OneVersusAllTrainer.cs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
[assembly: LoadableClass(OneVersusAllTrainer.Summary, typeof(OneVersusAllTrainer), typeof(OneVersusAllTrainer.Options),
2525
new[] { typeof(SignatureMulticlassClassifierTrainer), typeof(SignatureTrainer) },
2626
OneVersusAllTrainer.UserNameValue,
27-
OneVersusAllTrainer.LoadNameValue, DocName = "trainer/OvaPkpd.md")]
27+
OneVersusAllTrainer.LoadNameValue)]
2828

2929
[assembly: LoadableClass(typeof(OneVersusAllModelParameters), null, typeof(SignatureLoadModel),
3030
"OVA Executor",
@@ -37,7 +37,49 @@ namespace Microsoft.ML.Trainers
3737
using TDistPredictor = IDistPredictorProducing<float, float>;
3838
using TScalarPredictor = IPredictorProducing<float>;
3939
using TScalarTrainer = ITrainerEstimator<ISingleFeaturePredictionTransformer<IPredictorProducing<float>>, IPredictorProducing<float>>;
40-
40+
/// <summary>
41+
/// The <see cref="IEstimator{TTransformer}"/> for training a one-versus-all multi-class classifier on top of the specified binary classifier.
42+
/// </summary>
43+
/// <remarks>
44+
/// <format type="text/markdown"><![CDATA[
45+
/// To create this trainer, use [OneVersusAll](xref:Microsoft.ML.StandardTrainersCatalog.OneVersusAll``1(Microsoft.ML.MulticlassClassificationCatalog.MulticlassClassificationTrainers,Microsoft.ML.Trainers.ITrainerEstimator{Microsoft.ML.Data.BinaryPredictionTransformer{``0},``0},System.String,System.Boolean,Microsoft.ML.IEstimator{Microsoft.ML.ISingleFeaturePredictionTransformer{Microsoft.ML.Calibrators.ICalibrator}},System.Int32,System.Boolean)).
46+
///
47+
/// [!include[io](~/../docs/samples/docs/api-reference/io-columns-multiclass-classification.md)]
48+
///
49+
/// ### Trainer Characteristics
50+
/// | | |
51+
/// | -- | -- |
52+
/// | Machine learning task | Multiclass classification |
53+
/// | Is normalization required? | Depends on underline binary classifier |
54+
/// | Is caching required? | Depends on underline binary classifier |
55+
/// | Required NuGet in addition to Microsoft.ML | None |
56+
///
57+
/// ### Training Algorithm Details
58+
/// In this strategy, a binary classification algorithm is used to train one classifier for each class,
59+
/// which distinguishes that class from all other classes. Prediction is then performed by running
60+
/// these binary classifiers and choosing the prediction with the highest confidence score.
61+
/// This algorithm can be used with any of the binary classifiers in ML.NET. A few binary classifiers
62+
/// already have implementation for multi-class problems, thus users can choose either one depending on the context.
63+
/// The OVA version of a binary classifier, such as wrapping a LightGbmBinaryClassifier ,
64+
/// can be different from LightGbmClassifier, which develops a multi-class classifier directly.
65+
/// Note that even if the classifier indicates that it does not need caching, OneVersusAll will always
66+
/// request caching, as it will be performing multiple passes over the data set.
67+
/// This trainer will request normalization from the data pipeline if the classifier indicates it would benefit from it.
68+
///
69+
/// This can allow you to exploit trainers that do not naturally have a
70+
/// multiclass option, for example, using the FastTree Binary Classification
71+
/// to solve a multiclass problem.
72+
/// Alternately, it can allow ML.NET to solve a "simpler" problem even in the cases
73+
/// where the trainer has a multiclass option, but using it directly is not
74+
/// practical due to, usually, memory constraints. For example, while a multiclass
75+
/// logistic regression is a more principled way to solve a multiclass problem, it
76+
/// requires that the trainer store a lot more intermediate state in the form of
77+
/// L-BFGS history for all classes *simultaneously*, rather than just one-by-one
78+
/// as would be needed for a one-versus-all classification model.
79+
/// ]]>
80+
/// </format>
81+
/// </remarks>
82+
/// <seealso cref="StandardTrainersCatalog.OneVersusAll{TModel}(MulticlassClassificationCatalog.MulticlassClassificationTrainers, ITrainerEstimator{BinaryPredictionTransformer{TModel}, TModel}, string, bool, IEstimator{ISingleFeaturePredictionTransformer{ICalibrator}}, int, bool)" />
4183
public sealed class OneVersusAllTrainer : MetaMulticlassTrainer<MulticlassPredictionTransformer<OneVersusAllModelParameters>, OneVersusAllModelParameters>
4284
{
4385
internal const string LoadNameValue = "OVA";

0 commit comments

Comments
 (0)