Python Forum

Full Version: sklearn Polynomial Features Graphing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Here is the code I have written so far:
from sklearn.preprocessing import PolynomialFeatures
x=data['True Vertical Depth']
y=data['Cum Oil']
poly.fit_transform(x[:,None])
from sklearn.pipeline import make_pipeline
poly_model = make_pipeline(PolynomialFeatures(2),LinearRegression())
poly_model.fit(x[:, np.newaxis], y)
xfit = x[:, np.newaxis]
yfit = poly_model.predict(xfit)
plt.scatter(x, y,label='data')
plt.plot(xfit, yfit,'r',label='predict')
plt.xlabel('True Vertical Depth')
plt.ylabel('Cumulative Oil Production')
plt.title('Model of True Vertical Depth Influence on Cumulative Oil Production with 2nd Order Trendline')
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.show()
And a picture of the graph:
[Image: n3eddS]

As you can see the trendline is not a trendline really. It is more of a series of swiggles. I also know that this data probably shouldn't have a trendline because there is no trend, but its the assignment. My question is about how to fix the trendline. I've tried everything and they it'll only go to a single line when it the polynomial is 1.

Thanks!