0

I am doing a ML project and I need plotting for example data, so when I write this code

from sklearn.preprocessing import PolynomialFeatures
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
import pandas as pd
from sklearn.model_selection import train_test_split


df = pd.read_csv(
    r'/home/alibustami/Desktop/test data for polynomial regression.csv')
x = df.iloc[1:, 0:1].values
y = df.iloc[1:, 1].values
x_train, x_test, y_train, y_test = train_test_split(
    x, y, test_size=0.3, random_state=0)


polynom = PolynomialFeatures(degree=2)
x_poly = polynom.fit_transform(x_train)
polyReg = LinearRegression()
polyReg.fit(x_poly, y_train)

plt.scatter(x_train, y_train, color='green')
plt.plot(x_train, polyReg.predict(
    polynom.fit_transform(x_train)), color='blue')
plt.show()
print(x_poly)

and I get this output instead of one line, Help, please :) Output

0 Answers0