Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Nov 30, 2023

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from ChawlaAvi November 30, 2023 13:11
Comment on lines -34 to +43
# classify features into 3 types: binary, float and int
binary_features = []
for col in X.columns.values:
if list(sorted(np.unique(X[col].values))) == [0, 1]:
binary_features.append(col)

int_features = []
for col in list(set(X.columns.values) - set(binary_features)):
if list(X[col].map(int).values) == list(X[col].values):
int_features.append(col)

binary_features = [
col
for col in X.columns.values
if list(sorted(np.unique(X[col].values))) == [0, 1]
]
int_features = [
col
for col in list(set(X.columns.values) - set(binary_features))
if list(X[col].map(int).values) == list(X[col].values)
]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _get_tree_info refactored with the following changes:

This removes the following comments ( why? ):

# classify features into 3 types: binary, float and int

Comment on lines -89 to +110
features = tree_info['features']
binary_features = tree_info['binary_features']
int_features = tree_info['int_features']
target_names = tree_info['target_names']

node = {}
if parent == 'null':
node['name'] = "HEAD"
else:
features = tree_info['features']
feature = features[parent]
binary_features = tree_info['binary_features']
int_features = tree_info['int_features']
if pos == 'left':
if feature in binary_features:
node['name'] = feature + ': 0'
node['name'] = f'{feature}: 0'
elif feature in int_features:
node['name'] = feature + " <= " + str(int(tree_model.tree_.threshold[parent]))
node['name'] = f"{feature} <= {int(tree_model.tree_.threshold[parent])}"
else:
node['name'] = feature + " <= " + str(round(tree_model.tree_.threshold[parent], 3))
node[
'name'
] = f"{feature} <= {str(round(tree_model.tree_.threshold[parent], 3))}"
elif feature in binary_features:
node['name'] = f'{feature}: 1'
elif feature in int_features:
node['name'] = f"{feature} > {int(tree_model.tree_.threshold[parent])}"
else:
if feature in binary_features:
node['name'] = feature + ': 1'
elif feature in int_features:
node['name'] = feature + " > " + str(int(tree_model.tree_.threshold[parent]))
else:
node['name'] = feature + " > " + str(round(tree_model.tree_.threshold[parent], 3))
node[
'name'
] = f"{feature} > {str(round(tree_model.tree_.threshold[parent], 3))}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _parse_tree refactored with the following changes:

Comment on lines -157 to +155
tree_rules[node_id] = {}
tree_rules[node_id]['features'] = {}

tree_rules[node_id] = {'features': {}}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _extract_rules refactored with the following changes:

Comment on lines -205 to +214
if feat[0] == -sys.maxsize:
rule = k + ': 0'
else:
rule = k + ': 1'
rule = f'{k}: 0' if feat[0] == -sys.maxsize else f'{k}: 1'
elif k in tree_info['int_features']:
if feat[0] == -sys.maxsize:
rule = k + ' <= ' + str(int(feat[1]))
rule = f'{k} <= {int(feat[1])}'
elif feat[1] == sys.maxsize:
rule = k + ' > ' + str(int(feat[0]))
rule = f'{k} > {int(feat[0])}'
else:
rule = str(int(feat[0])) + ' < ' + k + ' <= ' + str(int(feat[1]))
rule = f'{int(feat[0])} < {k} <= {int(feat[1])}'
elif feat[0] == -sys.maxsize:
rule = f'{k} <= {str(round(feat[1], 3))}'
elif feat[1] == sys.maxsize:
rule = f'{k} > {str(round(feat[0], 3))}'
else:
if feat[0] == -sys.maxsize:
rule = k + ' <= ' + str(round(feat[1], 3))
elif feat[1] == sys.maxsize:
rule = k + ' > ' + str(round(feat[0], 3))
else:
rule = str(round(feat[0], 3)) + ' < ' + k + ' <= ' + str(round(feat[1], 3))
rule = f'{str(round(feat[0], 3))} < {k} <= {str(round(feat[1], 3))}'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _clean_rules refactored with the following changes:

if n<=1:
return 1
return fib(n-1) + fib(n-2)
return 1 if n<=1 else fib(n-1) + fib(n-2)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function fib refactored with the following changes:

if n<=1:
return 1
return fib(n-1) + fib(n-2)
return 1 if n<=1 else fib(n-1) + fib(n-2)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function fib refactored with the following changes:

ChawlaAvi

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants