You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
下面是我用sklearn写的,
############# 线性回归 #############
import random
import matplotlib.pyplot as plt
import numpy as np
from sklearn.linear_model import LinearRegression
产生数据
num = 50
random.seed(0) #seed(0)调试、复现结果或者需要稳定测试的场景,因为它保证了每次执行的随机操作是相同的。
x_data = [random.uniform(0, 10) for _ in range(num)]
噪音
noise = [random.gauss(0,1) for _ in range(num)]
y_data = [0.5 * x_data[idx] + 1 + noise[idx] for idx in range(num)]
绘制散点图
fig, ax = plt.subplots()
ax.scatter(x_data, y_data,label='数据点')
ax.set_xlabel('x'); ax.set_ylabel('y')
ax.set_aspect('equal', adjustable='box') #设置坐标轴的纵横比为相等,即 X 轴和 Y 轴的单位长度相同。adjustable='box' 表示如果图形区域的大小发生变化,坐标轴的比例也会自动调整。
ax.set_xlim(0,10); ax.set_ylim(-2,8)
ax.grid()
ax.legend(fontsize=12)
大佬您好,Book1_Ch06_Python_Codes的Bk1_Ch06_12.ipynb中 #一元线性回归 slope, intercept = statistics.linear_regression(x_data, y_data 没法线性回归,我不知道是不是因为这个statistics模块更新了,删掉了这个函数
The text was updated successfully, but these errors were encountered: