Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#Import required modules
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
#Some random values for input to a model
X_train = [[1,4],[3,5]]
Y_train = [1,2]
X_test = [[1,5]]
#Create a Linear Regressor
lin_regressor = LinearRegression()
#Pass the order of your polynomial here
poly = PolynomialFeatures(degree = 2)
#Convert to be used further to linear regression.
#If we have two variables a and b, then degree 2 and using fit_transform would give us 1,a, b, a2, ab and b2.
X_transform = poly.fit_transform(X_train)
X_test_ = poly.fit_transform(X_test)
#This finds the coefficient of polynomial regression. This is training part of the algorithm.,Y_train)
LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False)
#Predict the value on the value passed
y_preds = lin_regressor.predict(X_test_)
#Printing the predicted value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.