Skip to content

Commit e3aea3b

Browse files
author
Ivan Matantsev
committed
Merge branch 'feature/estimators' of https://github.com/Zruty0/machinelearning into feature/estimators
2 parents 8b65829 + 9fd480e commit e3aea3b

File tree

72 files changed

+9661
-817
lines changed

Some content is hidden

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

72 files changed

+9661
-817
lines changed

Microsoft.ML.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.CodeAnalyzer",
9797
EndProject
9898
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.CodeAnalyzer.Tests", "test\Microsoft.ML.CodeAnalyzer.Tests\Microsoft.ML.CodeAnalyzer.Tests.csproj", "{3E4ABF07-7970-4BE6-B45B-A13D3C397545}"
9999
EndProject
100+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.ImageAnalytics", "src\Microsoft.ML.ImageAnalytics\Microsoft.ML.ImageAnalytics.csproj", "{00E38F77-1E61-4CDF-8F97-1417D4E85053}"
101+
EndProject
102+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.HalLearners", "src\Microsoft.ML.HalLearners\Microsoft.ML.HalLearners.csproj", "{A7222F41-1CF0-47D9-B80C-B4D77B027A61}"
103+
EndProject
100104
Global
101105
GlobalSection(SolutionConfigurationPlatforms) = preSolution
102106
Debug|Any CPU = Debug|Any CPU
@@ -329,6 +333,22 @@ Global
329333
{3E4ABF07-7970-4BE6-B45B-A13D3C397545}.Release|Any CPU.Build.0 = Release|Any CPU
330334
{3E4ABF07-7970-4BE6-B45B-A13D3C397545}.Release-Intrinsics|Any CPU.ActiveCfg = Release|Any CPU
331335
{3E4ABF07-7970-4BE6-B45B-A13D3C397545}.Release-Intrinsics|Any CPU.Build.0 = Release|Any CPU
336+
{00E38F77-1E61-4CDF-8F97-1417D4E85053}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
337+
{00E38F77-1E61-4CDF-8F97-1417D4E85053}.Debug|Any CPU.Build.0 = Debug|Any CPU
338+
{00E38F77-1E61-4CDF-8F97-1417D4E85053}.Debug-Intrinsics|Any CPU.ActiveCfg = Debug|Any CPU
339+
{00E38F77-1E61-4CDF-8F97-1417D4E85053}.Debug-Intrinsics|Any CPU.Build.0 = Debug|Any CPU
340+
{00E38F77-1E61-4CDF-8F97-1417D4E85053}.Release|Any CPU.ActiveCfg = Release|Any CPU
341+
{00E38F77-1E61-4CDF-8F97-1417D4E85053}.Release|Any CPU.Build.0 = Release|Any CPU
342+
{00E38F77-1E61-4CDF-8F97-1417D4E85053}.Release-Intrinsics|Any CPU.ActiveCfg = Release|Any CPU
343+
{00E38F77-1E61-4CDF-8F97-1417D4E85053}.Release-Intrinsics|Any CPU.Build.0 = Release|Any CPU
344+
{A7222F41-1CF0-47D9-B80C-B4D77B027A61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
345+
{A7222F41-1CF0-47D9-B80C-B4D77B027A61}.Debug|Any CPU.Build.0 = Debug|Any CPU
346+
{A7222F41-1CF0-47D9-B80C-B4D77B027A61}.Debug-Intrinsics|Any CPU.ActiveCfg = Debug|Any CPU
347+
{A7222F41-1CF0-47D9-B80C-B4D77B027A61}.Debug-Intrinsics|Any CPU.Build.0 = Debug|Any CPU
348+
{A7222F41-1CF0-47D9-B80C-B4D77B027A61}.Release|Any CPU.ActiveCfg = Release|Any CPU
349+
{A7222F41-1CF0-47D9-B80C-B4D77B027A61}.Release|Any CPU.Build.0 = Release|Any CPU
350+
{A7222F41-1CF0-47D9-B80C-B4D77B027A61}.Release-Intrinsics|Any CPU.ActiveCfg = Release|Any CPU
351+
{A7222F41-1CF0-47D9-B80C-B4D77B027A61}.Release-Intrinsics|Any CPU.Build.0 = Release|Any CPU
332352
EndGlobalSection
333353
GlobalSection(SolutionProperties) = preSolution
334354
HideSolutionNode = FALSE
@@ -367,6 +387,8 @@ Global
367387
{BF66A305-DF10-47E4-8D81-42049B149D2B} = {D3D38B03-B557-484D-8348-8BADEE4DF592}
368388
{B4E55B2D-2A92-46E7-B72F-E76D6FD83440} = {7F13E156-3EBA-4021-84A5-CD56BA72F99E}
369389
{3E4ABF07-7970-4BE6-B45B-A13D3C397545} = {AED9C836-31E3-4F3F-8ABC-929555D3F3C4}
390+
{00E38F77-1E61-4CDF-8F97-1417D4E85053} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
391+
{A7222F41-1CF0-47D9-B80C-B4D77B027A61} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
370392
EndGlobalSection
371393
GlobalSection(ExtensibilityGlobals) = postSolution
372394
SolutionGuid = {41165AF1-35BB-4832-A189-73060F82B01D}

build.proj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
Targets="Restore" />
4545
</Target>
4646

47-
<Target Name="BuildNative" Condition="'$(SkipNativeBuild)' != 'true'">
47+
<Target Name="BuildNative"
48+
Condition="'$(SkipNativeBuild)' != 'true'"
49+
DependsOnTargets="RestoreProjects">
4850
<Message Importance="High" Text="Building native components..." />
4951
<MSBuild Projects="src/Native/build.proj"
5052
Targets="Build" />

build/Dependencies.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<SystemReflectionEmitLightweightPackageVersion>4.3.0</SystemReflectionEmitLightweightPackageVersion>
99
<PublishSymbolsPackageVersion>1.0.0-beta-62824-02</PublishSymbolsPackageVersion>
1010
<LightGBMPackageVersion>2.1.2.2</LightGBMPackageVersion>
11-
<MlNetMklDepsPackageVersion>0.0.0.1</MlNetMklDepsPackageVersion>
11+
<MlNetMklDepsPackageVersion>0.0.0.5</MlNetMklDepsPackageVersion>
12+
<SystemDrawingCommonPackageVersion>4.5.0</SystemDrawingCommonPackageVersion>
1213
</PropertyGroup>
1314
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Pack">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<PackageDescription>ML.NET additional learners making use of hardware acceleration. They depend on the MlNetMklDeps NuGet package.</PackageDescription>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="../Microsoft.ML/Microsoft.ML.nupkgproj" />
10+
<PackageReference Include="MlNetMklDeps" Version="$(MlNetMklDepsPackageVersion)" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project DefaultTargets="Pack">
2+
3+
<Import Project="Microsoft.ML.HalLearners.nupkgproj" />
4+
5+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Pack">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<PackageDescription>ML.NET component for Image support</PackageDescription>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="../Microsoft.ML/Microsoft.ML.nupkgproj" />
10+
<PackageReference Include="System.Drawing.Common" Version="$(SystemDrawingCommonPackageVersion)" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project DefaultTargets="Pack">
2+
3+
<Import Project="Microsoft.ML.ImageAnalytics.nupkgproj" />
4+
5+
</Project>

src/Microsoft.ML.Console/Microsoft.ML.Console.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<ProjectReference Include="..\Microsoft.ML.Data\Microsoft.ML.Data.csproj" />
1616
<ProjectReference Include="..\Microsoft.ML.Ensemble\Microsoft.ML.Ensemble.csproj" />
1717
<ProjectReference Include="..\Microsoft.ML.FastTree\Microsoft.ML.FastTree.csproj" />
18+
<ProjectReference Include="..\Microsoft.ML.HalLearners\Microsoft.ML.HalLearners.csproj" />
1819
<ProjectReference Include="..\Microsoft.ML.KMeansClustering\Microsoft.ML.KMeansClustering.csproj" />
1920
<ProjectReference Include="..\Microsoft.ML.LightGBM\Microsoft.ML.LightGBM.csproj" />
2021
<ProjectReference Include="..\Microsoft.ML.Maml\Microsoft.ML.Maml.csproj" />

src/Microsoft.ML.Core/ComponentModel/ComponentCatalog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ private static bool ShouldSkipPath(string path)
343343
case "libvw.dll":
344344
case "matrixinterf.dll":
345345
case "Microsoft.ML.neuralnetworks.gpucuda.dll":
346-
case "Microsoft.ML.mklimports.dll":
346+
case "MklImports.dll":
347347
case "microsoft.research.controls.decisiontrees.dll":
348348
case "Microsoft.ML.neuralnetworks.sse.dll":
349349
case "neuraltreeevaluator.dll":

src/Microsoft.ML.Data/Transforms/TrainAndScoreTransform.cs

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,32 @@ public sealed class Arguments : TransformInputBase
4646

4747
internal const string Summary = "Runs a previously trained predictor on the data.";
4848

49+
/// <summary>
50+
/// Convenience method for creating <see cref="ScoreTransform"/>.
51+
/// The <see cref="ScoreTransform"/> allows for model stacking (i.e. to combine information from multiple predictive models to generate a new model)
52+
/// in the pipeline by using the scores from an already trained model.
53+
/// </summary>
54+
/// <param name="env">Host Environment.</param>
55+
/// <param name="input">Input <see cref="IDataView"/>.</param>
56+
/// <param name="inputModelFile">The model file.</param>
57+
/// <param name="featureColumn">Role name for the features.</param>
58+
/// <param name="groupColumn">Role name for the group column.</param>
59+
public static IDataTransform Create(IHostEnvironment env,
60+
IDataView input,
61+
string inputModelFile,
62+
string featureColumn = DefaultColumnNames.Features,
63+
string groupColumn = DefaultColumnNames.GroupId)
64+
{
65+
var args = new Arguments()
66+
{
67+
FeatureColumn = featureColumn,
68+
GroupColumn = groupColumn,
69+
InputModelFile = inputModelFile
70+
};
71+
72+
return Create(env, args, input);
73+
}
74+
4975
public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataView input)
5076
{
5177
Contracts.CheckValue(env, nameof(env));
@@ -62,9 +88,9 @@ public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataV
6288
}
6389

6490
string feat = TrainUtils.MatchNameOrDefaultOrNull(env, input.Schema,
65-
"featureColumn", args.FeatureColumn, DefaultColumnNames.Features);
91+
nameof(args.FeatureColumn), args.FeatureColumn, DefaultColumnNames.Features);
6692
string group = TrainUtils.MatchNameOrDefaultOrNull(env, input.Schema,
67-
"groupColumn", args.GroupColumn, DefaultColumnNames.GroupId);
93+
nameof(args.GroupColumn), args.GroupColumn, DefaultColumnNames.GroupId);
6894
var customCols = TrainUtils.CheckAndGenerateCustomColumns(env, args.CustomColumn);
6995

7096
return ScoreUtils.GetScorer(args.Scorer, predictor, input, feat, group, customCols, env, trainSchema);
@@ -131,20 +157,66 @@ public sealed class Arguments : ArgumentsBase<SignatureTrainer>
131157

132158
internal const string Summary = "Trains a predictor, or loads it from a file, and runs it on the data.";
133159

160+
/// <summary>
161+
/// Convenience method for creating <see cref="TrainAndScoreTransform"/>.
162+
/// The <see cref="TrainAndScoreTransform"/> allows for model stacking (i.e. to combine information from multiple predictive models to generate a new model)
163+
/// in the pipeline by training a model first and then using the scores from the trained model.
164+
///
165+
/// Unlike <see cref="ScoreTransform"/>, the <see cref="TrainAndScoreTransform"/> trains the model on the fly as name indicates.
166+
/// </summary>
167+
/// <param name="env">Host Environment.</param>
168+
/// <param name="input">Input <see cref="IDataView"/>.</param>
169+
/// <param name="trainer">The <see cref="ITrainer"/> object i.e. the learning algorithm that will be used for training the model.</param>
170+
/// <param name="featureColumn">Role name for features.</param>
171+
/// <param name="labelColumn">Role name for label.</param>
172+
/// <param name="groupColumn">Role name for the group column.</param>
173+
public static IDataTransform Create(IHostEnvironment env,
174+
IDataView input,
175+
ITrainer trainer,
176+
string featureColumn = DefaultColumnNames.Features,
177+
string labelColumn = DefaultColumnNames.Label,
178+
string groupColumn = DefaultColumnNames.GroupId)
179+
{
180+
Contracts.CheckValue(env, nameof(env));
181+
env.CheckValue(input, nameof(input));
182+
env.CheckValue(trainer, nameof(trainer));
183+
env.CheckValue(featureColumn, nameof(featureColumn));
184+
env.CheckValue(labelColumn, nameof(labelColumn));
185+
env.CheckValue(groupColumn, nameof(groupColumn));
186+
187+
var args = new Arguments()
188+
{
189+
FeatureColumn = featureColumn,
190+
LabelColumn = labelColumn,
191+
GroupColumn = groupColumn
192+
};
193+
194+
return Create(env, args, trainer, input);
195+
}
196+
134197
public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataView input)
135198
{
136199
Contracts.CheckValue(env, nameof(env));
137200
env.CheckValue(args, nameof(args));
138-
env.CheckValue(input, nameof(input));
139201
env.CheckUserArg(args.Trainer.IsGood(), nameof(args.Trainer),
140202
"Trainer cannot be null. If your model is already trained, please use ScoreTransform instead.");
203+
env.CheckValue(input, nameof(input));
204+
205+
return Create(env, args, args.Trainer.CreateInstance(env), input);
206+
}
207+
208+
private static IDataTransform Create(IHostEnvironment env, Arguments args, ITrainer trainer, IDataView input)
209+
{
210+
Contracts.AssertValue(env, nameof(env));
211+
env.AssertValue(args, nameof(args));
212+
env.AssertValue(trainer, nameof(trainer));
213+
env.AssertValue(input, nameof(input));
141214

142215
var host = env.Register("TrainAndScoreTransform");
143216

144217
using (var ch = host.Start("Train"))
145218
{
146219
ch.Trace("Constructing trainer");
147-
ITrainer trainer = args.Trainer.CreateInstance(host);
148220
var customCols = TrainUtils.CheckAndGenerateCustomColumns(env, args.CustomColumn);
149221
string feat;
150222
string group;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<IncludeInPackage>Microsoft.ML.HalLearners</IncludeInPackage>
6+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\Microsoft.ML.Core\Microsoft.ML.Core.csproj" />
11+
<ProjectReference Include="..\Microsoft.ML.Data\Microsoft.ML.Data.csproj" />
12+
<ProjectReference Include="..\Microsoft.ML.StandardLearners\Microsoft.ML.StandardLearners.csproj" />
13+
<ProjectReference Include="..\Microsoft.ML\Microsoft.ML.csproj" />
14+
<PackageReference Include="MlNetMklDeps" Version="$(MlNetMklDepsPackageVersion)" />
15+
</ItemGroup>
16+
17+
</Project>

src/Microsoft.ML.StandardLearners/Standard/OlsLinearRegression.cs renamed to src/Microsoft.ML.HalLearners/OlsLinearRegression.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
using System;
88
using System.Collections.Generic;
99
using System.IO;
10-
using Microsoft.ML.Runtime.Internal.Internallearn;
1110
using Microsoft.ML.Runtime;
11+
using Microsoft.ML.Runtime.HalLearners;
12+
using Microsoft.ML.Runtime.Internal.Internallearn;
13+
using Microsoft.ML.Runtime.Internal.Utilities;
1214
using Microsoft.ML.Runtime.CommandLine;
1315
using Microsoft.ML.Runtime.Data;
1416
using Microsoft.ML.Runtime.EntryPoints;
1517
using Microsoft.ML.Runtime.Learners;
1618
using Microsoft.ML.Runtime.Model;
17-
using Microsoft.ML.Runtime.Internal.Utilities;
1819
using Microsoft.ML.Runtime.Training;
1920
using System.Runtime.InteropServices;
2021

@@ -30,7 +31,7 @@
3031

3132
[assembly: LoadableClass(typeof(void), typeof(OlsLinearRegressionTrainer), null, typeof(SignatureEntryPointModule), OlsLinearRegressionTrainer.LoadNameValue)]
3233

33-
namespace Microsoft.ML.Runtime.Learners
34+
namespace Microsoft.ML.Runtime.HalLearners
3435
{
3536
/// <include file='doc.xml' path='doc/members/member[@name="OLS"]/*' />
3637
public sealed class OlsLinearRegressionTrainer : TrainerBase<OlsLinearRegressionPredictor>
@@ -220,7 +221,7 @@ private OlsLinearRegressionPredictor TrainCore(IChannel ch, FloatLabelCursor.Fac
220221
catch (DllNotFoundException)
221222
{
222223
// REVIEW: Is there no better way?
223-
throw ch.ExceptNotSupp("The MKL library (Microsoft.ML.MklImports.dll) or one of its dependencies is missing.");
224+
throw ch.ExceptNotSupp("The MKL library (libMklImports) or one of its dependencies is missing.");
224225
}
225226
// Solve for beta in (LL')beta = X'y:
226227
Mkl.Pptrs(Mkl.Layout.RowMajor, Mkl.UpLo.Lo, m, 1, xtx, xty, 1);
@@ -329,7 +330,7 @@ private OlsLinearRegressionPredictor TrainCore(IChannel ch, FloatLabelCursor.Fac
329330

330331
internal static class Mkl
331332
{
332-
private const string DllName = "Microsoft.ML.MklImports.dll";
333+
private const string DllName = "MklImports";
333334

334335
public enum Layout
335336
{
@@ -466,7 +467,7 @@ public static void Pptri(Layout layout, UpLo uplo, int n, Double[] ap)
466467
Desc = "Train an OLS regression model.",
467468
UserName = UserNameValue,
468469
ShortName = ShortName,
469-
XmlInclude = new[] { @"<include file='../Microsoft.ML.StandardLearners/Standard/doc.xml' path='doc/members/member[@name=""OLS""]/*' />" })]
470+
XmlInclude = new[] { @"<include file='../Microsoft.ML.HalLearners/doc.xml' path='doc/members/member[@name=""OLS""]/*' />" })]
470471
public static CommonOutputs.RegressionOutput TrainRegression(IHostEnvironment env, Arguments input)
471472
{
472473
Contracts.CheckValue(env, nameof(env));

0 commit comments

Comments
 (0)