• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mmschlk / shapiq / 17372021070

01 Sep 2025 08:26AM UTC coverage: 93.704% (-0.2%) from 93.906%
17372021070

Pull #431

github

web-flow
Merge 7d2c68dac into 68f21c1d6
Pull Request #431: Product kernel explainer

180 of 203 new or added lines in 14 files covered. (88.67%)

4 existing lines in 2 files now uncovered.

5090 of 5432 relevant lines covered (93.7%)

0.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.27
/src/shapiq/explainer/product_kernel/validation.py
1
"""Conversion functions for the product kernel explainer implementation."""
2

3
from __future__ import annotations
1✔
4

5
from typing import TYPE_CHECKING
1✔
6

7
from shapiq.utils.modules import safe_isinstance
1✔
8

9
from .conversion import convert_gp_reg, convert_svm
1✔
10

11
if TYPE_CHECKING:
1✔
NEW
12
    from shapiq.typing import Model
×
13

NEW
14
    from .base import ProductKernelModel
×
15

16
SUPPORTED_MODELS = {
1✔
17
    "sklearn.svm.SVR",
18
    "sklearn.svm.SVC",
19
    "sklearn.gaussian_process.GaussianProcessRegressor",
20
}
21

22

23
def validate_pk_model(
1✔
24
    model: Model,
25
    class_label: int | None = None,  # TODO(IsaH57): check how to use (Issue #425)
26
) -> ProductKernelModel:
27
    """Validate the product kernel model.
28

29
    Args:
30
        model: The model to validate.
31
        class_label: The class label to be used for validation. Defaults to None.
32

33
    Returns:
34
        The validated product kernel model.
35
    """
36
    class_label = class_label or 1  # default to 1 for classification models
1✔
37

38
    # product kernel model already in the correct format
39
    if type(model).__name__ == "ProductKernelModel":
1✔
NEW
40
        pk_model = model
×
41
    elif safe_isinstance(model, "sklearn.svm.SVR") or (
1✔
42
        safe_isinstance(model, "sklearn.svm.SVC") and model.classes_.shape[0] == 2
43
    ):
44
        pk_model = convert_svm(model)
1✔
45
    elif safe_isinstance(model, "sklearn.gaussian_process.GaussianProcessRegressor"):
1✔
46
        pk_model = convert_gp_reg(model)
1✔
47

48
    # unsupported model types
49
    elif safe_isinstance(model, "sklearn.svm.SVC") and model.classes_.shape[0] >= 2:
1✔
NEW
50
        msg = "Only binary SVM classification supported."
×
NEW
51
        raise TypeError(msg)
×
52
    else:
53
        msg = f"Unsupported model type.Supported models are: {SUPPORTED_MODELS}"
1✔
54
        raise TypeError(msg)
1✔
55
    return pk_model
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc