Skip to content

Instantly share code, notes, and snippets.

@kayhman
Last active October 6, 2020 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kayhman/7ec09daf1226132aa7c566644fb9795c to your computer and use it in GitHub Desktop.
Save kayhman/7ec09daf1226132aa7c566644fb9795c to your computer and use it in GitHub Desktop.
import numpy as np
def linear_predictions(weights, inputs):
# y = weights[0] inputs[0] + weights[1] * inputs[1]
# where inputs[0] = 1.0
return np.dot(inputs, weights) * 60.0
def squared_loss(weights, inputs, targets):
# Training loss is the negative squared loss
preds = linear_predictions(weights, inputs)
err = (preds - targets)**2
return np.sum(err)
v_avg = 30 # km/h
startup_time = 2 /60.0 # hours
inputs = np.array([[1.0, 6.0],
[1.0, 4.0 ]])
targets = np.array([13, 10.5])
weights = np.array([startup_time, 1.0 / v_avg]) # Program params are estimaed by experience, stats analysis, Least Square Error, ...
print("Trained loss:", squared_loss(weights, inputs, targets))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment