我已经为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()
答案 0 :(得分:0)
score(X, y, sample_weight=None)
否则,您可以使用statsmodels,并且可以从OLS https://www.statsmodels.org/dev/generated/statsmodels.regression.linear_model.OLS.html读取所有统计值