<jupyter_start><jupyter_text>Importing all the required libraries<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression<jupyter_output><empty_output><jupyter_text>Data preprocessing<jupyter_code>dataset = pd.read_csv('Salary_Data.csv')
dataset.head()
X = dataset.iloc[:,0].values
y = dataset.iloc[:, 1].values<jupyter_output><empty_output><jupyter_text>Splitting the dataset into the Training set and Test set<jupyter_code>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 1/3, random_state = 0)<jupyter_output><empty_output><jupyter_text>Fitting Simple Linear Regression to the Training set Here the regressor alogrithm is imported from scikit learn library. In genreal this can be seen as solving " y = mX + c" Fitting Simple Linear Regression to the Training set<jupyter_code>regressor = LinearRegression()<jupyter_output><empty_output><jupyter_text>From the above line we have created a object of regressor that will be used to fit a line on the training set<jupyter_code>regressor.fit(np.reshape(X_train, (-1,1)), y_train)<jupyter_output><empty_output><jupyter_text>In the above line "fit" meathod is been called from the regressor object. The fit meathod takes two input the X and y. where X is the training data and y is the training labels. Note : X_train input argument is reshaped to a column vector  Prediction  In the last step we have fit the trainiing data to the regresor object. In order to check the accuracy of the trained model it needs to be tested againset a test set. Therefore using the "predict" method of the regressor object for prediction<jupyter_code>y_pred = regressor.predict(np.reshape(X_test, (-1, 1)))
y_hat = pd.DataFrame(y_pred, columns=["calculated"])
y_act = pd.DataFrame(y_test, columns=["actual"])

output = pd.concat([y_act, y_hat], axis=1)
output<jupyter_output><empty_output><jupyter_text>The variable y_pred comtaines the predicted salary for the test set. The above table gives the calculated and actual salary of the employee. In order to have a better clarity we will plot the test and train data againest the the fit line<jupyter_code>plt.scatter(X_train, y_train, color = 'red')
plt.plot(X_train, regressor.predict(np.reshape(X_train,(-1,1))), color = 'blue')

plt.title('Salary vs Experience (Training set)')
plt.xlabel('Years of Experience')
plt.ylabel('Salary')
plt.show()<jupyter_output><empty_output><jupyter_text>In the above graph red dots are the orignal data points from the training dataset and blue line is the line that best represents the the complete data<jupyter_code>plt.scatter(X_test, y_test, color = 'red')
plt.plot(X_train, regressor.predict(np.reshape(X_train, (-1,1))), color = 'blue')

plt.title('Salary vs Experience (Test set)')
plt.xlabel('Years of Experience')
plt.ylabel('Salary')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09220338983050848, 'fraction_numerical': 0.0047457627118644066, 'mean_word_length': 6.605670103092783, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '663603', 'license': 'MIT', 'n_tokens_mistral': 981, 'n_tokens_neox': 944, 'n_words': 318, 'path': 'regression/simple-linear-regression/Simple-linear-regression.ipynb', 'repo_name': 'akki6843/data_dive', 'size': '2950'}