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
%matplotlib inline | |
import matplotlib.pyplot as plt | |
# calculate the cost at -5 | |
def f(w1): | |
return sum((w1*data['speed'] - data['dist'])**2) | |
w1 = -5 | |
h = 0.1 | |
x_tan = np.linspace(-10, 0, 15) |
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
%matplotlib inline | |
import matplotlib.pyplot as plt | |
# calculate the cost for many different values | |
# of w1 using our cost function | |
costs = [] | |
for i in range(-10,11,1): | |
w1 = i | |
y_actual = data['dist'] | |
y_predict = w1*data['speed'] | |
costs.append(np.mean((y_predict - y_actual)**2)) |
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
# performs the gradient descent for linear regression | |
def calc_regression_simple(w1, frames, x_data, y_data): | |
learn_rate = 0.001 | |
ys = [] | |
for i in range(frames): | |
# get the gradient and update the parameter | |
w1_gradient = 2*np.mean(x_data*(w1*x_data - y_data)) | |
w1 = w1 - (w1_gradient*learn_rate) | |
# calculate the predictions from this new function | |
x = np.linspace(0,30) |
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
import pandas as pd | |
# load the data | |
data = pd.read_csv('cars.csv') | |
data.head() |
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
%matplotlib inline | |
import matplotlib.pyplot as plt | |
# calculate the cost at -5 | |
def f(w1): | |
return np.mean((w1*data['speed'] - data['dist'])**2) | |
w1 = -5 | |
h = 0.1 | |
x_tan = np.linspace(-10, 0, 15) |
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
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
from matplotlib import animation, rc | |
from IPython.display import HTML | |
# set ffmpeg path to installed path (for anmation) | |
plt.rcParams['animation.ffmpeg_path'] = '/usr/local/bin/ffmpeg' |
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
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
from matplotlib import animation, rc | |
from IPython.display import HTML | |
# set ffmpeg path to installed path (for anmation) | |
plt.rcParams['animation.ffmpeg_path'] = '/usr/local/bin/ffmpeg' |
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
import random | |
import numpy as np | |
def display_cave(matrix): | |
for i in range(matrix.shape[0]): | |
for j in range(matrix.shape[1]): | |
char = "#" if matrix[i][j] == WALL else "." | |
print(char, end='') | |
print() | |
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
import random | |
import numpy as np | |
def display_cave(matrix): | |
for i in range(matrix.shape[0]): | |
for j in range(matrix.shape[1]): | |
char = "#" if matrix[i][j] == WALL else "." | |
print(char, end='') | |
print() | |
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
shape = (42,42) | |
WALL = 0 | |
FLOOR = 1 | |
# set the probability of filling | |
# a wall at 40% not 50% | |
fill_prob = 0.4 | |
new_map = np.ones(shape) | |
for i in range(shape[0]): |
OlderNewer