Created
April 15, 2018 11:00
-
-
Save oem/a201b3651057981e069bb5db43b7251b to your computer and use it in GitHub Desktop.
cost function for linear regression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# features is a Matrix, labels and theta are Vectors | |
def cost_function(features, labels, theta) | |
m = features.row_count | |
predictions = predict(features, theta) | |
squared_errors = (predictions - labels).map { |error| error**2 } | |
(1.0 / (2.0 * m)) * squared_errors.reduce { |a, b| a + b } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment