Simple Python code to construct a Linear Regression Model and estimate the Coefficients
(The portions of the code that need to be changed are highlighted in yellow)
# Import the required packages:
import pandas as pd
from sklearn.linear_model import LinearRegression
# Read the Excel file:
data = pd.read_excel("[Link]")
# Check the first 5 data:
[Link]()
# Check the last 5 data:
# [Link]()
# Description of the data in the DataFrame:
[Link]()
# Define independent variables as "x" by dropping other columns:
x = [Link](["CATHETER LENGTH"], axis = 1)
# If multiple columns (say "Column 4" and "Column 5") need to be dropped, then
# x = [Link](["Column 4", "Column 5"], axis =1)
# Check the first 5 data:
[Link]()
# Extract the dependent variable "y" from data:
y = data["CATHETER LENGTH"]
# Define a linear regression model:
model = LinearRegression()
# Fit the defined model by the given independent (x) and dependent (y) variables:
[Link](x,y)
# Find the R2 value of the model:
[Link](x,y)
# Check the intercept / first coefficient (theta_0):
model.intercept_
# Check other coefficients (theta_1 etc):
model.coef_