-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiple_regression.py
32 lines (25 loc) · 974 Bytes
/
multiple_regression.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import OneHotEncoder
from sklearn.compose import ColumnTransformer
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn import datasets
dataset = pd.read_csv('50_Startups.csv')
x = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values
# encoding
ct = ColumnTransformer(
transformers=[('encoder', OneHotEncoder(), [3])], remainder='passthrough')
x = np.array(ct.fit_transform(x))
# splitting of the dataset into training set and test set
x_train, x_test, y_train, y_test = train_test_split(
x, y, test_size=0.2, random_state=0)
# training
regressor = LinearRegression()
regressor.fit(x_train, y_train)
# predicting the test set result
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))