import matplotlib.pyplot as plt
from matplotlib import pyplot as plt
import numpy as np
import torch
import pandas as pd
%matplotlib inline
%config InlineBackend.figure_format = ‘svg’
绘制 loss 曲线
train_loss_results = [] # 将每轮的loss记录在此列表中,为后续画loss曲线提供数据
points = np.genfromtxt(‘l3_data.csv’,delimiter = ‘,’)
plt.scatter(points[:,0],points[:,1],c = ‘’,edgecolors = ‘b’,s = 15)
plt.show()
y = wx + b
def compute_error_for_line_given_points(b, w, points):
“”"
计算给定超参数[w,b]的误差值
“”"
totalError = 0
for i in range(0, len(points)):
x = points[i, 0]
y = points[i, 1]
totalError += (y - (w * x + b)) ** 2
return totalError / float(len(points))