Skip to content

Commit

Permalink
Pass flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
guillermo-navas-palencia committed Jan 14, 2024
1 parent 25f4c43 commit 591e224
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 49 deletions.
28 changes: 15 additions & 13 deletions optbinning/binning/binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -1176,25 +1176,26 @@ def status(self):
self._check_is_fitted()

return self._status
def to_json(self, path: str):

def to_json(self, path):
"""
Save optimal bins and/or splits points and transformation depending on the target type.
Save optimal bins and/or splits points and transformation depending on
the target type.
Parameters
----------
path: The path where the json is going to be saved
path: The path where the json is going to be saved.
"""
if path is None:
raise ValueError('Specify the path for the json file')

table = self.binning_table

opt_bin_dict=dict()
opt_bin_dict = dict()
opt_bin_dict['name'] = table.name
opt_bin_dict['dtype'] = table.dtype
opt_bin_dict['special_codes'] = table.special_codes

if table.dtype == 'numerical':
opt_bin_dict['splits'] = table.splits.tolist()
elif table.dtype == 'categorical':
Expand All @@ -1211,22 +1212,23 @@ def to_json(self, path: str):

with open(path, "w") as write_file:
json.dump(opt_bin_dict, write_file)
def read_json(self, path: str):

def read_json(self, path):
"""
Read json file containing split points and set them as the new split points.
Read json file containing split points and set them as the new split
points.
Parameters
----------
----------
path: The path of the json file.
"""
self._is_fitted = True

with open(path, "r") as read_file:
bin_table_attr = json.load(read_file)

for key in bin_table_attr.keys():
if isinstance(bin_table_attr[key], list):
bin_table_attr[key] = np.array(bin_table_attr[key])

self._binning_table = BinningTable(**bin_table_attr)
12 changes: 7 additions & 5 deletions optbinning/binning/binning_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ class ContinuousBinningTable:
def __init__(self, name, dtype, special_codes, splits, n_records, sums,
stds, min_target, max_target, n_zeros, min_x=None, max_x=None,
categories=None, cat_others=None, user_splits=None):

self.name = name
self.dtype = dtype
self.special_codes = special_codes
Expand Down Expand Up @@ -1696,8 +1696,11 @@ def plot(self, add_special=True, add_missing=True, style="bin",
Parameters
----------
metric : str, optional (default="mean")
Supported metrics are "mean" to show the Mean value of the target variable in each bin,
"iv" to show the IV of each bin and "woe" to show the Weight of Evidence (WoE) of each bin.
Supported metrics are "mean" to show the Mean value of the target
variable in each bin, "iv" to show the IV of each bin and "woe" to
show the Weight of Evidence (WoE) of each bin.
.. versionadded:: 0.19.0
add_special : bool (default=True)
Whether to add the special codes bin.
Expand Down Expand Up @@ -1763,7 +1766,7 @@ def plot(self, add_special=True, add_missing=True, style="bin",
elif self.min_x is None or self.max_x is None:
raise ValueError('If style="actual", min_x and max_x must be '
'provided.')

if metric == "mean":
metric_values = self._mean
metric_label = "Mean"
Expand Down Expand Up @@ -2084,4 +2087,3 @@ def quality_score(self):
_check_is_analyzed(self)

return self._quality_score

30 changes: 16 additions & 14 deletions optbinning/binning/continuous_binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,25 +978,26 @@ def binning_table(self):
self._check_is_fitted()

return self._binning_table
def to_json(self, path: str):

def to_json(self, path):
"""
Save optimal bins and/or splits points and transformation depending on the target type.
Save optimal bins and/or splits points and transformation depending on
the target type.
Parameters
----------
path: The path where the json is going to be saved
path: The path where the json is going to be saved.
"""
if path is None:
raise ValueError('Specify the path for the json file.')

table = self.binning_table

opt_bin_dict=dict()
opt_bin_dict = dict()
opt_bin_dict['name'] = table.name
opt_bin_dict['dtype'] = table.dtype
opt_bin_dict['special_codes'] = table.special_codes

if table.dtype == 'numerical':
opt_bin_dict['splits'] = table.splits.tolist()
elif table.dtype == 'categorical':
Expand All @@ -1017,25 +1018,26 @@ def to_json(self, path: str):

with open(path, "w") as write_file:
json.dump(opt_bin_dict, write_file)
def read_json(self, path: str):

def read_json(self, path):
"""
Read json file containing split points and set them as the new split points.
Read json file containing split points and set them as the new split
points.
Parameters
----------
----------
path: The path of the json file.
"""
if path is None:
raise ValueError('Specify the path for the json file.')

self._is_fitted = True

with open(path, "r") as read_file:
cont_table_attr = json.load(read_file)

for key in cont_table_attr.keys():
if isinstance(cont_table_attr[key], list):
cont_table_attr[key] = np.array(cont_table_attr[key])

self._binning_table = ContinuousBinningTable(**cont_table_attr)
2 changes: 1 addition & 1 deletion optbinning/binning/cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def build_model_scenarios(self, n_nonevent, n_event, w):
# Constraint: max-pvalue
for s in range(n_scenarios):
self.add_constraint_violation(model, x,
pvalue_violation_indices[s])
pvalue_violation_indices[s])

# Constraint: min diff
for s in range(n_scenarios):
Expand Down
32 changes: 16 additions & 16 deletions optbinning/binning/multiclass_binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,51 +874,51 @@ def splits(self):
self._check_is_fitted()

return self._splits_optimal
def to_json(self, path: str):

def to_json(self, path):
"""
Save optimal bins and/or splits points and transformation depending on the target type.
Save optimal bins and/or splits points and transformation depending on
the target type.
Parameters
----------
path: The path where the json is going to be saved
path: The path where the json is going to be saved.
"""
if path is None:
raise ValueError('Specify the path for the json file.')

table = self.binning_table

opt_bin_dict=dict()
opt_bin_dict = dict()
opt_bin_dict['name'] = table.name
opt_bin_dict['special_codes'] = table.special_codes

opt_bin_dict['splits'] = table.splits.tolist()

opt_bin_dict['splits'] = table.splits.tolist()
opt_bin_dict['n_event'] = table.n_event.tolist()

opt_bin_dict['classes'] = table.classes.tolist()

with open(path, "w") as write_file:
json.dump(opt_bin_dict, write_file)
def read_json(self, path: str):

def read_json(self, path):
"""
Read json file containing split points and set them as the new split points.
Read json file containing split points and set them as the new split
points.
Parameters
----------
----------
path: The path of the json file.
"""
if path is None:
raise ValueError('Specify the path for the json file.')

self._is_fitted = True

with open(path, "r") as read_file:
multi_table_attr = json.load(read_file)

for key in multi_table_attr.keys():
if isinstance(multi_table_attr[key], list):
multi_table_attr[key] = np.array(multi_table_attr[key])

self._binning_table = MulticlassBinningTable(**multi_table_attr)

0 comments on commit 591e224

Please sign in to comment.