SVEKER.ExplainingSVC

class SVEKER.ExplainingSVC(*, C: float = 1, kernel_type: Literal['rbf', 'tanimoto', 'poly', 'sigmoid'] = 'tanimoto', degree: int = 3, gamma: float = 1.0, coef0: float = 0, shrinking: bool = True, probability: bool = True, tol: float = 0.001, cache_size: float = 200, class_weight: Mapping | str | None = None, verbose: bool = False, max_iter: int = -1, decision_function_shape: Literal['ovo', 'ovr'] = 'ovr', break_ties: bool = False, random_state: int | RandomState | None = None, no_player_value: float = 0.0)

Class for SVC with exact Shapley values. Inherits from ExplainingSVM and from sklearn.SVC.

For documentation of the sklearn methods, please take a look at the documentation there. Here, only the newly implemented methods will be discussed.

__init__(*, C: float = 1, kernel_type: Literal['rbf', 'tanimoto', 'poly', 'sigmoid'] = 'tanimoto', degree: int = 3, gamma: float = 1.0, coef0: float = 0, shrinking: bool = True, probability: bool = True, tol: float = 0.001, cache_size: float = 200, class_weight: Mapping | str | None = None, verbose: bool = False, max_iter: int = -1, decision_function_shape: Literal['ovo', 'ovr'] = 'ovr', break_ties: bool = False, random_state: int | RandomState | None = None, no_player_value: float = 0.0) None

Initializes SVC with exact Shapley values.

Parameters:
  • C (float) – Regularization parameter

  • kernel_type (str) – Kernel to be used, must be in ['tanimoto', 'rbf', 'poly', 'sigmoid']

  • gamma (float) – Parameter \(\gamma\), only for Polynomial, RBF, Sigmoid kernel.

  • degree (float) – Parameter \(d\), only for Polynomial kernel, must be non-negative.

  • coef0 (float) – Parameter \(r\), only for Polynomial, Sigmoid kernel.

  • shrinking (bool) – Wheter to use shrinking heuristic

  • probability (bool) – Enables probability estimates thorugh Platt scaling

  • tol (float) – Tolerance for stopping criteria

  • cache_size (float) – Kernel chache size

  • class_weight (dict or 'balanced') – Set the parameter \(C\) of class :mahtL`i` to class_weight[i]*C for SVC, if not given, all classes will have the weight of unity.

  • verbose (bool) – Enables verbose output

  • max_iter (int) – Maximum number of iterations, if -1 no limit

  • decision_function_shape – one-v-rest (ovr) or one-v-one (ovo)

  • break_ties (bool) – If true, decision_function_shape='ovr', and number of classes > 2, predict will break ties according to the confidence values of decision_function; otherwise the first class among the tied classes is returned.

  • random_state (int, RandomState instnace or None) – Controls pseudo random numbers

  • no_player_value (float) – Defines the no player value

property expected_value

Expected value

Returns:

Expected value

Return type:

float

property expected_value_logit_space

Expected value in logit space. Calcualted by scaling the the expected value using Platt scaling parameters.

Returns:

Expected value in logit space

Return type:

float

fit(X, y, sample_weight=None)

Fits the classifier and saves the explicit support vectors.

Parameters:
  • X (array_like) – Training vectors

  • y (array_like) – Target values

  • sample_weights – Per-sample weight

platt(dist)

Platt scaling

\(\frac{1}{1-\exp{}(-Ax+B)}\)

where \(A\) and \(B\) are the parameters from Platt scaling and \(x\) is the distance from the hyperplane.

Parameters:

dist (float) – Distance from the hyperplane

Returns:

Platt-scaled distance

Return type:

float

predict_proba(X)

Reimplementation of predict_proba to fix numerical inconsistencies

Parameters:

X (array_like) – Input vectors

Returns:

Predicted probabilities

Return type:

array-like

set_params(**params)

Sets the parameters of the class. Necessary in order to work with sklearn Pipelines and grid searches

Parameters:

params – parameter to change with corresponding value

Returns:

Returns Class with changed parameters.

shapley_values(x: ndarray, logit_space=False)

Calculates the Shapley values for the input vectors

Parameters:
  • X (array-like) – Input vectors

  • logit_space (bool) – Whether to scale the shapley values to logit space using Platt scaling parameters

Returns:

Shapley values for the input vectors

Return type:

array-like