In [ ]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

In [ ]:
np.set_printoptions(precision=3, suppress=True)

Data Preparation

Importing a dataset


In [ ]:
dataset = pd.read_csv('Data.csv')

In [ ]:
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values

Splitting the dataset into a Training set and a Test set


In [ ]:
from sklearn.model_selection import train_test_split

In [ ]:
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)

Feature scaling


In [ ]:
from sklearn.preprocessing import StandardScaler

In [ ]:
sc_X = StandardScaler()
X_train = sc_X.fit_transform(X_train)
X_test = sc_X.transform(X_test)

In [ ]:
sc_y = StandardScaler()
y_train = sc_y.fit_transform(y_train.reshape(-1, 1))[:, 0]

Regression Model

Fitting the model to the dataset


In [ ]:
# regressor = 
regressor.fit(X, y)

Visualising the Regression results


In [ ]:
plt.scatter(X, y, color='red')
plt.plot(X, regressor.predict(X), color='blue')
plt.title('Regression Model')
plt.xlabel('Independent variable')
plt.ylabel('Dependent variable')
plt.show()

Visualising the Regression results (for higher resolution and smoother curve)


In [ ]:
X_grid = np.arange(min(X), max(X), 0.1)
X_grid = X_grid.reshape((len(X_grid), 1))
plt.scatter(X, y, color='red')
plt.plot(X_grid, regressor.predict(X_grid), color='blue')
plt.title('Regression Model')
plt.xlabel('Independent variable')
plt.ylabel('Dependent variable')
plt.show()