forked from dotnet/machinelearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebuggerExtensions.cs
More file actions
64 lines (58 loc) · 3.35 KB
/
Copy pathDebuggerExtensions.cs
File metadata and controls
64 lines (58 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.ML.Core.Data;
using Microsoft.ML.Data;
using Microsoft.ML.Transforms;
namespace Microsoft.ML
{
/// <summary>
/// Static extensions for data preview.
/// </summary>
public static class DebuggerExtensions
{
/// <summary>
/// Extract a 'head' of the data view in a view that is convenient to debug.
/// </summary>
/// <param name="data">The data view to preview</param>
/// <param name="maxRows">Maximum number of rows to pull</param>
public static DataDebuggerPreview Preview(this IDataView data, int maxRows = DataDebuggerPreview.Defaults.MaxRows)
=> new DataDebuggerPreview(data, maxRows);
/// <summary>
/// Preview an effect of the <paramref name="transformer"/> on a given <paramref name="data"/>.
/// </summary>
/// <param name="transformer">The transformer which effect we are previewing</param>
/// <param name="data">The data view to use for preview</param>
/// <param name="maxRows">Maximum number of rows to pull</param>
public static DataDebuggerPreview Preview(this ITransformer transformer, IDataView data, int maxRows = DataDebuggerPreview.Defaults.MaxRows)
=> new DataDebuggerPreview(transformer.Transform(data), maxRows);
/// <summary>
/// Preview an effect of the <paramref name="estimator"/> on a given <paramref name="data"/>.
/// </summary>
/// <param name="estimator">The estimnator which effect we are previewing</param>
/// <param name="data">The data view to use for preview</param>
/// <param name="maxRows">Maximum number of rows to show in preview</param>
/// <param name="maxTrainingRows">Maximum number of rows to fit the estimator</param>
public static DataDebuggerPreview Preview(this IEstimator<ITransformer> estimator, IDataView data, int maxRows = DataDebuggerPreview.Defaults.MaxRows,
int maxTrainingRows = DataDebuggerPreview.Defaults.MaxRows)
{
Contracts.CheckValue(estimator, nameof(estimator));
Contracts.CheckValue(data, nameof(data));
Contracts.CheckParam(maxRows >= 0, nameof(maxRows));
Contracts.CheckParam(maxTrainingRows >= 0, nameof(maxTrainingRows));
using (var env = new LocalEnvironment(conc: 1))
{
var trainData = SkipTakeFilter.Create(env, new SkipTakeFilter.TakeArguments { Count = maxTrainingRows }, data);
return new DataDebuggerPreview(estimator.Fit(trainData).Transform(data), maxRows);
}
}
/// <summary>
/// Preview an effect of the <paramref name="reader"/> on a given <paramref name="source"/>.
/// </summary>
/// <param name="reader">The data reader to preview</param>
/// <param name="source">The source to pull the data from</param>
/// <param name="maxRows">Maximum number of rows to pull</param>
public static DataDebuggerPreview Preview<TSource>(this IDataReader<TSource> reader, TSource source, int maxRows = DataDebuggerPreview.Defaults.MaxRows)
=> new DataDebuggerPreview(reader.Read(source), maxRows);
}
}