# Simple Linear Regression

# Importing the libraries
import numpy as np
#import matplotlib.pyplot as plt
import pandas as pd
import pickle

# Importing the dataset
dataset = pd.read_csv(filepath_or_buffer='data/Salary_data.csv')
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
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 1/3, random_state = 0)

# Fitting Simple Linear Regression to the Training set
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train, y_train)

# Pickling the trained model:pickling is done to ensure that the model is not trained all over again and the pre trained model can be used
pickle.dump(regressor, open('model.pickle','wb'))
model = pickle.load(open('model.pickle','rb'))