-
-
Notifications
You must be signed in to change notification settings - Fork 379
Put all BaseMode.meta fields into @property methods
#1700
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
Put all BaseMode.meta fields into @property methods
#1700
Conversation
…s-into-properties
…s-into-properties
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.
nitpick: can we also propagate the change to the other daughter classes?
python-client/giskard/models/huggingface.py
255: return [[p[label] for label in self.meta.classification_labels] for p in _predictions]
python-client/giskard/models/langchain.py
62: model_type=self.meta.model_type,
67: classification_threshold=self.meta.classification_threshold,
68: classification_labels=self.meta.classification_labels,
python-client/giskard/models/base/wrapper.py
176: if raw_predictions.shape[-1] != len(self.meta.classification_labels):
179: f"where `n_classes` is the number of classes in your model output ({len(self.meta.classification_labels)} in this case)."
and all of these occurrences?
python-client/tests/test_statistical.py
22: classification_label=model.meta.classification_labels[label],
46: classification_label=model.meta.classification_labels[label],
69: classification_label=model.meta.classification_labels[label],
python-client/tests/models/test_sklearn_wrapper.py
25: gsk_model.meta.model_type = "unknown"
python-client/tests/models/test_model_postprocess.py
14: model.meta = meta
python-client/tests/models/test_model_explanation.py
41: for label in model.meta.classification_labels:
python-client/tests/models/test_catboost_wrapper.py
26: assert model.meta.feature_names == ["feature_1", "feature_2"]
27: assert model.meta.classification_labels == ["target1", "target2"]
python-client/tests/scan/test_overconfidence_detector.py
27: model.meta.classification_labels = ["A", "B", "C"]
python-client/tests/scan/test_scanner.py
68: german_credit_model.meta.feature_names = None
python-client/tests/scan/test_underconfidence_detector.py
27: model.meta.classification_labels = ["A", "B", "C"]
python-client/tests/integrations/test_mlflow.py
20: model_type=mlflow_model_types[model.meta.model_type],
60: evaluator_config = {"model_config": {"classification_labels": model.meta.classification_labels}}
69: evaluator_config = {"model_config": {"classification_labels": model.meta.classification_labels}}
98: cl = model.meta.classification_labels
python-client/tests/test_metamorphic_direction.py
50: classification_label=model.meta.classification_labels[0],
69: classification_label=model.meta.classification_labels[0],
python-client/tests/test_upload.py
72: model_type=model.meta.model_type,
75: classification_labels=model.meta.classification_labels,
84: model_type=model.meta.model_type,
85: feature_names=model.meta.feature_names,
python-client/giskard/ml_worker/websocket/utils.py
271: if i.type == "Model" and i.model_meta is not None:
272: return ModelInput(i.name, i.model_meta.model_type)
python-client/giskard/llm/talk/talk.py
62: required_features = set() if self.model.meta.feature_names is None else set(self.model.meta.feature_names)
202: name=self.spec.model.meta.name,
203: model_type=self.spec.model.meta.model_type,
204: feature_names=self.spec.model.meta.feature_names,
205: classification_threshold=self.spec.model.meta.classification_threshold,
206: classification_labels=self.spec.model.meta.classification_labels,
python-client/giskard/core/model_validation.py
39: model_type = model.meta.model_type
47: validate_classification_labels(model.meta.classification_labels, model_type)
50: validate_classification_threshold_label(model.meta.classification_labels, model.meta.classification_threshold)
52: assert model.meta.feature_names is None or isinstance(
53: model.meta.feature_names, list
58: validate_features(feature_names=model.meta.feature_names, validate_df=validate_ds.df)
67: model.meta.name, model.meta.classification_labels, target_values, validate_ds.target
73: if model.meta.model_type == SupportedModelTypes.CLASSIFICATION and validate_ds.target is not None:
89: features = model.meta.feature_names if model.meta.feature_names is not None else validation_ds.df.columns
125: validate_prediction_output(validation_ds, model.meta.model_type, prediction.raw)
127: validate_classification_prediction(model.meta.classification_labels, prediction.raw)
153: with open(f + "/giskard-model-meta.yaml") as yaml_f:
314: num_classes = len(model.meta.classification_labels)
python-client/giskard/ml_worker/websocket/listener.py
255: labels = {k: v for k, v in enumerate(model.meta.classification_labels)}
257: if len(model.meta.classification_labels) > 2 or model.meta.classification_threshold is None:
265: diff = prediction_results.all_predictions.iloc[:, 1] - model.meta.classification_threshold
419: if model.meta.feature_names:
420: input_df = input_df[model.meta.feature_names]
422: map_features_weight = dict(zip(model.meta.classification_labels, list_weights))
python-client/giskard/ml_worker/testing/utils.py
29: and isinstance(model.meta.classification_labels[0], numbers.Number)
41: f'{model.meta.classification_labels} and not the target: "{target}". '
46: model.meta.model_type != SupportedModelTypes.CLASSIFICATION
47: or classification_label in model.meta.classification_labels
48: ), f'"{classification_label}" is not part of model labels: {model.meta.classification_labels}'
python-client/giskard/utils/analytics_collector.py
59: [anonymize(n) for n in model.meta.feature_names]
60: if model.meta.feature_names
66: "model_type": model.meta.model_type.value,
python-client/giskard/models/model_explanation.py
71: features_names = model.meta.feature_names
200: feature_names = model.meta.feature_names or list(dataset.df.columns.drop(dataset.target, errors="ignore"))
204: return ShapResult(shap_explanations, feature_types, model.meta.model_type, only_highest_proba)
229: feature_names = model.meta.feature_names or list(dataset.df.columns.drop(dataset.target, errors="ignore"))
237: class_names=model.meta.classification_labels,
240: raise ValueError(f"Prediction task is not supported: {model.meta.model_type}")
python-client/giskard/models/_precooked.py
50: model.meta.model_type,
51: model.meta.feature_names,
52: model.meta.classification_labels,
python-client/giskard/models/base/model.py
31:META_FILENAME = "giskard-model-meta.yaml"
382: client.save_model_meta(project_key, self.id, self.meta, platform.python_version(), get_size(f))
409: meta_response = client.load_model_meta(project_key, model_id)
python-client/giskard/testing/tests/statistic.py
153: raise ValueError(f"Prediction task is not supported: {model.meta.model_type}")
238: if isinstance(model.meta.classification_labels[0], numbers.Number):
244: if positive_outcome not in list(model.meta.classification_labels):
246: f"The positive outcome chosen {positive_outcome} is not part of the dataset target values {list(model.meta.classification_labels)}."
python-client/giskard/integrations/mlflow/giskard_evaluator_utils.py
34: module = pyfunc_model.metadata.flavors["python_function"]["loader_module"]
37: return flavor.load_model(pyfunc_model.metadata.get_model_info().model_uri)
python-client/giskard/testing/tests/performance.py
51: is_binary_classification = len(model.meta.classification_labels) == 2
55: metric = score_fn(targets, prediction, pos_label=model.meta.classification_labels[1])
215: if len(model.meta.classification_labels) == 2:
python-client/giskard/testing/tests/metamorphic.py
186: passed_idx, failed_idx = _compare_prediction(results_df, model.meta.model_type, direction, output_sensitivity)
432: _, failed_idx = _compare_prediction(result_df, model.meta.model_type, direction, None)
python-client/giskard/testing/tests/drift.py
796: if classification_label is not None and isinstance(model.meta.classification_labels[0], numbers.Number):
892: if classification_label is not None and isinstance(model.meta.classification_labels[0], numbers.Number):
python-client/giskard/testing/tests/calibration.py
19: label2id = {label: n for n, label in enumerate(model.meta.classification_labels)}
31: n = len(model.meta.classification_labels)
python-client/giskard/push/perturbation.py
261: if model.meta.model_type == SupportedModelTypes.CLASSIFICATION:
270: elif model.meta.model_type == SupportedModelTypes.REGRESSION:
python-client/giskard/push/contribution.py
40: if model.meta.model_type == SupportedModelTypes.CLASSIFICATION:
48: elif model.meta.model_type == SupportedModelTypes.REGRESSION:
80: model_type=model.meta.model_type,
110: if model.meta.model_type == SupportedModelTypes.CLASSIFICATION:
124: model_type=model.meta.model_type,
257: if model.meta.model_type == SupportedModelTypes.CLASSIFICATION:
258: return explain(model, ds, df.iloc[0])["explanations"][model.meta.classification_labels[0]]
259: elif model.meta.model_type == SupportedModelTypes.REGRESSION:
python-client/giskard/scanner/scanner.py
77: num_features = len(model.meta.feature_names) if model.meta.feature_names else len(dataset.columns)
91: detectors = self.get_detectors(tags=[model.meta.model_type.value])
188: raise ValueError(f"Dataset must be provided for {model.meta.model_type.value} models.")
python-client/giskard/scanner/issues.py
105: return self.model.meta.feature_names or self.dataset.columns.tolist()
python-client/giskard/scanner/robustness/base_detector.py
40: if model.meta.feature_names:
41: features = [f for f in features if f in model.meta.feature_names]
python-client/giskard/scanner/correlation/spurious_correlation_detector.py
27: features = model.meta.feature_names or dataset.columns.drop(dataset.target, errors="ignore")
python-client/giskard/scanner/common/examples.py
50: num_labels_to_print = min(len(issue.model.meta.classification_labels), int(with_prediction))
55: "\n".join([f"{issue.model.meta.classification_labels[i]} (p = {ps[i]:.2f})" for i in label_idx])
python-client/giskard/scanner/common/loss_based_detector.py
41: max_data_size = self.MAX_DATASET_SIZE // len(model.meta.feature_names or dataset.columns)
78: features = model.meta.feature_names or dataset.columns.drop(dataset.target, errors="ignore")
python-client/giskard/scanner/performance/metrics.py
81: labels=model.meta.classification_labels,
82: pos_label=model.meta.classification_labels[1],
86: return metric_fn(y_true, y_pred, labels=model.meta.classification_labels, average="micro")
97: neg = model.meta.classification_labels[0]
111: return (y_pred == model.meta.classification_labels[1]).sum()
123: return (y_true == model.meta.classification_labels[1]).sum()
140: y_true, y_score, multi_class="ovo", labels=model.meta.classification_labels
python-client/giskard/scanner/performance/performance_bias_detector.py
86: metrics.log_loss([true_label], [probs], labels=model.meta.classification_labels)
…s-into-properties
7cf09e0 to
a5c636b
Compare
|
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.
LGTM
* Put all `BaseMode.meta` fields into `@property` methods * Moved model.meta.property to model.property * Moved model.meta.property to model.property * Import reorganization --------- Co-authored-by: Andrey Avtomonov <[email protected]>

Description
Put all
BaseMode.metafields into@propertymethodsRelated Issue
GSK-1957
Type of Change
Checklist
CODE_OF_CONDUCT.mddocument.CONTRIBUTING.mdguide.make codestyle.