Skip to content

Commit 7a445b2

Browse files
committed
update with latest master
2 parents cb78dee + 8cf2596 commit 7a445b2

File tree

113 files changed

+798
-29157
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+798
-29157
lines changed

Microsoft.ML.sln

+1-12
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.StandardLearne
2323
EndProject
2424
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.Transforms", "src\Microsoft.ML.Transforms\Microsoft.ML.Transforms.csproj", "{2911A286-ECA4-4730-97A9-DA1FEE2DED97}"
2525
EndProject
26-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.Legacy", "src\Microsoft.ML.Legacy\Microsoft.ML.Legacy.csproj", "{7288C084-11C0-43BE-AC7F-45DCFEAEEBF6}"
27-
EndProject
2826
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.KMeansClustering", "src\Microsoft.ML.KMeansClustering\Microsoft.ML.KMeansClustering.csproj", "{F1CAE3AB-4F86-4BC0-BBA8-C4A58E7E8A4A}"
2927
EndProject
3028
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.PCA", "src\Microsoft.ML.PCA\Microsoft.ML.PCA.csproj", "{58E06735-1129-4DD5-86E0-6BBFF049AAD9}"
@@ -147,7 +145,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.HalLearners.St
147145
EndProject
148146
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.OnnxTransform.StaticPipe", "src\Microsoft.ML.OnnxTransform.StaticPipe\Microsoft.ML.OnnxTransform.StaticPipe.csproj", "{D1324668-9568-40F4-AA55-30A9A516C230}"
149147
EndProject
150-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.ML.LightGBM.StaticPipe", "src\Microsoft.ML.LightGBM.StaticPipe\Microsoft.ML.LightGBM.StaticPipe.csproj", "{22C51B08-ACAE-47B2-A312-462DC239A23B}"
148+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.LightGBM.StaticPipe", "src\Microsoft.ML.LightGBM.StaticPipe\Microsoft.ML.LightGBM.StaticPipe.csproj", "{22C51B08-ACAE-47B2-A312-462DC239A23B}"
151149
EndProject
152150
Global
153151
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -213,14 +211,6 @@ Global
213211
{2911A286-ECA4-4730-97A9-DA1FEE2DED97}.Release|Any CPU.Build.0 = Release|Any CPU
214212
{2911A286-ECA4-4730-97A9-DA1FEE2DED97}.Release-Intrinsics|Any CPU.ActiveCfg = Release-Intrinsics|Any CPU
215213
{2911A286-ECA4-4730-97A9-DA1FEE2DED97}.Release-Intrinsics|Any CPU.Build.0 = Release-Intrinsics|Any CPU
216-
{7288C084-11C0-43BE-AC7F-45DCFEAEEBF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
217-
{7288C084-11C0-43BE-AC7F-45DCFEAEEBF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
218-
{7288C084-11C0-43BE-AC7F-45DCFEAEEBF6}.Debug-Intrinsics|Any CPU.ActiveCfg = Debug-Intrinsics|Any CPU
219-
{7288C084-11C0-43BE-AC7F-45DCFEAEEBF6}.Debug-Intrinsics|Any CPU.Build.0 = Debug-Intrinsics|Any CPU
220-
{7288C084-11C0-43BE-AC7F-45DCFEAEEBF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
221-
{7288C084-11C0-43BE-AC7F-45DCFEAEEBF6}.Release|Any CPU.Build.0 = Release|Any CPU
222-
{7288C084-11C0-43BE-AC7F-45DCFEAEEBF6}.Release-Intrinsics|Any CPU.ActiveCfg = Release-Intrinsics|Any CPU
223-
{7288C084-11C0-43BE-AC7F-45DCFEAEEBF6}.Release-Intrinsics|Any CPU.Build.0 = Release-Intrinsics|Any CPU
224214
{F1CAE3AB-4F86-4BC0-BBA8-C4A58E7E8A4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
225215
{F1CAE3AB-4F86-4BC0-BBA8-C4A58E7E8A4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
226216
{F1CAE3AB-4F86-4BC0-BBA8-C4A58E7E8A4A}.Debug-Intrinsics|Any CPU.ActiveCfg = Debug-Intrinsics|Any CPU
@@ -593,7 +583,6 @@ Global
593583
{65D0603E-B96C-4DFC-BDD1-705891B88C18} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
594584
{707BB22C-7E5F-497A-8C2F-74578F675705} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
595585
{2911A286-ECA4-4730-97A9-DA1FEE2DED97} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
596-
{7288C084-11C0-43BE-AC7F-45DCFEAEEBF6} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
597586
{F1CAE3AB-4F86-4BC0-BBA8-C4A58E7E8A4A} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
598587
{58E06735-1129-4DD5-86E0-6BBFF049AAD9} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
599588
{64BC22D3-1E76-41EF-94D8-C79E471FF2DD} = {AED9C836-31E3-4F3F-8ABC-929555D3F3C4}

docs/release-notes/0.9/release-0.9.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# ML.NET 0.9 Release Notes
2+
3+
Welcome to 2019! For the past 9 months we have been adding features and improving [ML.NET](https://aka.ms/mlnet). In the forthcoming 0.10, 0.11, and 0.12 releases before we reach 1.0, we will focus on the overall stability of the package, continue to refine the API, increase test coverage and improve documentation. 0.9 release packs multiple fixes as well as significant clean up to the internal code of the package.
4+
5+
### Installation
6+
7+
ML.NET supports Windows, MacOS, and Linux. See [supported OS versions of .NET
8+
Core
9+
2.0](https://github.com/dotnet/core/blob/master/release-notes/2.0/2.0-supported-os.md)
10+
for more details.
11+
12+
You can install ML.NET NuGet from the CLI using:
13+
```
14+
dotnet add package Microsoft.ML
15+
```
16+
17+
From package manager:
18+
```
19+
Install-Package Microsoft.ML
20+
```
21+
22+
### Release Notes
23+
24+
Below are a few of the highlights from this release. There are many other improvements in the API.
25+
26+
* Added Feature Contribution Calculation
27+
([#1847](https://github.com/dotnet/machinelearning/pull/1847))
28+
29+
* FCC can be used to compute feature contributions in addition to the overall prediction when models are evaluated.
30+
31+
* Removed Legacy namespace that was marked obsolete
32+
([#2043](https://github.com/dotnet/machinelearning/pull/2043))
33+
34+
* GPU support for ONNX Transform
35+
([#1922](https://github.com/dotnet/machinelearning/pull/1922))
36+
37+
* GPU is currently supported on 64 bit Windows
38+
* Cross platform support is still being developed for this feature
39+
40+
* `Permutation Feature Importance` now supports confidence intervals
41+
([#1844](https://github.com/dotnet/machinelearning/pull/1844))
42+
43+
* Introducing `PredictionEngine` instead of `PredictionFunction`
44+
([#1920](https://github.com/dotnet/machinelearning/pull/1920))
45+
46+
### Acknowledgements
47+
48+
Shoutout to [dhilmathy](https://github.com/dhilmathy),
49+
[mnboos](https://github.com/mnboos),
50+
[robosek](https://github.com/robosek), and the [ML.NET](https://aka.ms/mlnet) team for their
51+
contributions as part of this release!

docs/samples/Microsoft.ML.Samples/Dynamic/FeatureContributionCalculationTransform.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ public static void FeatureContributionCalculationTransform_Regression()
5959
// Create a Feature Contribution Calculator
6060
// Calculate the feature contributions for all features given trained model parameters
6161
// And don't normalize the contribution scores
62-
var featureContributionCalculator = mlContext.Model.Explainability.FeatureContributionCalculation(model.Model, model.FeatureColumn, top: 11, normalize: false);
62+
var featureContributionCalculator = mlContext.Model.Explainability.FeatureContributionCalculation(model.Model, model.FeatureColumn, numPositiveContributions: 11, normalize: false);
6363
var outputData = featureContributionCalculator.Fit(scoredData).Transform(scoredData);
6464

6565
// FeatureContributionCalculatingEstimator can be use as an intermediary step in a pipeline.
6666
// The features retained by FeatureContributionCalculatingEstimator will be in the FeatureContribution column.
67-
var pipeline = mlContext.Model.Explainability.FeatureContributionCalculation(model.Model, model.FeatureColumn, top: 11)
67+
var pipeline = mlContext.Model.Explainability.FeatureContributionCalculation(model.Model, model.FeatureColumn, numPositiveContributions: 11)
6868
.Append(mlContext.Regression.Trainers.OrdinaryLeastSquares(featureColumn: "FeatureContributions"));
6969
var outData = featureContributionCalculator.Fit(scoredData).Transform(scoredData);
7070

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using Microsoft.ML.Data;
2+
using Microsoft.ML.LightGBM.StaticPipe;
3+
using Microsoft.ML.SamplesUtils;
4+
using Microsoft.ML.StaticPipe;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
9+
namespace Microsoft.ML.Samples.Static
10+
{
11+
class LightGBMMulticlassWithInMemoryData
12+
{
13+
public void MultiClassLightGbmStaticPipelineWithInMemoryData()
14+
{
15+
// Create a general context for ML.NET operations. It can be used for exception tracking and logging,
16+
// as a catalog of available operations and as the source of randomness.
17+
var mlContext = new MLContext();
18+
19+
// Create in-memory examples as C# native class.
20+
var examples = DatasetUtils.GenerateRandomMulticlassClassificationExamples(1000);
21+
22+
// Convert native C# class to IDataView, a consumble format to ML.NET functions.
23+
var dataView = ComponentCreation.CreateDataView(mlContext, examples);
24+
25+
// IDataView is the data format used in dynamic-typed pipeline. To use static-typed pipeline, we need to convert
26+
// IDataView to DataView by calling AssertStatic(...). The basic idea is to specify the static type for each column
27+
// in IDataView in a lambda function.
28+
var staticDataView = dataView.AssertStatic(mlContext, c => (
29+
Features: c.R4.Vector,
30+
Label: c.Text.Scalar));
31+
32+
// Create static pipeline. First, we make an estimator out of static DataView as the starting of a pipeline.
33+
// Then, we append necessary transforms and a classifier to the starting estimator.
34+
var pipe = staticDataView.MakeNewEstimator()
35+
.Append(mapper: r => (
36+
r.Label,
37+
// Train multi-class LightGBM. The trained model maps Features to Label and probability of each class.
38+
// The call of ToKey() is needed to convert string labels to integer indexes.
39+
Predictions: mlContext.MulticlassClassification.Trainers.LightGbm(r.Label.ToKey(), r.Features)
40+
))
41+
.Append(r => (
42+
// Actual label.
43+
r.Label,
44+
// Labels are converted to keys when training LightGBM so we convert it here again for calling evaluation function.
45+
LabelIndex: r.Label.ToKey(),
46+
// Used to compute metrics such as accuracy.
47+
r.Predictions,
48+
// Assign a new name to predicted class index.
49+
PredictedLabelIndex: r.Predictions.predictedLabel,
50+
// Assign a new name to class probabilities.
51+
Scores: r.Predictions.score
52+
));
53+
54+
// Split the static-typed data into training and test sets. Only training set is used in fitting
55+
// the created pipeline. Metrics are computed on the test.
56+
var (trainingData, testingData) = mlContext.MulticlassClassification.TrainTestSplit(staticDataView, testFraction: 0.5);
57+
58+
// Train the model.
59+
var model = pipe.Fit(trainingData);
60+
61+
// Do prediction on the test set.
62+
var prediction = model.Transform(testingData);
63+
64+
// Evaluate the trained model is the test set.
65+
var metrics = mlContext.MulticlassClassification.Evaluate(prediction, r => r.LabelIndex, r => r.Predictions);
66+
67+
// Check if metrics are resonable.
68+
Console.WriteLine ("Macro accuracy: {0}, Micro accuracy: {1}.", 0.863482146891263, 0.86309523809523814);
69+
70+
// Convert prediction in ML.NET format to native C# class.
71+
var nativePredictions = new List<DatasetUtils.MulticlassClassificationExample>(prediction.AsDynamic.AsEnumerable<DatasetUtils.MulticlassClassificationExample>(mlContext, false));
72+
73+
// Get schema object out of the prediction. It contains metadata such as the mapping from predicted label index
74+
// (e.g., 1) to its actual label (e.g., "AA"). The call to "AsDynamic" converts our statically-typed pipeline into
75+
// a dynamically-typed one only for extracting metadata. In the future, metadata in statically-typed pipeline should
76+
// be accessible without dynamically-typed things.
77+
var schema = prediction.AsDynamic.Schema;
78+
79+
// Retrieve the mapping from labels to label indexes.
80+
var labelBuffer = new VBuffer<ReadOnlyMemory<char>>();
81+
schema[nameof(DatasetUtils.MulticlassClassificationExample.PredictedLabelIndex)].Metadata.GetValue("KeyValues", ref labelBuffer);
82+
// nativeLabels is { "AA" , "BB", "CC", "DD" }
83+
var nativeLabels = labelBuffer.DenseValues().ToArray(); // nativeLabels[nativePrediction.PredictedLabelIndex - 1] is the original label indexed by nativePrediction.PredictedLabelIndex.
84+
85+
86+
// Show prediction result for the 3rd example.
87+
var nativePrediction = nativePredictions[2];
88+
// Console output:
89+
// Our predicted label to this example is "AA" with probability 0.922597349.
90+
Console.WriteLine("Our predicted label to this example is {0} with probability {1}",
91+
nativeLabels[(int)nativePrediction.PredictedLabelIndex - 1],
92+
nativePrediction.Scores[(int)nativePrediction.PredictedLabelIndex - 1]);
93+
94+
var expectedProbabilities = new float[] { 0.922597349f, 0.07508608f, 0.00221699756f, 9.95488E-05f };
95+
// Scores and nativeLabels are two parallel attributes; that is, Scores[i] is the probability of being nativeLabels[i].
96+
// Console output:
97+
// The probability of being class "AA" is 0.922597349.
98+
// The probability of being class "BB" is 0.07508608.
99+
// The probability of being class "CC" is 0.00221699756.
100+
// The probability of being class "DD" is 9.95488E-05.
101+
for (int i = 0; i < labelBuffer.Length; ++i)
102+
Console.WriteLine("The probability of being class {0} is {1}.", nativeLabels[i], nativePrediction.Scores[i]);
103+
}
104+
}
105+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Pack">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<PackageDescription>ML.NET component for a statically typed API.</PackageDescription>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="../Microsoft.ML/Microsoft.ML.nupkgproj" />
10+
<ProjectReference Include="../Microsoft.ML.ImageAnalytics/Microsoft.ML.ImageAnalytics.nupkgproj" />
11+
<ProjectReference Include="../Microsoft.ML.MatrixFactorization/Microsoft.ML.MatrixFactorization.nupkgproj" />
12+
</ItemGroup>
13+
14+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project DefaultTargets="Pack">
2+
3+
<Import Project="Microsoft.ML.StaticPipe.nupkgproj" />
4+
5+
</Project>

0 commit comments

Comments
 (0)