gpt4 book ai didi

python - 逻辑回归梯度下降

转载 作者:太空狗 更新时间:2023-10-30 01:05:05 26 4
gpt4 key购买 nike

<分区>

我必须使用批量梯度下降法进行逻辑回归。

import numpy as np

X = np.asarray([
[0.50],[0.75],[1.00],[1.25],[1.50],[1.75],[1.75],
[2.00],[2.25],[2.50],[2.75],[3.00],[3.25],[3.50],
[4.00],[4.25],[4.50],[4.75],[5.00],[5.50]])

y = np.asarray([0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1])

m = len(X)

def sigmoid(a):
return 1.0 / (1 + np.exp(-a))

def gradient_Descent(theta, alpha, X , y):
for i in range(0,m):
cost = ((-y) * np.log(sigmoid(X[i]))) - ((1 - y) * np.log(1 - sigmoid(X[i])))
grad = theta - alpha * (1.0/m) * (np.dot(cost,X[i]))
theta = theta - alpha * grad

gradient_Descent(0.1,0.005,X,y)

我必须这样做的方式是这样的,但我似乎无法理解如何让它工作。

Method

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com