Skip to content

Using PFI with AutoML, possible? #3972

Description

@famschopman

Playing with AutoML and so far having much fun with it.

I have a trained model and now trying to retrieve the feature weights. None of the objects returned expose a LastTransformer object that I need to

Code snippet:

var mlContext = new MLContext();
var _appPath = AppDomain.CurrentDomain.BaseDirectory;
 var _dataPath = Path.Combine(_appPath, "Datasets", "dataset.csv");
var _modelPath = Path.Combine(_appPath, "Datasets", "TrainedModels");


ColumnInferenceResults columnInference = mlContext.Auto().InferColumns(_dataPath, LabelColumnName, groupColumns: false);
            ColumnInformation columnInformation = columnInference.ColumnInformation;

            TextLoader textLoader = mlContext.Data.CreateTextLoader(columnInference.TextLoaderOptions);
            IDataView data = textLoader.Load(_dataPath);

            DataOperationsCatalog.TrainTestData dataSplit = mlContext.Data.TrainTestSplit(data, testFraction: 0.2);
            IDataView trainData = dataSplit.TrainSet;
            IDataView testData = dataSplit.TestSet;

            var cts = new CancellationTokenSource();
            var experimentSettings = CreateExperimentSettings(mlContext, cts);

            var progressHandler = new BinaryExperimentProgressHandler();

            ExperimentResult<BinaryClassificationMetrics> experimentResult = mlContext.Auto()
                .CreateBinaryClassificationExperiment(experimentSettings)
                .Execute(trainData, labelColumnName: "Attrition", progressHandler: new BinaryExperimentProgressHandler());

            RunDetail<BinaryClassificationMetrics> bestRun = experimentResult.BestRun;
            ITransformer trainedModel = bestRun.Model;
            var predictions = trainedModel.Transform(testData);
            var metrics = mlContext.BinaryClassification.EvaluateNonCalibrated(data: predictions, labelColumnName: "Attrition", scoreColumnName: "Score");

            mlContext.Model.Save(trainedModel, trainData.Schema, _modelPath);

Then I want to get the PFI information and I get stuck. There appears no way to get the LastTransformer object from the trainedModel.

            var transformedData = trainedModel.Transform(trainData);
            var linearPredictor = model.LastTransformer; 

            var permutationMetrics = mlContext.BinaryClassification.PermutationFeatureImportance(
                linearPredictor, transformedData, permutationCount: 30);

Hope someone can help me with some guidance.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions