#Salary Prediction based on number of years of experience
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# import the dataset
dataset = pd.read_csv('Salary-Data.csv')
x = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 1].values

# spliting the dataset into trainig and testing

x_train, x_test, y_train, y_test = train_test_split(
    x, y, test_size=0.2, random_state=0)

# design the model
regressor = LinearRegression()
regressor.fit(x_train, y_train)

# prediction
y_pred = regressor.predict(x_test)

# visualize data
plt.scatter(x_train, y_train, color='red')
plt.plot(x_train, regressor.predict(x_train), color='blue')
plt.title('salary vs year of experience')
plt.xlabel('year of experience')
plt.ylabel('salary')
plt.show()

plt.scatter(x_test, y_test, color='red')
plt.plot(x_train, regressor.predict(x_train), color='blue')
plt.title('salary vs year of experience')
plt.xlabel('year of experience')
plt.ylabel('salary')
plt.show()

5ef6253279c1788d925e7a5dc59c22edb6e18b5f
<mask token>

<mask token>
regressor.fit(x_train, y_train)
<mask token>
plt.scatter(x_train, y_train, color='red')
plt.plot(x_train, regressor.predict(x_train), color='blue')
plt.title('salary vs year of experience')
plt.xlabel('year of experience')
plt.ylabel('salary')
plt.show()
plt.scatter(x_test, y_test, color='red')
plt.plot(x_train, regressor.predict(x_train), color='blue')
plt.title('salary vs year of experience')
plt.xlabel('year of experience')
plt.ylabel('salary')
plt.show()

<mask token>
dataset = pd.read_csv('Salary-Data.csv')
x = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 1].values
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2,
    random_state=0)
regressor = LinearRegression()
regressor.fit(x_train, y_train)
y_pred = regressor.predict(x_test)
plt.scatter(x_train, y_train, color='red')
plt.plot(x_train, regressor.predict(x_train), color='blue')
plt.title('salary vs year of experience')
plt.xlabel('year of experience')
plt.ylabel('salary')
plt.show()
plt.scatter(x_test, y_test, color='red')
plt.plot(x_train, regressor.predict(x_train), color='blue')
plt.title('salary vs year of experience')
plt.xlabel('year of experience')
plt.ylabel('salary')
plt.show()

from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
dataset = pd.read_csv('Salary-Data.csv')
x = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 1].values
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2,
    random_state=0)
regressor = LinearRegression()
regressor.fit(x_train, y_train)
y_pred = regressor.predict(x_test)
plt.scatter(x_train, y_train, color='red')
plt.plot(x_train, regressor.predict(x_train), color='blue')
plt.title('salary vs year of experience')
plt.xlabel('year of experience')
plt.ylabel('salary')
plt.show()
plt.scatter(x_test, y_test, color='red')
plt.plot(x_train, regressor.predict(x_train), color='blue')
plt.title('salary vs year of experience')
plt.xlabel('year of experience')
plt.ylabel('salary')
plt.show()

#Salary Prediction based on number of years of experience
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# import the dataset
dataset = pd.read_csv('Salary-Data.csv')
x = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 1].values

# spliting the dataset into trainig and testing

x_train, x_test, y_train, y_test = train_test_split(
    x, y, test_size=0.2, random_state=0)

# design the model
regressor = LinearRegression()
regressor.fit(x_train, y_train)

# prediction
y_pred = regressor.predict(x_test)

# visualize data
plt.scatter(x_train, y_train, color='red')
plt.plot(x_train, regressor.predict(x_train), color='blue')
plt.title('salary vs year of experience')
plt.xlabel('year of experience')
plt.ylabel('salary')
plt.show()

plt.scatter(x_test, y_test, color='red')
plt.plot(x_train, regressor.predict(x_train), color='blue')
plt.title('salary vs year of experience')
plt.xlabel('year of experience')
plt.ylabel('salary')
plt.show()
