def fit(self, encoded_data: EncodedData, label_name: str, cores_for_training: int = 2): self.class_mapping = Util.make_class_mapping(encoded_data.labels[label_name]) self.feature_names = encoded_data.feature_names self.label_name = label_name mapped_y = Util.map_to_new_class_values(encoded_data.labels[label_name], self.class_mapping) self.model = CacheHandler.memo_by_params(self._prepare_caching_params(encoded_data, encoded_data.labels[label_name], self.FIT, label_name), lambda: self._fit(encoded_data.examples, mapped_y, cores_for_training))
def fit_by_cross_validation(self, encoded_data: EncodedData, number_of_splits: int = 5, label_name: str = None, cores_for_training: int = -1, optimization_metric='balanced_accuracy'): self.class_mapping = Util.make_class_mapping(encoded_data.labels[label_name]) self.feature_names = encoded_data.feature_names self.label_name = label_name mapped_y = Util.map_to_new_class_values(encoded_data.labels[label_name], self.class_mapping) self.model = CacheHandler.memo_by_params( self._prepare_caching_params(encoded_data, mapped_y, self.FIT_CV, label_name, number_of_splits), lambda: self._fit_by_cross_validation(encoded_data.examples, mapped_y, number_of_splits, label_name, cores_for_training, optimization_metric))
def fit(self, encoded_data: EncodedData, label: Label, cores_for_training: int = 2): self.label = label self.class_mapping = Util.make_class_mapping( encoded_data.labels[self.label.name]) self.feature_names = encoded_data.feature_names mapped_y = Util.map_to_new_class_values( encoded_data.labels[self.label.name], self.class_mapping) self.model = self._fit(encoded_data.examples, mapped_y, cores_for_training)
def _make_roc_curve(self, hp_item: HPItem, label_name: str, proba_name: str) -> dict: df = pd.read_csv(hp_item.test_predictions_path) true_y = df[f"{label_name}_true_class"].values predicted_y = df[proba_name].values true_y = Util.map_to_new_class_values( true_y, hp_item.method.get_class_mapping()) fpr, tpr, _ = roc_curve(y_true=true_y, y_score=predicted_y) return { "FPR": fpr, "TPR": tpr, "AUC": roc_auc_score(true_y=true_y, predicted_y=predicted_y), "HPItem": str(hp_item.hp_setting) }
def fit_by_cross_validation(self, encoded_data: EncodedData, number_of_splits: int = 5, label: Label = None, cores_for_training: int = -1, optimization_metric='balanced_accuracy'): self.class_mapping = Util.make_class_mapping( encoded_data.labels[label.name]) self.feature_names = encoded_data.feature_names self.label = label mapped_y = Util.map_to_new_class_values( encoded_data.labels[self.label.name], self.class_mapping) self.model = self._fit_by_cross_validation(encoded_data.examples, mapped_y, number_of_splits, label, cores_for_training, optimization_metric)