Linear data regr.
Create
'Position_Salaries' Data
set. Build a linear
regression
model by identifying
independent and target
variable. Split the
variables into training
and testing sets. then
divide the training and
testing
sets into a 7:3 ratio,
respectively and print
them. Build a simple
linear
regression model.
import numpy as np
import pandas as pd
from
sklearn.model_selection
import train_test_split
from
sklearn.linear_model
import
LinearRegression
data = {'Position': [1, 2,
3, 4, 5],
'Salary': [45000,
50000, 60000, 80000,
110000]}
df =
pd.DataFrame(data)
X = df[['Position']]
y = df['Salary']
X_train, X_test, y_train,
y_test =
train_test_split(X, y,
test_size=0.3,
random_state=42)
model =
LinearRegression()
model.fit(X_train,
y_train)