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

Fixes#8847 #9141

Closed
wants to merge 2 commits into from
Closed

Conversation

mahi01agarwal
Copy link

Describe your change:

Fixes #8847

  • 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".

@algorithms-keeper algorithms-keeper bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Sep 30, 2023
@mahi01agarwal
Copy link
Author

Hey , I have created a pull request #9141 that fixes issue #8847 , Please review it.ThankYou.

Copy link
Contributor

@tianyizheng02 tianyizheng02 left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution. However, I'd really prefer that you don't just limit your fix to the univariate case, because the old implementation worked for multiple variables. Could you provide a direct-method implementation that also works for multiple variables?

"""
import numpy as np
import requests


# Function to collect the CSGO dataset
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Function to collect the CSGO dataset

This comment is unnecessary because we already have a docstring for the function.

Comment on lines +32 to +33
# Remove the labels (headers) from the list
data.pop(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Remove the labels (headers) from the list
data.pop(0)
data.pop(0) # Remove the labels (headers) from the list

# Remove the labels (headers) from the list
data.pop(0)

# Convert data to a NumPy matrix
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Convert data to a NumPy matrix

Comment is unnecessary because this line is already clear without one

:param theta : Feature vector (weight's for our model)
;param return : Updated Feature's, using
curr_features - alpha_ * gradient(w.r.t. feature)
# Function to calculate Mean Absolute Error (MAE)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Function to calculate Mean Absolute Error (MAE)

Unnecessary comment, we already have a docstring for the function

;param return : Updated Feature's, using
curr_features - alpha_ * gradient(w.r.t. feature)
# Function to calculate Mean Absolute Error (MAE)
def calculate_mae(predicted_y, original_y):
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add type hints

Comment on lines +47 to +49
return sum(abs(y - predicted_y[i]) for i, y in enumerate(original_y)) / len(
original_y
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return sum(abs(y - predicted_y[i]) for i, y in enumerate(original_y)) / len(
original_y
)
return sum(abs(y1 - y2) for y1, y2 in zip(predicted_y, original_y)) / len(
original_y
)

)


# Function to perform simple linear regression
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Function to perform simple linear regression

Comment is unnecessary when there's already a docstring for the function



# Function to perform simple linear regression
def simple_solve(data_x, data_y):
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add type hints

Comment on lines +84 to +87
print(f"sse is: {sse}")
print(f"Half mse is: {half_mse}")
print(f"Coefficient is: {beta_1}")
print(f"Intercept is: {beta_0}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please read the contributing guidelines. Algorithmic functions should avoid side effects, including printing. Instead, please have your function simply return the regression coefficients.

@cclauss
Copy link
Member

cclauss commented Sep 30, 2023

The title of this pull request is not self-documenting. Why force readers and reviewers to look up an issue? Closing.

@cclauss cclauss closed this Sep 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

machine_learning/linear_regression.py doesn't give optimal coefficients
3 participants