Multivariate Linear Regression in Python – Step 5.) Predict Results with Multivariate Linear Regression Model

with No Comments

#Import libraries

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

#Import data
dataset = pd.read_csv(‘multivariate_data.csv’)
x = dataset.iloc[:,:-1].values
y =dataset.iloc[:,4].values

#Encode Categorical Data using LabelEncoder and OneHotEncoder
from sklearn.preprocessing import LabelEncoder,OneHotEncoder
onehotencoder=OneHotEncoder(categorical_features =[3])

#Remove Dummy Variable Trap
x=x[:, 1:]

#splitting training set and testing set
from sklearn.cross_validation import train_test_split
xtrain, xtest, ytrain, ytest =train_test_split(x,y,test_size=0.2)

# Training the Multivariate Linear Regression Model
from sklearn.linear_model import LinearRegression
regressor = LinearRegression(), ytrain)

# Predicting the Test set results
y_prediction= regressor.predict(xtest)

Leave a Reply