# codind:utf-8
from sklearn.linear_model import SGDRegressor,LinearRegression,Ridge
from sklearn.preprocessing import  PolynomialFeatures
import numpy as np
import matplotlib.pyplot as plt

x = np.arange(-10,10,0.1).reshape(-1,1)
y = np.sin(x) + np.random.randn(len(x),1)
# y = y.reshape(-1)
poly_reg =PolynomialFeatures(degree=9)
X_ploy =poly_reg.fit_transform(x)
print(X_ploy.shape)
lin_reg=LinearRegression()
lin_reg.fit(X_ploy,y)

y_pred = lin_reg.predict(X_ploy)

plt.scatter(x,y,s=4)
plt.plot(x,y_pred,'r*')
plt.show()

 sklearn进行拟合

 

相关文章:

  • 2022-01-05
  • 2022-12-23
  • 2021-06-24
  • 2022-12-23
  • 2021-09-16
  • 2021-05-14
  • 2022-01-29
  • 2021-12-28
猜你喜欢
  • 2021-05-31
  • 2022-12-23
  • 2021-05-13
  • 2021-10-31
  • 2022-01-15
  • 2021-04-22
相关资源
相似解决方案