Professional Documents
Culture Documents
Simple Linear Regression Lab II
Simple Linear Regression Lab II
Simple Linear Regression Lab II
import numpy as np
import pandas as pd
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values
# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
regressor = LinearRegression()
regressor.fit(X_train, y_train)
# x-axis experience and y-axis is salary, here observation point shown as red
# here y coordinate will be predictions from x_train, and color blue for observational points
# Title of graph
plt.xlabel('Years of Experience')
# x-axis lable
plt.ylabel('Salary')
# y-axis lable
plt.show()
# here real values are red and predicted values are blue
# Visualising the Test set results
plt.scatter(X_test, y_test, color = 'red')
plt.xlabel('Years of Experience')
plt.ylabel('Salary')
plt.show()
# here blue line is same as previous graph but red points are from test set