赞
踩
Date:2018.3.4
Example:
Given
Parameters:
Output: First consider the linear regression:
Date:2018.3.5
Loss(error) function:
Usually we use the square loss function:
If
So, if y is 0, we try to make
Coss function:
Loss function measures how well you’re doing on a single training example. However, coss function measures how well you’re doing an entire training set.
Want to find
Repeat:
calculus and derivatives
skip
The slope of the function
skip
Given a function:
u=bc
v=a+u
J=3v
a forward path and a backward pass(back propagation)
chain rule
Date:2018.3.6
The model is:
We have only two features
z = w1*x1+w2*x2+b
a = y^ = sigmoid(z)
L(a,y)
w1:= w1 - \alpha dw1
w2:= w2 - \alpha dw2
b := b - \alpha db
The cost function:
This is only one loop for gradient descent,actually,you need more steps to use gradient descent, if the data has a lot of features,you may need 3 for loops, one for gradient descent,one for all items, one for all features, so it is too slow for the algorithm. The vectorization can accelerate the speed.
Vectorization is the art of getting rid of explicit for loops in your code.
Non-vectorizated:
z=0
for i in range(n_x):
z+=w[i]*x[i]
z+=b
Vectorizated:
z = np.dot(w,x)+b
Whenever possible, avoid explicit for-loops.
Given
u = np.zeros((n,1))
for i in range(n):
u[i]=math.exp(v[i])
Vectorization:
import numpy as np
u = np.exp(v)
In logistic regression derivatives:
Date:2018.3.7
import numpy as np
A = np.array([[1,2,3],[4,5,6],[7,8,9]])
cal = A.sum(axis = 0)
percentage = 100*A/cal.reshape(1,3)#reshape(),改成1行3列的数组
print(percentage)
Usually use a = np.random.randn(5,1)
,not use a = np.random.randn(5)
a = np.random.randn(5) #a.shape = (5,),rank 1 array
a = np.random.randn(5,1)#a.shape = (5,1),5 by 1 column vector
a = np.random.randn(1,5)#a.shape = (1,5),1 by 5 row vector
you can use assert(a.shape==(5,1))
to ensure you get a column vector otherwise a rank 1 array. Use a.reshape(5,1)
if you get a rank 1 array.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。