-
Notifications
You must be signed in to change notification settings - Fork 1.9k
It is not possible to use PermutationFeatureImportance from a model loaded from disk in F# #3976
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
Comments
work around for now is to use a C# helper given below but really if an interface (IPredictorProducing) is going to be exposed via another public interface, it should not really be marked internal. public static class MLHelper<T> where T : class
{
public static System.Collections.Immutable.ImmutableArray<BinaryClassificationMetricsStatistics> PFI_BinaryClassification
(
MLContext ctx,
ITransformer model,
IDataView data,
string labelColumnName = "Label",
bool useFeatureWeightFilter = false,
int? numberOfExamplesToUse = null,
int permutationCount = 1
)
{
var m = ctx.BinaryClassification.PermutationFeatureImportance(
model as ISingleFeaturePredictionTransformer<T>,
data,
labelColumnName : labelColumnName,
useFeatureWeightFilter : useFeatureWeightFilter,
numberOfExamplesToUse : numberOfExamplesToUse,
permutationCount : permutationCount
);
return m;
}
} |
@fwaris - I just ran into this issue as well. I don't understand how your workaround works. What @codemzs - this is the same issue as we were discussing today. I don't think it is possible to use This is an issue because if you use AutoML, it always saves the model to disk in order to save on memory. The problem is this code: machinelearning/src/Microsoft.ML.Data/Scorers/PredictionTransformer.cs Lines 595 to 601 in bb00e07
Whenever you load a predition transformer from a model stream, it is always creating an instance of a We need to change the above code to save off the right type into the model, and create an instance of |
@eerhardt, it seems you can punt on the type resolution in F# by using an underscore; i.e. the following trick seems to work (I tested again just to make sure): let metrics = MLHelper<_>.PFI_BinaryClassification(mlctx, model, labelColumnName="Label") The 'model' variable is of the concrete type (from debugger): However I agree with you that this area requires re-work to make it easier to use. |
* Address the issue of using PFI with a model loaded from disk. * Provided working tests and samples for using PFI with a model loaded from disk for the cases of Ranking, Regression, and Multiclass prediction transformers. No tests or samples provided for Binary classification, for reasons that will be addressed in a future issue. * Also modified LbfgsTests so that it uses the appropiate casts now that the PredictionTransformers have been updated.
Hi. So PRs #4262 and #4306 fixed the problem Eric pointed out in his comment in this thread. So please, let us know if this has been fixed for you. Particularly, those PRs where only tested for ML.NET on C#, so I would appreciate feedback from the F# side. I will rename and tag this issue as F# specific then, since that was your original problem. |
This is not fixed yet. 1. As a pipeline + estimator
2. As an estimator, without pipeline
Then loading from the disk.
1. As a pipeline + estimator - model contains only pipeline transformers, including MapValueToKey and Concatenate, there is no way to get actual trainer / estimator and use it for PFI. LastTransformer property will return Concatenate transformer, but PFI requires an estimator, e.g. LighGbm or Regression 2. As an estimator without pipeline - now I see LightGbm trainer in the list of TransformationChain, but CreatePredictionEngine raises an exception "Features" column is not defined, because in this case model was saved as a pure estimator, without pipeline |
Correction.
|
How are you finding the 1.5.0-preview nuget? We literally just released today. |
@codemzs "Show pre-release" checkbox in Nuget package manager |
ha! of course, I meant how has your experience been with it so far? does it fix any of your issues? |
The only thing I needed is to run PFI using model loaded from file. As far as it works, I'm happy |
Hi, @artemiusgreat . So I am not sure: is your problem solved or not? I believe it should be possible to access the
I am not sure why would you need to use the
PFI doesn't require an estimator, but a Prediction Transformer. So, in your example, the LightGbm trainer is also an estimator, and once it is trained (with
If you are still facing problems, please share with us the complete code and dataset you're using, so that I can take a closer look. Thanks. |
@antoniovs1029 Sorry, missed your comment. Yest it was fixed. Thanks. |
Also, confirming that it works. See this issue comment for some tricks that help when working with AutoML outputs Note: The fix works in a compiled F# project but not in F# interactive (fsi) because the current fsi is bound to older libraries. I expect that it will work in the new preview version of fsi but I have not tested that yet. |
I am trying to use PermutationFeatureImportance (PFI) with F# but the F# type system is not resolving ITransformer to ISingleFeaturePredictionTransformer - which is required by PFI.
I believe it is due to IPredictorProducing (and related interfaces) being marked as "internal".
F# supports explicit interfaces and maybe that is the reason for this issue.
Here is a snippet of code that shows what I am trying to do
(I am using the latest bits - v 1.2.0 at the time of this post)
@dsyme
The text was updated successfully, but these errors were encountered: