Skip to content
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

Correct possible bug #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Correct possible bug #29

wants to merge 1 commit into from

Conversation

seazuma
Copy link

@seazuma seazuma commented Mar 17, 2022

I appreciate your library smogn. I found some suspicious points in over_sampling.py and tried to fix them.

(1) Line 88:
if data.iloc[:, j].dtype in num_dtypes and any(data.iloc[:, j] > 0):
-->
if data.iloc[:, j].dtype in num_dtypes and all(data.iloc[:, j] > 0):
(2) over_sampling.py, Line 283-285, 377-379:
synth_matrix[i * x_synth + j,
(d - 1)] = data.iloc[i, (d - 1)] + data.iloc[
knn_matrix[i, neigh], (d - 1)] / 2
-->
synth_matrix[i * x_synth + j,
(d - 1)] = ( data.iloc[i, (d - 1)] + data.iloc[
knn_matrix[i, neigh], (d - 1)] ) / 2
(3) over_sampling.py, Line 267, 363:
for z in feat_list_num:
-->
for z in feat_list_num[0:(d-1)]:
(Because when z=d-1, the entry synth_matrix[x_synth * n + count, z] is not defined yet.)

(1) Line 88:
if data.iloc[:, j].dtype in num_dtypes and any(data.iloc[:, j] > 0):
-->
if data.iloc[:, j].dtype in num_dtypes and all(data.iloc[:, j] > 0):
(2) over_sampling.py, Line 283-285, 377-379:
synth_matrix[i * x_synth + j, 
(d - 1)] = data.iloc[i, (d - 1)] + data.iloc[
knn_matrix[i, neigh], (d - 1)] / 2
-->
synth_matrix[i * x_synth + j, 
(d - 1)] = ( data.iloc[i, (d - 1)] + data.iloc[
knn_matrix[i, neigh], (d - 1)] ) / 2
(3) over_sampling.py, Line 267, 363:
for z in feat_list_num:
-->
for z in feat_list_num[0:(d-1)]:
(Because when z=d-1, the entry synth_matrix[x_synth * n + count, z] is not defined yet.)
Copy link
Owner

@nickkunz nickkunz left a comment

Choose a reason for hiding this comment

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

@seazuma thank you for opening this PR. I just had a couple of questions I was hoping you might be able to address.

(d - 1)] = data.iloc[i, (d - 1)] + data.iloc[
knn_matrix[i, neigh], (d - 1)] / 2
(d - 1)] = (data.iloc[i, (d - 1)] + data.iloc[
knn_matrix[i, neigh], (d - 1)]) / 2
Copy link
Owner

Choose a reason for hiding this comment

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

This is good.

@@ -264,7 +264,7 @@ def over_sampling(

## generate synthetic y response variable by
## inverse distance weighted
for z in feat_list_num:
for z in feat_list_num[0:(d - 1)]:
Copy link
Owner

Choose a reason for hiding this comment

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

Why is this preferred (genuinely curious)?

Copy link
Author

Choose a reason for hiding this comment

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

I made this change because synth_matrix[:,z] was only defined for 0:(d-1).

@@ -85,7 +85,7 @@ def over_sampling(
num_dtypes = ["int64", "float64"]

for j in range(d):
if data.iloc[:, j].dtype in num_dtypes and any(data.iloc[:, j] > 0):
if data.iloc[:, j].dtype in num_dtypes and all(data.iloc[:, j] > 0):
Copy link
Owner

Choose a reason for hiding this comment

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

What is this doing that any() is not?

Copy link
Author

Choose a reason for hiding this comment

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

all() assures all elements are positive.
any() only assures that some elements are positive (there may also be negative elements).
I made this change because I thought the former is expected here.

@@ -360,7 +360,7 @@ def over_sampling(

## generate synthetic y response variable by
## inverse distance weighted
for z in feat_list_num:
for z in feat_list_num[0:(d - 1)]:
Copy link
Owner

Choose a reason for hiding this comment

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

Why is this preferred (genuinely curious)?

Copy link
Author

Choose a reason for hiding this comment

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

I made this change because synth_matrix[:,z] was only defined for 0:(d-1).

@@ -374,9 +374,9 @@ def over_sampling(
x_synth * n + count, feat_list_nom])

if a == b:
synth_matrix[x_synth * n + count, (d - 1)] = data.iloc[
synth_matrix[x_synth * n + count, (d - 1)] = (data.iloc[
Copy link
Owner

Choose a reason for hiding this comment

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

This is good.

@nickkunz
Copy link
Owner

@seazuma I hope that you might be able to address some of the questions I had in your PR. Thank you.

@seazuma
Copy link
Author

seazuma commented Aug 30, 2022

@nickkunz I apologize for having failed to notice your comments before. Thank you for letting me know again. I have replied to them.

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