Created
February 22, 2019 20:24
-
-
Save Robofied/caa6eadbeb2c6ad4af194618e3bf341d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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. | |
lin_regressor.fit(X_transform,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 | |
print(y_preds) | |
#[1.34317343] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment