0% found this document useful (0 votes)
26 views1 page

Multiple Regression Codes

This document outlines the process of implementing a Multiple Linear Regression model using Python. It includes steps for importing libraries, loading a dataset, encoding categorical data, splitting the dataset into training and test sets, training the model, and predicting results. The final output displays the predicted values alongside the actual test set results.

Uploaded by

Dr Sumathy V
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views1 page

Multiple Regression Codes

This document outlines the process of implementing a Multiple Linear Regression model using Python. It includes steps for importing libraries, loading a dataset, encoding categorical data, splitting the dataset into training and test sets, training the model, and predicting results. The final output displays the predicted values alongside the actual test set results.

Uploaded by

Dr Sumathy V
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

# Multiple Linear Regression

# Importing the libraries


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

# Importing the dataset


dataset = pd.read_csv('50_Startups.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values
print(X)

# Encoding categorical data


from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder
ct = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), [3])],
remainder='passthrough')
X = np.array(ct.fit_transform(X))
print(X)

# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2,
random_state = 0)

# Training the Multiple Linear Regression model on the Training set


from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train, y_train)

# Predicting the Test set results


y_pred = regressor.predict(X_test)
np.set_printoptions(precision=2)
print(np.concatenate((y_pred.reshape(len(y_pred),1),
y_test.reshape(len(y_test),1)),1))

You might also like