Skip to content

model_diagnostics/weights-keyword-argument

Pack Severity Fix Versions
model-diagnostics error unsafe, with xpd check --fix --unsafe-fixes All versions

model_diagnostics uses weights= instead of scikit-learn's sample_weight= and rng= instead of random_state=. Passing sample_weight= or random_state= raises TypeError: got an unexpected keyword argument.

decompose(y_val, y_pred, sample_weight=w_val, scoring_function=SquaredError())
decompose(y_val, y_pred, weights=w_val, scoring_function=SquaredError())
compute_permutation_importance(model.predict, X_val, y_val, sample_weight=w_val, random_state=0)
compute_permutation_importance(model.predict, X_val, y_val, weights=w_val, rng=0)

Calls to model_diagnostics scoring, calibration, or XAI functions passing sample_weight= instead of weights=, or random_state= instead of rng=.

Rename sample_weight= to weights= and random_state= to rng= (or run xpd check --fix --unsafe-fixes).

model_diagnostics functions take weights= rather than sample_weight=, so sample_weight= raises TypeError. Rename sample_weight= to weights=.

See all rules in the model-diagnostics pack.