-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Lockdown HAL Project #2497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Lockdown HAL Project #2497
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7806211
Lockdown Hal project
cc5cf79
Merge remote-tracking branch 'upstream/master' into Ivanidze/LockdownHAL
1527369
small updates
a78fccd
Merge branch 'master' into Ivanidze/LockdownHAL
d70c352
merge with master
065207f
Merge with master
002af90
Merge with master
ea9d1d2
merge with master
140d69d
Fix merge conflicts
5b19660
Address comments
e2634e1
Phrasing
b67de2a
Make it build
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...oft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicStochasticGradientDescent.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace Microsoft.ML.Samples.Dynamic | ||
{ | ||
public static class SymbolicStochasticGradientDescent | ||
{ | ||
// This example requires installation of additional nuget package <a href="https://www.nuget.org/packages/Microsoft.ML.HalLearners/">Microsoft.ML.HalLearners</a>. | ||
// In this example we will use the adult income dataset. The goal is to predict | ||
// if a person's income is above $50K or not, based on different pieces of information about that person. | ||
// For more details about this dataset, please see https://archive.ics.uci.edu/ml/datasets/adult | ||
public static void Example() | ||
{ | ||
// Create a new context for ML.NET operations. It can be used for exception tracking and logging, | ||
// as a catalog of available operations and as the source of randomness. | ||
// Setting the seed to a fixed number in this examples to make outputs deterministic. | ||
var mlContext = new MLContext(seed: 0); | ||
|
||
// Download and featurize the dataset. | ||
var data = SamplesUtils.DatasetUtils.LoadFeaturizedAdultDataset(mlContext); | ||
|
||
// Leave out 10% of data for testing. | ||
var split = mlContext.BinaryClassification.TrainTestSplit(data, testFraction: 0.1); | ||
// Create data training pipeline. | ||
var pipeline = mlContext.BinaryClassification.Trainers.SymbolicStochasticGradientDescent(labelColumnName: "IsOver50K", numberOfIterations: 25); | ||
var model = pipeline.Fit(split.TrainSet); | ||
|
||
// Evaluate how the model is doing on the test data. | ||
var dataWithPredictions = model.Transform(split.TestSet); | ||
var metrics = mlContext.BinaryClassification.EvaluateNonCalibrated(dataWithPredictions, "IsOver50K"); | ||
SamplesUtils.ConsoleUtils.PrintMetrics(metrics); | ||
// Accuracy: 0.85 | ||
// AUC: 0.90 | ||
// F1 Score: 0.64 | ||
// Negative Precision: 0.88 | ||
// Negative Recall: 0.93 | ||
// Positive Precision: 0.72 | ||
// Positive Recall: 0.58 | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...les/Dynamic/Trainers/BinaryClassification/SymbolicStochasticGradientDescentWithOptions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
namespace Microsoft.ML.Samples.Dynamic | ||
{ | ||
public static class SymbolicStochasticGradientDescentWithOptions | ||
{ | ||
// This example requires installation of additional nuget package <a href="https://www.nuget.org/packages/Microsoft.ML.HalLearners/">Microsoft.ML.HalLearners</a>. | ||
// In this example we will use the adult income dataset. The goal is to predict | ||
// if a person's income is above $50K or not, based on different pieces of information about that person. | ||
// For more details about this dataset, please see https://archive.ics.uci.edu/ml/datasets/adult | ||
public static void Example() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Xml #Resolved |
||
{ | ||
// Create a new context for ML.NET operations. It can be used for exception tracking and logging, | ||
// as a catalog of available operations and as the source of randomness. | ||
// Setting the seed to a fixed number in this examples to make outputs deterministic. | ||
var mlContext = new MLContext(seed: 0); | ||
|
||
// Download and featurize the dataset. | ||
var data = SamplesUtils.DatasetUtils.LoadFeaturizedAdultDataset(mlContext); | ||
|
||
// Leave out 10% of data for testing. | ||
var split = mlContext.BinaryClassification.TrainTestSplit(data, testFraction: 0.1); | ||
// Create data training pipeline | ||
var pipeline = mlContext.BinaryClassification.Trainers.SymbolicStochasticGradientDescent( | ||
new ML.Trainers.HalLearners.SymSgdClassificationTrainer.Options() | ||
{ | ||
LabelColumn = "IsOver50K", | ||
LearningRate = 0.2f, | ||
NumberOfIterations = 10, | ||
NumberOfThreads = 1, | ||
|
||
}); | ||
|
||
var model = pipeline.Fit(split.TrainSet); | ||
|
||
// Evaluate how the model is doing on the test data. | ||
var dataWithPredictions = model.Transform(split.TestSet); | ||
var metrics = mlContext.BinaryClassification.EvaluateNonCalibrated(dataWithPredictions, "IsOver50K"); | ||
SamplesUtils.ConsoleUtils.PrintMetrics(metrics); | ||
// Accuracy: 0.84 | ||
// AUC: 0.88 | ||
// F1 Score: 0.60 | ||
// Negative Precision: 0.87 | ||
// Negative Recall: 0.93 | ||
// Positive Precision: 0.69 | ||
// Positive Recall: 0.53 | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Regression/OrdinaryLeastSquares.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using Microsoft.ML.Data; | ||
using Microsoft.ML.SamplesUtils; | ||
|
||
namespace Microsoft.ML.Samples.Dynamic | ||
{ | ||
public static class OrdinaryLeastSquares | ||
{ | ||
// This example requires installation of additional nuget package <a href="https://www.nuget.org/packages/Microsoft.ML.HalLearners/">Microsoft.ML.HalLearners</a>. | ||
// In this examples we will use the housing price dataset. The goal is to predict median home value. | ||
// For more details about this dataset, please see https://archive.ics.uci.edu/ml/machine-learning-databases/housing/ | ||
public static void Example() | ||
{ | ||
// Downloading a regression dataset from github.com/dotnet/machinelearning | ||
string dataFile = SamplesUtils.DatasetUtils.DownloadHousingRegressionDataset(); | ||
|
||
// Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging, | ||
// as well as the source of randomness. | ||
var mlContext = new MLContext(seed: 3); | ||
|
||
// Creating a data reader, based on the format of the data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. newline please. #Closed |
||
// The data is tab separated with all numeric columns. | ||
// The first column being the label and rest are numeric features | ||
// Here only seven numeric columns are used as features | ||
var dataView = mlContext.Data.ReadFromTextFile(dataFile, new TextLoader.Arguments | ||
{ | ||
Separators = new[] { '\t' }, | ||
HasHeader = true, | ||
Columns = new[] | ||
{ | ||
new TextLoader.Column("Label", DataKind.R4, 0), | ||
new TextLoader.Column("Features", DataKind.R4, 1, 6) | ||
} | ||
}); | ||
|
||
//////////////////// Data Preview //////////////////// | ||
// MedianHomeValue CrimesPerCapita PercentResidental PercentNonRetail CharlesRiver NitricOxides RoomsPerDwelling PercentPre40s | ||
// 24.00 0.00632 18.00 2.310 0 0.5380 6.5750 65.20 | ||
// 21.60 0.02731 00.00 7.070 0 0.4690 6.4210 78.90 | ||
// 34.70 0.02729 00.00 7.070 0 0.4690 7.1850 61.10 | ||
|
||
var split = mlContext.Regression.TrainTestSplit(dataView, testFraction: 0.2); | ||
|
||
// Create the estimator, here we only need OrdinaryLeastSquares trainer | ||
// as data is already processed in a form consumable by the trainer | ||
var pipeline = mlContext.Regression.Trainers.OrdinaryLeastSquares(); | ||
|
||
var model = pipeline.Fit(split.TrainSet); | ||
|
||
// Check the weights that the model learned | ||
var weightsValues = model.Model.Weights; | ||
Console.WriteLine($"weight 0 - {weightsValues[0]}"); // CrimesPerCapita (weight 0) = -0.1682112 | ||
Console.WriteLine($"weight 3 - {weightsValues[3]}"); // CharlesRiver (weight 1) = 3.663493 | ||
var dataWithPredictions = model.Transform(split.TestSet); | ||
var metrics = mlContext.Regression.Evaluate(dataWithPredictions); | ||
|
||
ConsoleUtils.PrintMetrics(metrics); | ||
// L1: 4.15 | ||
// L2: 31.98 | ||
// LossFunction: 31.98 | ||
// RMS: 5.65 | ||
// RSquared: 0.56 | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @shmoradims, @jwood803 so you don't work on the same. #Closed