0

I have written code for polynomial regression given data in csv file, now I want to print coefficients of polynomial.How to do that?

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()

1 Answers1

0
score(X, y, sample_weight=None)

https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html#sklearn.linear_model.LinearRegression.score

Otherwise you can use statsmodels and you can read all statistical values from the OLS https://www.statsmodels.org/dev/generated/statsmodels.regression.linear_model.OLS.html

madik_atma
  • 787
  • 10
  • 28