├── README.md ├── Salary_Data.csv └── Simple_Linear_Regression.py /README.md: -------------------------------------------------------------------------------- 1 | # Simple-Linear-Regression 2 | 3 | A simple python program that implements Linear Regression on a sample dataset. The programuses sklearn.linear_model from the scikit-learn library to import the class LinearRegression. The object of the class is declared and is fitted with the X_Train and Y_Train data. 4 | 5 | Y_Pred stores the predicted values of X_Test 6 | 7 | A graph is plotted using the matplotlib.pyplot to visually represent the Linear Regression model. 8 | -------------------------------------------------------------------------------- /Salary_Data.csv: -------------------------------------------------------------------------------- 1 | YearsExperience,Salary 2 | 1.1,39343.00 3 | 1.3,46205.00 4 | 1.5,37731.00 5 | 2.0,43525.00 6 | 2.2,39891.00 7 | 2.9,56642.00 8 | 3.0,60150.00 9 | 3.2,54445.00 10 | 3.2,64445.00 11 | 3.7,57189.00 12 | 3.9,63218.00 13 | 4.0,55794.00 14 | 4.0,56957.00 15 | 4.1,57081.00 16 | 4.5,61111.00 17 | 4.9,67938.00 18 | 5.1,66029.00 19 | 5.3,83088.00 20 | 5.9,81363.00 21 | 6.0,93940.00 22 | 6.8,91738.00 23 | 7.1,98273.00 24 | 7.9,101302.00 25 | 8.2,113812.00 26 | 8.7,109431.00 27 | 9.0,105582.00 28 | 9.5,116969.00 29 | 9.6,112635.00 30 | 10.3,122391.00 31 | 10.5,121872.00 32 | -------------------------------------------------------------------------------- /Simple_Linear_Regression.py: -------------------------------------------------------------------------------- 1 | # Simple Linear Regression 2 | # Importing the libraries 3 | 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the datasets 9 | 10 | datasets = pd.read_csv('Salary_Data.csv') 11 | 12 | X = datasets.iloc[:, :-1].values 13 | Y = datasets.iloc[:, 1].values 14 | 15 | # Splitting the dataset into the Training set and Test set 16 | 17 | from sklearn.model_selection import train_test_split 18 | X_Train, X_Test, Y_Train, Y_Test = train_test_split(X, Y, test_size = 1/3, random_state = 0) 19 | 20 | # Fitting Simple Linear Regression to the training set 21 | 22 | from sklearn.linear_model import LinearRegression 23 | regressor = LinearRegression() 24 | regressor.fit(X_Train, Y_Train) 25 | 26 | # Predicting the Test set result  27 | 28 | Y_Pred = regressor.predict(X_Test) 29 | 30 | 31 | # Visualising the Training set results 32 | 33 | plt.scatter(X_Train, Y_Train, color = 'red') 34 | plt.plot(X_Train, regressor.predict(X_Train), color = 'blue') 35 | plt.title('Salary vs Experience (Training Set)') 36 | plt.xlabel('Years of experience') 37 | plt.ylabel('Salary') 38 | plt.show() 39 | 40 | # Visualising the Test set results 41 | 42 | plt.scatter(X_Test, Y_Test, color = 'red') 43 | plt.plot(X_Train, regressor.predict(X_Train), color = 'blue') 44 | plt.title('Salary vs Experience (Training Set)') 45 | plt.xlabel('Years of experience') 46 | plt.ylabel('Salary') 47 | plt.show() --------------------------------------------------------------------------------