- Reinforcement Learning with TensorFlow
- Sayon Dutta
- 316字
- 2021-08-27 18:51:54
Steps to solve logistic regression using gradient descent
Putting together all the building blocks we've just covered, let's try to solve a binary logistic regression with two input features.
The basic steps to compute are:
Calculate
Calculate
, the predicted output
Calculate the cost function:
Say we have two input features, that is, two dimensions and m samples dataset. Therefore, the following would be the case:
Weights
and bias
Therefore,
, and,
Calculate
(average loss over all the examples)
Calculating the derivative with regards to W1, W2 and
that is
,
and
, respectively
Modify
and
as mentioned in the preceding gradient descent section
The pseudo code of the preceding m samples dataset are:
- Initialize the value of the learning rate,
, and the number of epochs, e
- Loop over many number of epochs e' (where each time a full dataset will pass in batches)
- Initialize J (cost function) and b (bias) as 0, and for W1 and W2, you can go for random normal or xavier initialization (explained in the next section)
Here, a is , dw1 is
, dw2 is
and db is
. Each iteration contains a loop iterating over m examples.
The pseudo code for the same is given here:
w1 = xavier initialization, w2 = xavier initialization, e = 100, α = 0.0001
for j → 1 to e :
J = 0, dw1 = 0, dw2 = 0, db = 0
for i → 1 to m :
z = w1x1[i] + w2x2[i] + b
a = σ(z)
J = J - [ y[i] log a + (1-y) log (1-a) ]
dw1 = dw1 + (a-y[i]) * x1[i]
dw2 = dw2 + (a-y[i]) * x2[i]
db = db + (a-y[i])
J = J / m
dw1 = dw1 / m
dw2 = dw2 / m
db = db / m
w1 = w1 - α * dw1
w2 = w2 - α * dw2
- Canvas LMS Course Design
- 走入IBM小型機世界
- 嵌入式Linux上的C語言編程實踐
- 大數(shù)據(jù)處理平臺
- 統(tǒng)計策略搜索強化學(xué)習(xí)方法及應(yīng)用
- 大數(shù)據(jù)技術(shù)與應(yīng)用
- 數(shù)據(jù)庫系統(tǒng)原理及應(yīng)用教程(第5版)
- Linux服務(wù)與安全管理
- Machine Learning with the Elastic Stack
- Applied Data Visualization with R and ggplot2
- Photoshop CS5圖像處理入門、進階與提高
- Linux系統(tǒng)下C程序開發(fā)詳解
- 算法設(shè)計與分析
- Flash CS5二維動畫設(shè)計與制作
- Appcelerator Titanium Smartphone App Development Cookbook(Second Edition)