text_plain_output_1.png
from sklearn.linear_model import LinearRegression

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

df = pd.read_csv('/kaggle/input/salary-dataset-simple-linear-regression/Salary_dataset.csv')

df.columns

years_exp = df.YearsExperience.values
years_exp

salary = df.Salary.values
salary

x = years_exp
y = salary

plt.plot

x = x.reshape(-1, 1)
x

plt.plot

lr = LinearRegression()
lr.fit(x_train, y_train)

y_predict = lr.predict([[1.2], [3.3]])
y_predict

lr.score(x_test, y_test) * 100

y_predict = lr.predict(x_test)
y_predict

plt.scatter(x, y, color='blue')
plt.scatter(x_test, y_predict, color='red')
plt.xlabel('YearsExperience')
plt.ylabel('Salary')
plt.plot