In [ ]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
In [ ]:
np.set_printoptions(precision=3, suppress=True)
In [ ]:
dataset = pd.read_csv('Data.csv')
In [ ]:
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values
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)
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]
In [ ]:
# regressor =
regressor.fit(X, y)
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()
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()