Last active
April 30, 2019 09:46
-
-
Save AndyButland/ff56d35d727c38b7d463795be4eb0adb to your computer and use it in GitHub Desktop.
This file contains 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
private static void ReportOnFeatureImportance(MLContext context, ITransformer model, IDataView data) | |
{ | |
... | |
var results = featureNames | |
.Select((t, i) => new FeatureImportance | |
{ | |
Name = t, | |
RSquaredMean = Math.Abs(permutationMetrics[i].RSquared.Mean), | |
CorrelationCoefficient = CalculateSingleFactorCorrelationCoefficient(context, data, t) | |
}) | |
.OrderByDescending(x => x.RSquaredMean); | |
... | |
} | |
private static double CalculateSingleFactorCorrelationCoefficient(MLContext context, IDataView data, string featureColumn) | |
{ | |
return CalculateCorrelationCoefficientBetweenValues(GetSingleColumn(context, data, featureColumn), GetSingleColumn(context, data, PredictionLabel)); | |
} | |
private static IEnumerable<float> GetSingleColumn(IHostEnvironment context, IDataView data, string columnName) | |
{ | |
return data.GetColumn<float>(context, columnName); | |
} | |
private static double CalculateCorrelationCoefficientBetweenValues(IEnumerable<float> featureColumn, IEnumerable<float> resultColumn) | |
{ | |
return StatsHelper.ComputeCorrellationCoefficent(featureColumn.ToArray(), resultColumn.ToArray()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment