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
def train(theta0, x, y, iteration, alpha=0.01): | |
""" | |
This function find the best model parameters using gradient descent method | |
Parameters | |
---------- | |
theta0 : float | |
Model parameters | |
x : float | |
Training data |
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
# Importing matplotlib | |
import matplotlib.pyplot as plt | |
import matplotlib as mpl | |
# For plotting in jupyter notebook | |
%matplotlib inline | |
# Import more packages to generate data | |
import numpy as np |
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
# Let's set give data to our plot | |
x1 = np.arange(-3 * np.pi, 3 * np.pi, np.pi/6) | |
x2 = np.arange(-3 * np.pi, 3 * np.pi, np.pi/3) | |
y1 = np.sin(x1) | |
y2 = np.cos(x2) | |
plt.plot(x1, y1, label='sin') |
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
# Let's add more parameters to our plot | |
plt.plot(x1, y1, label='sin', color='teal', marker='v') | |
# Add title | |
plt.title('Simple plot') | |
# Add label | |
plt.xlabel('X') | |
plt.ylabel('Y') |
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
# Let's add more parameters to our plot | |
plt.plot(x1, y1, label='sin', linestyle=':', | |
color='teal', marker='$\U0001F609$', ms=15) | |
# Add title | |
plt.title('Simple plot') | |
# Add label | |
plt.xlabel('X') |
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
# Simple subplot | |
plt.subplot(1, 2, 1) | |
plt.plot(x1, y1) | |
plt.title('Plot 1') | |
plt.subplot(1, 2, 2) | |
plt.plot(x2, y2) | |
plt.title('Plot 2') |
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
# Subplot with | |
plt.subplot(2, 1, 1) | |
plt.plot(x1, y1) | |
plt.title('Plot 1') | |
plt.subplot(2, 2, 3) | |
plt.plot(x2, y2) | |
plt.title('Plot 2') |
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
# Let's add a text to a plot with specific color and make it bold and italic | |
arrowprops = dict(arrowstyle="->", | |
connectionstyle="arc3,rad=.3", # Specify the connection style | |
color='red', # Set the color | |
lw=1 # Set the width of line | |
) | |
plt.plot(x2, y2) | |
plt.annotate('Local max', # text to annotate |
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
# Let's plot a heart | |
theta = np.linspace(0, 2 * np.pi, 100) | |
x = 16 * ( np.sin(theta) ** 3 ) | |
y = 13 * np.cos(theta) - 5* np.cos(2*theta) - 2 * np.cos(3*theta) - np.cos(4*theta) | |
# font | |
hfont = {'fontname':'Apple Chancery', | |
'fontsize': 14, | |
'color': 'w'} |
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
plt.figure(figsize=(8, 5), # size | |
dpi=200, # dpi | |
facecolor='yellow' # color of background | |
) | |
plt.plot(x1, y1) | |
OlderNewer