Skip to content

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.

## 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).


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.

## 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).


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