-
Notifications
You must be signed in to change notification settings - Fork 5
Add Permutation Importance #202
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
base: main
Are you sure you want to change the base?
Conversation
This is the current basic call: import numpy as np
import polars as pl
from sklearn.linear_model import LinearRegression
from model_diagnostics.xai import plot_permutation_importance
rng = np.random.default_rng(1)
n = 1000
X = pl.DataFrame(
{
"area": rng.uniform(30, 120, n),
"rooms": rng.choice([2.5, 3.5, 4.5], n),
"age": rng.uniform(0, 100, n),
}
)
y = X["area"] + 20 * X["rooms"] + rng.normal(0, 1, n)
model = LinearRegression()
model.fit(X, y)
_ = plot_permutation_importance(
predict_function=model.predict,
X=X,
y=y,
) The extended feature API allows to permute groups like this: _ = plot_permutation_importance(
predict_function=model.predict,
features={"size": ["area", "rooms"], "age": "age"},
X=X,
y=y,
) |
from model_diagnostics.scoring import SquaredError | ||
|
||
|
||
def safe_copy(X): |
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.
Might be good to put safe_copy
and safe_column_names
into _utils.array
and add tests for them. I think they cause the current CI failure.
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.
My local tests are failing for the Python 3.9 environment only (pandas and pyarrow). I will move the functions to _utils.array, draft some unit tests, and rename safe_column_names()
to get_column_names()
.
This will be a great addition! Thanks @mayer79 |
The failing test is in the python 3.9 env with Could you check if increasing one of the versions fixes the problem, e.g. polars version? |
The following changes in the 3.9 env would be necessary. I don't know how much it would hurt to abandon pandas 1
I have added some additional unit tests and moved |
Implements #201