Created
November 6, 2019 12:18
-
-
Save ice2heart/6d9ecb007bcb10f3914e0069b255632e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
from mpl_toolkits.mplot3d import Axes3D | |
data = pd.read_csv('weights_heights.csv', index_col='Index') | |
# height = data.Height.values | |
# weight = data.Weight.values | |
# vfunc = np.vectorize(lambda x, y: (y - (w0 + w1 * x))**2) | |
def error(w0, w1): | |
# return sum(map(vfunc, data.Weight, data.Height)) # 4.867 | |
return sum(map(lambda x, y: (y - (w0 + w1 * x))**2, data.Weight, data.Height)) # cpu 2.862 total | |
# return sum(map(lambda x, y: (y - (w0 + w1 * x))**2, weight, height)) # 3.343 total | |
fig = plt.figure() | |
fig.set_size_inches(15, 10) | |
ax = fig.gca(projection='3d') | |
w0 = np.arange(-100, 100, 1) | |
w1 = np.arange(-5, 5, 0.1) | |
w0, w1 = np.meshgrid(w0, w1) | |
er = error(w0, w1) | |
surf = ax.plot_surface(w0, w1, er) | |
ax.set_xlabel('Intercept') | |
ax.set_ylabel('Slope') | |
ax.set_zlabel('Error') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment