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

Fix DeprecationWarning in local_weighted_learning.py #9165

Merged
merged 1 commit into from
Oct 1, 2023

Conversation

tianyizheng02
Copy link
Contributor

Describe your change:

Recent build logs (e.g., this one) show that machine_learning/local_weighted_learning/local_weighted_learning.py produces a DeprecationWarning:

machine_learning/local_weighted_learning/local_weighted_learning.py::machine_learning.local_weighted_learning.local_weighted_learning.local_weight_regression
machine_learning/local_weighted_learning/local_weighted_learning.py::machine_learning.local_weighted_learning.local_weighted_learning.local_weight_regression
machine_learning/local_weighted_learning/local_weighted_learning.py::machine_learning.local_weighted_learning.local_weighted_learning.local_weight_regression
  /home/runner/work/Python/Python/machine_learning/local_weighted_learning/local_weighted_learning.py:125: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
    y_pred[i] = item @ local_weight(item, x_train, y_train, tau)

This warning occurs because the output of @, which is an np.ndarray, is being implicitly converted to a scalar. This PR replaces @ with np.dot() to resolve this warning.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

Fix DeprecationWarning that occurs during build due to converting an
np.ndarray to a scalar implicitly
@algorithms-keeper algorithms-keeper bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Oct 1, 2023
@ChrisO345 ChrisO345 merged commit 5f8d1cb into TheAlgorithms:master Oct 1, 2023
@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Oct 1, 2023
@tianyizheng02
Copy link
Contributor Author

@ChrisO345 I just took a look at this PR's build logs and apparently the DeprecationWarning is still there, even with the new np.dot function call. I'll open a new PR to try to fix it again, and I'll request your review once I confirm that it's actually fixed.

sedatguzelsemme pushed a commit to sedatguzelsemme/Python that referenced this pull request Sep 15, 2024
)

Fix DeprecationWarning that occurs during build due to converting an
np.ndarray to a scalar implicitly
@isidroas isidroas mentioned this pull request Jan 25, 2025
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This PR modified some existing files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants