【问题标题】:Coefficients of Polynomial in polynomial regression多项式回归中的多项式系数
【发布时间】:2019-01-18 19:51:23
【问题描述】:

我已经为给定 csv 文件中的数据编写了多项式回归的代码,现在我想打印多项式的系数。如何做到这一点?

import numpy as np
import pandas as pd

df=pd.read_csv('square.csv')

x=df.iloc[:,0:1].values
y=df.iloc[:,1].values

from sklearn.preprocessing import PolynomialFeatures
poly=PolynomialFeatures(degree=5)
poly_x=poly.fit_transform(x)

from sklearn.linear_model import LinearRegression
regressor=LinearRegression()
regressor.fit(poly_x,y)

import matplotlib.pyplot as plt

plt.scatter(x, y, color = 'blue')
plt.plot(x,regressor.predict(poly.fit_transform(x)),color='red')
plt.show()

【问题讨论】:

    标签: python


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2017-12-08
    • 2020-01-14
    • 2018-09-03
    • 2011-04-23
    • 2019-01-24
    • 2021-06-03
    • 2018-12-19
    • 1970-01-01
    相关资源
    最近更新 更多