import numpy as np" Y4 `; P: ^4 K* n5 K
from sklearn.linear_model import LinearRegression" G6 O! U U, W/ M; P* H5 x
import matplotlib.pyplot as plt5 v5 w5 O `8 H, A9 g) R) V
3 M$ j& s. }: h! m: l$ R# 生成一些示例数据 ! e1 L0 {- w0 y* w4 mnp.random.seed(0)8 }, T0 d$ @2 H
X = 2 * np.random.rand(100, 1) 2 d; b% v$ a. o$ Ey = 3 + 4 * X + np.random.randn(100, 1)# ?; x. u+ O% C- O6 ~
9 F' }! ?: I; @$ i
# 创建线性回归模型 ' ]* K$ s! V* zmodel = LinearRegression()5 v; T& y( b: v1 L6 u, l