-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Public API for KMeansPredictor #1739
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
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ab08535
Rename KMeansPredictor to KMeansModelParameters, rename namespace, an…
najeeb-kazmi cbb92f6
Internalizing SaveCore
najeeb-kazmi bbf1dff
Adding sample
najeeb-kazmi 28347a3
BestFriend attribute for the correct method overridden by LightGbmBin…
najeeb-kazmi 58aa330
Making FastTree best friends with LightGBM
najeeb-kazmi f8663e8
Update core_ep-list.tsv
najeeb-kazmi 073ff03
Reverting libmf commit id
najeeb-kazmi 68def92
Explicitly implementing IValueMapper and ICanSaveInTextFormat everywhere
najeeb-kazmi a36eb9b
Final cleanup
najeeb-kazmi 5ca4465
addressing some comments
najeeb-kazmi dbbfa64
reverting namespace change
najeeb-kazmi a31d811
update core_ep-list.tsv
najeeb-kazmi 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| using Microsoft.ML.Runtime.Api; | ||
| using Microsoft.ML.Runtime.Data; | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Microsoft.ML.Samples.Dynamic | ||
| { | ||
| public class KMeans_example | ||
| { | ||
| public static void KMeans() | ||
| { | ||
| // 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 ml = new MLContext(); | ||
|
|
||
| // Get a small dataset as an IEnumerable and convert it to an IDataView. | ||
| var data = SamplesUtils.DatasetUtils.GetInfertData(); | ||
| var trainData = ml.CreateStreamingDataView(data); | ||
|
|
||
| // Preview of the data. | ||
| // | ||
| // Age Case Education Induced Parity PooledStratum RowNum ... | ||
| // 26 1 0-5yrs 1 6 3 1 ... | ||
| // 42 1 0-5yrs 1 1 1 2 ... | ||
| // 39 1 0-5yrs 2 6 4 3 ... | ||
| // 34 1 0-5yrs 2 4 2 4 ... | ||
| // 35 1 6-11yrs 1 3 32 5 ... | ||
|
|
||
| // A pipeline for concatenating the age, parity and induced columns together in the Features column and training a KMeans model on them. | ||
| string outputColumnName = "Features"; | ||
| var pipeline = ml.Transforms.Concatenate(outputColumnName, new[] { "Age", "Parity", "Induced" }) | ||
| .Append(ml.Clustering.Trainers.KMeans(outputColumnName, clustersCount: 2)); | ||
|
|
||
| var model = pipeline.Fit(trainData); | ||
|
|
||
| // Get cluster centroids and the number of clusters k from KMeansModelParameters. | ||
| VBuffer<float>[] centroids = default; | ||
| int k; | ||
|
|
||
| var modelParams = model.LastTransformer.Model; | ||
| modelParams.GetClusterCentroids(ref centroids, out k); | ||
|
|
||
| var centroid = centroids[0].GetValues(); | ||
| Console.WriteLine("The coordinates of centroid 0 are: " + string.Join(", ", centroid.ToArray())); | ||
| } | ||
| } | ||
| } |
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
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
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
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
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
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
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
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.
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.
Good stuff