首页 > 其他分享 >线性回归的梯度下降

线性回归的梯度下降

时间:2023-03-21 15:57:40浏览次数:34  
标签:02 03 dj 梯度 回归 db 线性 dw

线性回归的梯度下降

问题陈述:

让我们使用与之前相同的两个数据点 - 1000平方英尺的房子以300,000美元的价格出售,而2000平方英尺的房屋以500,000美元的价格出售。

import math, copy
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('./deeplearning.mplstyle')
from lab_utils_uni import plt_house_x, plt_contour_wgrad, plt_divergence, plt_gradients
# Load our data set
x_train = np.array([1.0, 2.0])   #features
y_train = np.array([300.0, 500.0])   #target value

成本函数:

#Function to calculate the cost
def compute_cost(x, y, w, b):
   
    m = x.shape[0] 
    cost = 0
    
    for i in range(m):
        f_wb = w * x[i] + b
        cost = cost + (f_wb - y[i])**2
    total_cost = 1 / (2 * m) * cost

    return total_cost

梯度下降摘要

线性模型,在线性回归中,您可以利用输入的训练数据来拟合参数

标签:02,03,dj,梯度,回归,db,线性,dw
From: https://www.cnblogs.com/fyuan0206/p/17240251.html

相关文章