Skip to content

Instantly share code, notes, and snippets.

View justinormont's full-sized avatar

Justin Ormont justinormont

View GitHub Profile
@justinormont
justinormont / StringStats.cs
Created July 9, 2019 17:14
String Statistics
// Note: Some of these functions are likely better left to the .NET language's implementation for better internalization support.
// Using a regex for these was found to be slower.
Func<char, bool> isVowel = ((x) => x == 'e' || x == 'a' || x == 'o' || x == 'i' || x == 'u' || x == 'E' || x == 'A' || x == 'O' || x == 'I' || x == 'U' );
Func<char, bool> isConsonant = ((x) => (x >= 'A' && x <= 'Z')||(x >= 'a' && x <= 'z') && !(x == 'e' || x == 'a' || x == 'o' || x == 'i' || x == 'u' || x == 'E' || x == 'A' || x == 'O' || x == 'I' || x == 'U'));
Func<char, bool> isVowelOrDigit = ((x) => x == 'e' || x == 'a' || x == 'o' || x == 'i' || x == 'u' || x == 'E' || x == 'A' || x == 'O' || x == 'I' || x == 'U' || (x >= '0' && x <= '9'));
Func<string, int> maxRepeatingCharCount = ((s) => { int max = 0, j = 0; for (var i = 0; i < s.Length; ++i) { if (s[i] == s[j]) { if (max < i - j) max = i - j; } else j = i; } return max; });
Func<string, int> maxRepeatingVowelCount = ((s) => { int max = 0, j = 0; for (var i = 0; i < s.Leng
@justinormont
justinormont / featureImportanceMCLR.cs
Created May 23, 2019 14:13
ML.NET Feature Importance for Multiclass Logistic Regression
/*
This demonstrates feature importance for a multiclass logistic regression in ML.NET
var trainer = mlContext.MulticlassClassification.Trainers.LbfgsMaximumEntropy(new LbfgsMaximumEntropyMulticlassTrainer.Options() { LabelColumnName = "MyLabel", FeatureColumnName = "Features" })
*/
var p = (Microsoft.ML.Data.EstimatorChain<Microsoft.ML.Data.MulticlassPredictionTransformer<Microsoft.ML.Trainers.MaximumEntropyModelParameters>>)trainingPipeline;
// Train the model
var model = p.Fit(trainingDataView);