Skip to content

Add regression trainer selector on the Regression. #6

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void SetUpExperiment()
{
MaxExperimentTimeInSeconds = 180,
OptimizingMetric = MulticlassClassificationMetric.LogLoss,
CacheDirectory = null
CacheDirectoryName = null,
};

// These two trainers yield no metrics in UWP:
Expand Down Expand Up @@ -105,7 +105,7 @@ public void HyperParameterize()
{
MaxExperimentTimeInSeconds = 180,
OptimizingMetric = MulticlassClassificationMetric.LogLoss,
CacheDirectory = null
CacheDirectoryName = null
};

// There can be only one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public IEnumerable<RegressionData> Load(string trainingDataPath)
return _mlContext.Data.CreateEnumerable<RegressionData>(trainingData, reuseRowObject: false);
}

public void BuildAndTrain()
public void BuildAndTrain(string regressionTrainer)
{
var pipeline = _mlContext.Transforms.ReplaceMissingValues("Age", "Age", MissingValueReplacingEstimator.ReplacementMode.Mean)
var prepipeline = _mlContext.Transforms.ReplaceMissingValues("Age", "Age", MissingValueReplacingEstimator.ReplacementMode.Mean)
.Append(_mlContext.Transforms.ReplaceMissingValues("Ws", "Ws", MissingValueReplacingEstimator.ReplacementMode.Mean))
.Append(_mlContext.Transforms.ReplaceMissingValues("Bmp", "Bmp", MissingValueReplacingEstimator.ReplacementMode.Mean))
.Append(_mlContext.Transforms.ReplaceMissingValues("NBA_DraftNumber", "NBA_DraftNumber", MissingValueReplacingEstimator.ReplacementMode.Mean))
Expand All @@ -53,15 +53,43 @@ public void BuildAndTrain()
.Append(_mlContext.Transforms.NormalizeMeanVariance("Bmp", "Bmp"))
.Append(_mlContext.Transforms.Concatenate(
"Features",
new[] { "NBA_DraftNumber", "Age", "Ws", "Bmp" }))
// .Append(_mlContext.Regression.Trainers.FastTree()); // PlatformNotSupportedException
// .Append(_mlContext.Regression.Trainers.OnlineGradientDescent(new OnlineGradientDescentTrainer.Options { })); // InvalidOperationException if you don't normalize.
// .Append(_mlContext.Regression.Trainers.StochasticDualCoordinateAscent());
// .Append(_mlContext.Regression.Trainers.PoissonRegression());
.Append(_mlContext.Regression.Trainers.Gam());

Model = pipeline.Fit(trainingData);

new[] { "NBA_DraftNumber", "Age", "Ws", "Bmp" }));
// .Append(_mlContext.Regression.Trainers.FastTree()); // PlatformNotSupportedException
// .Append(_mlContext.Regression.Trainers.OnlineGradientDescent(new OnlineGradientDescentTrainer.Options { })); // InvalidOperationException if you don't normalize.
// .Append(_mlContext.Regression.Trainers.StochasticDualCoordinateAscent());
// .Append(_mlContext.Regression.Trainers.PoissonRegression());
//.Append(_mlContext.Regression.Trainers.Gam());
switch (regressionTrainer)
{
//case "FastTree": // PlatformNotSupportedException
// var pipelineFastTree = prepipeline.Append(_mlContext.Regression.Trainers.FastTree());
// Model = pipelineFastTree.Fit(trainingData);
// break;
//case "FastTreeTweedie": // PlatformNotSupportedException
// var pipelineFastTreeTweedie = prepipeline.Append(_mlContext.Regression.Trainers.FastTreeTweedie());
// Model = pipelineFastTreeTweedie.Fit(trainingData);
// break;
case "Gam":
var pipelineGam = prepipeline.Append(_mlContext.Regression.Trainers.Gam());
Model = pipelineGam.Fit(trainingData);
break;
case "LightGbm":
var pipelineLightGbm = prepipeline.Append(_mlContext.Regression.Trainers.LightGbm());
Model = pipelineLightGbm.Fit(trainingData);
break;
case "Ols":
var pipelineOls = prepipeline.Append(_mlContext.Regression.Trainers.Ols());
Model = pipelineOls.Fit(trainingData);
break;
case "Sdca":
var pipelineSdca = prepipeline.Append(_mlContext.Regression.Trainers.Sdca());
Model = pipelineSdca.Fit(trainingData);
break;
default:
var pipeline = prepipeline.Append(_mlContext.Regression.Trainers.Gam());
Model = pipeline.Fit(trainingData);
break;
}
predictionEngine = _mlContext.Model.CreatePredictionEngine<RegressionData, RegressionPrediction>(Model);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public Task<IEnumerable<RegressionData>> Load(string trainingDataPath)
});
}

public Task BuildAndTrain()
public Task BuildAndTrain(string regressionTrainer)
{
return Task.Run(() =>
{
_model.BuildAndTrain();
_model.BuildAndTrain(regressionTrainer);
});
}

Expand Down
11 changes: 8 additions & 3 deletions XamlBrewer.Uwp.MachineLearningSample/Views/RegressionPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,14 @@
IsChecked="False"
Grid.Row="4"
Grid.Column="1" />
<Button x:Name="RestartButton"
Click="Page_Loaded"
Grid.Row="5">Restart</Button>
<StackPanel Orientation="Horizontal"
Grid.Row="5">
<ComboBox x:Name="RegressionTrainersCombo"
SelectionChanged="RegressionTrainersCombo_SelectionChanged"
Header="Regression trainer" />
<Button x:Name="RestartButton" Margin="20"
Click="Page_Loaded">Restart</Button>
</StackPanel>
<controls:AnimatedVisualPlayer x:Name="BusyIndicator"
Visibility="Collapsed"
Height="180"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public RegressionPage()
this.DataContext = new RegressionPageViewModel();

Loaded += Page_Loaded;
RegressionTrainersCombo.ItemsSource = new[] { "Gam", "LightGbm", "Ols", "Sdca" };
RegressionTrainersCombo.SelectedIndex = 0;
}

private RegressionPageViewModel ViewModel => DataContext as RegressionPageViewModel;
Expand Down Expand Up @@ -50,7 +52,7 @@ private async void Page_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)

// Create and train the model
TrainingBox.IsChecked = true;
await ViewModel.BuildAndTrain();
await ViewModel.BuildAndTrain(RegressionTrainersCombo.SelectedItem.ToString());

// Save the model.
await ViewModel.Save("regressionModel.zip");
Expand Down Expand Up @@ -172,5 +174,10 @@ private async void Slider_ValueChanged(object sender, Windows.UI.Xaml.Controls.P
Diagram.Model.Annotations.Add(annotation);
Diagram.InvalidatePlot();
}

private void RegressionTrainersCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -333,22 +333,22 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ML">
<Version>1.5.1</Version>
<Version>1.7.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.ML.AutoML">
<Version>0.17.1</Version>
<Version>0.19.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.ML.FastTree">
<Version>1.5.1</Version>
<Version>1.7.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.ML.Recommender">
<Version>0.17.1</Version>
<Version>0.19.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.10</Version>
<Version>6.2.13</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Lottie">
<Version>6.1.0</Version>
<Version>7.1.0</Version>
</PackageReference>
<PackageReference Include="OxyPlot.Windows">
<Version>2.0.0-unstable1035</Version>
Expand Down