Conversation
snippets/linear_regression.py
Outdated
|
|
||
| def compCostFunction(estim_y, true_y): | ||
| E = estim_y - true_y | ||
| C = (1 / 2 * m) * np.sum(E ** 2) |
There was a problem hiding this comment.
where does the variable m come from here?
There was a problem hiding this comment.
Yes, global variables are terrible. Please move all the code defining variables into a function.
There was a problem hiding this comment.
... and m should be a parameter that is passed into the function.
| assert isinstance(y, np.ndarray), "Only works for arrays" | ||
| return x.shape[0] == y.shape[0] | ||
|
|
||
| # To be deleted later |
There was a problem hiding this comment.
are these comments obsolete? if yes, please remove
| # To be deleted later | ||
| # feature_1 = np.linspace(0, 2, num=100) | ||
|
|
||
| X = np.random.randn(100,3) # feature matrix |
There was a problem hiding this comment.
could the variables be named with more informative names?
snippets/linear_regression.py
Outdated
|
|
||
| return W, cost_history | ||
|
|
||
| params, history = iterativeLinearRegression(X, y) |
There was a problem hiding this comment.
The code should be restructured so that the module can be imported and does nothing.
The test code should be under if __name__ == '__main__':.
lilianAweber
left a comment
There was a problem hiding this comment.
Add some small comments and questions
snippets/linear_regression.py
Outdated
| # feature_1 = np.linspace(0, 2, num=100) | ||
|
|
||
| X = np.random.randn(100,3) # feature matrix | ||
| y = 1 + np.dot(X, [3.5, 4., -4]) # target vector |
There was a problem hiding this comment.
I'd write this as
y = 1 + X @ [3.5, 4., -4]) # target vector
# z = 2 + y @ feature_matrix @ feature_matrix.T| params, history = iterativeLinearRegression(X, y) | ||
| print(params) | ||
|
|
||
| import matplotlib.pyplot as plt |
There was a problem hiding this comment.
This duplicates line above…
| print(params) | ||
| print(history) | ||
|
|
||
| import matplotlib.pyplot as plt |
There was a problem hiding this comment.
This should be moved to the header
snippets/linear_regression.py
Outdated
| # iterate until the maximum number of steps | ||
| for i in np.arange(steps): # begin the process | ||
|
|
||
| y_estimated = X.dot(W) |
snippets/linear_regression.py
Outdated
| cost = compCostFunction(y_estimated, y) | ||
| # Update gradient descent | ||
| E = y_estimated - y | ||
| gradient = (1 / m) * X.T.dot(E) |

No description provided.