import numpy as np from sklearn.linear_model import LinearRegression np.random.seed(1) X = 2 * np.random.rand(10000, 1) #模拟出10000个y y = 4 + 3 * X + np.random.randn(10000, 1) #实例化出一个线性回归器,是个对象 lin_reg = LinearRegression() lin_reg.fit(X, y) print(lin_reg.intercept_, lin_reg.coef_) # X_new = np.array([[0], [2]]) X_new = np.array([[2]]) print(lin_reg.predict(X_new))