|
5 | 5 | import json |
6 | 6 | import logging |
7 | 7 | import os |
| 8 | +from collections.abc import Callable, Mapping, Sequence |
8 | 9 | from contextlib import nullcontext |
9 | 10 | from copy import deepcopy |
10 | 11 | from dataclasses import dataclass, field |
|
13 | 14 | from math import ceil, isnan |
14 | 15 | from multiprocessing.managers import SharedMemoryManager |
15 | 16 | from operator import itemgetter |
16 | | -from typing import Callable, Dict, List, Mapping, Optional, Sequence, Tuple, Union |
| 17 | +from typing import Optional, Union |
17 | 18 | from warnings import warn |
18 | 19 |
|
19 | 20 | import numpy as np |
@@ -1950,7 +1951,7 @@ def _from_json(self, file): |
1950 | 1951 | UNTESTED_from_jsonable(self, jsonable) |
1951 | 1952 | else: |
1952 | 1953 | # file is a file-like object implementing .read() |
1953 | | - jsonable = json.load(fp) |
| 1954 | + jsonable = json.load(file) |
1954 | 1955 | UNTESTED_from_jsonable(self, jsonable) |
1955 | 1956 | return self |
1956 | 1957 |
|
@@ -3220,23 +3221,23 @@ class ExplainableBoostingClassifier(ClassifierMixin, EBMModel): |
3220 | 3221 | """ |
3221 | 3222 |
|
3222 | 3223 | n_features_in_: int |
3223 | | - term_names_: List[str] |
3224 | | - bins_: List[Union[List[Dict[str, int]], List[np.ndarray]]] # np.float64, 1D[cut] |
3225 | | - feature_names_in_: List[str] |
3226 | | - feature_types_in_: List[str] |
| 3224 | + term_names_: list[str] |
| 3225 | + bins_: list[Union[list[dict[str, int]], list[np.ndarray]]] # np.float64, 1D[cut] |
| 3226 | + feature_names_in_: list[str] |
| 3227 | + feature_types_in_: list[str] |
3227 | 3228 | feature_bounds_: np.ndarray # np.float64, 2D[feature, min_max] |
3228 | | - term_features_: List[Tuple[int, ...]] |
3229 | | - bin_weights_: List[np.ndarray] # np.float64, [bin0...] |
3230 | | - bagged_scores_: List[np.ndarray] # np.float64, [bag, bin0..., ?class] |
3231 | | - term_scores_: List[np.ndarray] # np.float64, [bin0..., ?class] |
3232 | | - standard_deviations_: List[np.ndarray] # np.float64, [bin0..., ?class] |
| 3229 | + term_features_: list[tuple[int, ...]] |
| 3230 | + bin_weights_: list[np.ndarray] # np.float64, [bin0...] |
| 3231 | + bagged_scores_: list[np.ndarray] # np.float64, [bag, bin0..., ?class] |
| 3232 | + term_scores_: list[np.ndarray] # np.float64, [bin0..., ?class] |
| 3233 | + standard_deviations_: list[np.ndarray] # np.float64, [bin0..., ?class] |
3233 | 3234 | link_: str |
3234 | 3235 | link_param_: float |
3235 | 3236 | bag_weights_: np.ndarray # np.float64, 1D[bag] |
3236 | 3237 | best_iteration_: np.ndarray # np.int64, 2D[stage, bag] |
3237 | 3238 |
|
3238 | | - histogram_edges_: List[Union[None, np.ndarray]] # np.float64, 1D[hist_edge] |
3239 | | - histogram_weights_: List[np.ndarray] # np.float64, 1D[hist_bin] |
| 3239 | + histogram_edges_: list[Union[None, np.ndarray]] # np.float64, 1D[hist_edge] |
| 3240 | + histogram_weights_: list[np.ndarray] # np.float64, 1D[hist_bin] |
3240 | 3241 | unique_val_counts_: np.ndarray # np.int64, 1D[feature] |
3241 | 3242 |
|
3242 | 3243 | classes_: np.ndarray # np.int64, np.bool_, or np.unicode_, 1D[class] |
@@ -3730,23 +3731,23 @@ class ExplainableBoostingRegressor(RegressorMixin, EBMModel): |
3730 | 3731 | """ |
3731 | 3732 |
|
3732 | 3733 | n_features_in_: int |
3733 | | - term_names_: List[str] |
3734 | | - bins_: List[Union[List[Dict[str, int]], List[np.ndarray]]] # np.float64, 1D[cut] |
3735 | | - feature_names_in_: List[str] |
3736 | | - feature_types_in_: List[str] |
| 3734 | + term_names_: list[str] |
| 3735 | + bins_: list[Union[list[dict[str, int]], list[np.ndarray]]] # np.float64, 1D[cut] |
| 3736 | + feature_names_in_: list[str] |
| 3737 | + feature_types_in_: list[str] |
3737 | 3738 | feature_bounds_: np.ndarray # np.float64, 2D[feature, min_max] |
3738 | | - term_features_: List[Tuple[int, ...]] |
3739 | | - bin_weights_: List[np.ndarray] # np.float64, [bin0...] |
3740 | | - bagged_scores_: List[np.ndarray] # np.float64, [bag, bin0...] |
3741 | | - term_scores_: List[np.ndarray] # np.float64, [bin0...] |
3742 | | - standard_deviations_: List[np.ndarray] # np.float64, [bin0...] |
| 3739 | + term_features_: list[tuple[int, ...]] |
| 3740 | + bin_weights_: list[np.ndarray] # np.float64, [bin0...] |
| 3741 | + bagged_scores_: list[np.ndarray] # np.float64, [bag, bin0...] |
| 3742 | + term_scores_: list[np.ndarray] # np.float64, [bin0...] |
| 3743 | + standard_deviations_: list[np.ndarray] # np.float64, [bin0...] |
3743 | 3744 | link_: str |
3744 | 3745 | link_param_: float |
3745 | 3746 | bag_weights_: np.ndarray # np.float64, 1D[bag] |
3746 | 3747 | best_iteration_: np.ndarray # np.int64, 2D[stage, bag] |
3747 | 3748 |
|
3748 | | - histogram_edges_: List[Union[None, np.ndarray]] # np.float64, 1D[hist_edge] |
3749 | | - histogram_weights_: List[np.ndarray] # np.float64, 1D[hist_bin] |
| 3749 | + histogram_edges_: list[Union[None, np.ndarray]] # np.float64, 1D[hist_edge] |
| 3750 | + histogram_weights_: list[np.ndarray] # np.float64, 1D[hist_bin] |
3750 | 3751 | unique_val_counts_: np.ndarray # np.int64, 1D[feature] |
3751 | 3752 |
|
3752 | 3753 | intercept_: float |
@@ -4007,16 +4008,16 @@ class DPExplainableBoostingClassifier(ClassifierMixin, EBMModel): |
4007 | 4008 | """ |
4008 | 4009 |
|
4009 | 4010 | n_features_in_: int |
4010 | | - term_names_: List[str] |
4011 | | - bins_: List[Union[List[Dict[str, int]], List[np.ndarray]]] # np.float64, 1D[cut] |
4012 | | - feature_names_in_: List[str] |
4013 | | - feature_types_in_: List[str] |
| 4011 | + term_names_: list[str] |
| 4012 | + bins_: list[Union[list[dict[str, int]], list[np.ndarray]]] # np.float64, 1D[cut] |
| 4013 | + feature_names_in_: list[str] |
| 4014 | + feature_types_in_: list[str] |
4014 | 4015 | feature_bounds_: np.ndarray # np.float64, 2D[feature, min_max] |
4015 | | - term_features_: List[Tuple[int, ...]] |
4016 | | - bin_weights_: List[np.ndarray] # np.float64, [bin] |
4017 | | - bagged_scores_: List[np.ndarray] # np.float64, [bag, bin] |
4018 | | - term_scores_: List[np.ndarray] # np.float64, [bin] |
4019 | | - standard_deviations_: List[np.ndarray] # np.float64, [bin] |
| 4016 | + term_features_: list[tuple[int, ...]] |
| 4017 | + bin_weights_: list[np.ndarray] # np.float64, [bin] |
| 4018 | + bagged_scores_: list[np.ndarray] # np.float64, [bag, bin] |
| 4019 | + term_scores_: list[np.ndarray] # np.float64, [bin] |
| 4020 | + standard_deviations_: list[np.ndarray] # np.float64, [bin] |
4020 | 4021 | link_: str |
4021 | 4022 | link_param_: float |
4022 | 4023 | bag_weights_: np.ndarray # np.float64, 1D[bag] |
@@ -4062,7 +4063,7 @@ def __init__( |
4062 | 4063 | composition: str = "gdp", |
4063 | 4064 | bin_budget_frac: float = 0.1, |
4064 | 4065 | privacy_bounds: Optional[ |
4065 | | - Union[np.ndarray, Mapping[Union[int, str], Tuple[float, float]]] |
| 4066 | + Union[np.ndarray, Mapping[Union[int, str], tuple[float, float]]] |
4066 | 4067 | ] = None, |
4067 | 4068 | ): |
4068 | 4069 | super().__init__( |
@@ -4344,16 +4345,16 @@ class DPExplainableBoostingRegressor(RegressorMixin, EBMModel): |
4344 | 4345 | """ |
4345 | 4346 |
|
4346 | 4347 | n_features_in_: int |
4347 | | - term_names_: List[str] |
4348 | | - bins_: List[Union[List[Dict[str, int]], List[np.ndarray]]] # np.float64, 1D[cut] |
4349 | | - feature_names_in_: List[str] |
4350 | | - feature_types_in_: List[str] |
| 4348 | + term_names_: list[str] |
| 4349 | + bins_: list[Union[list[dict[str, int]], list[np.ndarray]]] # np.float64, 1D[cut] |
| 4350 | + feature_names_in_: list[str] |
| 4351 | + feature_types_in_: list[str] |
4351 | 4352 | feature_bounds_: np.ndarray # np.float64, 2D[feature, min_max] |
4352 | | - term_features_: List[Tuple[int, ...]] |
4353 | | - bin_weights_: List[np.ndarray] # np.float64, [bin0...] |
4354 | | - bagged_scores_: List[np.ndarray] # np.float64, [bag, bin0..., ?class] |
4355 | | - term_scores_: List[np.ndarray] # np.float64, [bin0..., ?class] |
4356 | | - standard_deviations_: List[np.ndarray] # np.float64, [bin0..., ?class] |
| 4353 | + term_features_: list[tuple[int, ...]] |
| 4354 | + bin_weights_: list[np.ndarray] # np.float64, [bin0...] |
| 4355 | + bagged_scores_: list[np.ndarray] # np.float64, [bag, bin0..., ?class] |
| 4356 | + term_scores_: list[np.ndarray] # np.float64, [bin0..., ?class] |
| 4357 | + standard_deviations_: list[np.ndarray] # np.float64, [bin0..., ?class] |
4357 | 4358 | link_: str |
4358 | 4359 | link_param_: float |
4359 | 4360 | bag_weights_: np.ndarray # np.float64, 1D[bag] |
@@ -4401,7 +4402,7 @@ def __init__( |
4401 | 4402 | composition: str = "gdp", |
4402 | 4403 | bin_budget_frac: float = 0.1, |
4403 | 4404 | privacy_bounds: Optional[ |
4404 | | - Union[np.ndarray, Mapping[Union[int, str], Tuple[float, float]]] |
| 4405 | + Union[np.ndarray, Mapping[Union[int, str], tuple[float, float]]] |
4405 | 4406 | ] = None, |
4406 | 4407 | privacy_target_min: Optional[float] = None, |
4407 | 4408 | privacy_target_max: Optional[float] = None, |
|
0 commit comments