No title

BATHULA PRAVEEN (BP)
0

 


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

dataset.head()


           YearsExperience             Salary


0          1.1                               39343.0


1            1.3                        46205.0


2            1.5                         37731.0


3                 2.0                435250


4          2.2                      39891.0




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)




from sklearn.linear_model import LinearRegression

regressor = LinearRegression()

regressor.fit(X_train, y_train)




Out[8]:


LinearRegression()


In [9]:


# Predicting the Test set results

y_pred = regressor.predict(X_ test)

plt.scatter(X_test, y_test, color = 'red’)

plt.plot(X_train, regressor.predict(X_train), color = 'blue’)

plt.title('Salary vs Experience (Test set)')

plt.xlabel( Years of Experience')

plt.ylabel( Salary")

plt.show()





Post a Comment

0Comments

Post a Comment (0)