plexus.scores.ExplainableClassifier module

class plexus.scores.ExplainableClassifier.ExplainableClassifier(**parameters)

Bases: Score

A classifier based on XGBoost that uses n-gram vectorization and produces a ranked list of features for a target class, by importance.

Initialize the Score instance with the given parameters.

Parameters

**parametersdict

Arbitrary keyword arguments that are used to initialize the Parameters instance.

Raises

ValidationError

If the provided parameters do not pass validation.

class Parameters(*, scorecard_name: str | None = None, name: str | None = None, id: str | int | None = None, key: str | None = None, dependencies: List[dict] | None = None, data: dict | None = None, number_of_classes: int | None = None, label_score_name: str | None = None, label_field: str | None = None, top_n_features: int = 10000, leaderboard_n_features: int = 10, target_score_name: str, target_score_value: str, ngram_range: str = '2,3', decision_threshold: float = 0.5, scale_pos_weight_index: float = 0, include_explanations: bool = False, keywords: list = None)

Bases: Parameters

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

decision_threshold: float
include_explanations: bool
keywords: list
leaderboard_n_features: int
model_config: ClassVar[ConfigDict] = {'protected_namespaces': ()}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

ngram_range: str
scale_pos_weight_index: float
target_score_name: str
target_score_value: str
top_n_features: int
class Result(*, parameters: Parameters, value: str | bool, metadata: dict = {}, error: str | None = None, confidence: float, explanation: str)

Bases: Result

This Score has an additional output attribute, explanation, which is a string

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

confidence: float
explanation: str
model_config: ClassVar[ConfigDict] = {'protected_namespaces': ()}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

__init__(**parameters)

Initialize the Score instance with the given parameters.

Parameters

**parametersdict

Arbitrary keyword arguments that are used to initialize the Parameters instance.

Raises

ValidationError

If the provided parameters do not pass validation.

evaluate_model()

Evaluate the model on the validation data.

Returns

dict

Dictionary containing evaluation metrics.

explain_model()
predict(context, model_input)

Make predictions on the input data.

Parameters

contextAny

Context for the prediction (e.g., MLflow context)

model_inputScore.Input

The input data for making predictions.

Returns

Union[Score.Result, List[Score.Result]]

Either a single Score.Result or a list of Score.Results

predict_validation()

Predict on the validation set.

This method should be implemented by subclasses to provide the prediction logic on the validation set.

preprocess_text(text)
register_model()

Register the model with the model registry.

save_model()

Save the model to the model registry.

train_model()

Train the XGBoost model with the specified positive class weight.

Parameters

X_trainnumpy.ndarray

Training data features.

y_trainnumpy.ndarray

Training data labels.

X_valnumpy.ndarray

Validation data features.

y_valnumpy.ndarray

Validation data labels.

vectorize_transcript(transcript: str)