This is the code I've used — however, for the picture below, all these spiderweb like lines keep popping up and I want to make them go away. Any suggestions? I just want a curved 3rd degree polynomial line that appropriately fits the data without the spiderwebs.
df = pd.read_csv('poly_data.csv', delimiter = ' ', names = ['x', 'y'])
x = df['x'].to_numpy()
y = df['y'].to_numpy()
model = LinearRegression()
poly = PolynomialFeatures(3)
x_poly = poly.fit_transform(x.reshape(-1, 1))
model.fit(x_poly, y.reshape(-1, 1))[![enter image description here][1]][1]
y_pred = model.predict(x_poly)
plt.scatter(x, y)
plt.scatter(x, y_pred)
plt.plot(x, model.predict(x_poly), label = '3rd order')
plt.title('Polynomial Regression')
plt.xlabel('x')
plt.ylabel('y')
plt.show()

