Polynomial Regression in Python – Step 4.) Predict Results with Polynomial Regression Model

with No Comments

# Import the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Import the CSV Data
dataset = pd.read_csv(‘Poly_Data.csv’)
X = dataset.iloc[:, 1:2].values
y = dataset.iloc[:, 2].values

# Split the dataset into Training set and Test set
from sklearn.cross_validation import train_test_split
xtrain, xtest, ytrain, ytest = train_test_split(X, y, test_size = 0.2)

# Training Polynomial Regression Model
from sklearn.preprocessing import PolynomialFeatures
poly_reg = PolynomialFeatures(degree = 4)
X_poly = poly_reg.fit_transform(xtrain)
poly_reg.fit(X_poly, ytrain)
lin_reg = LinearRegression()
lin_reg.fit(X_poly, ytrain)

# Predict Result with Polynomial Regression


Leave a Reply