0% found this document useful (0 votes)
31 views2 pages

Python Codes

The document provides a simple Python code to construct a Linear Regression Model using the sklearn library. It includes steps for importing data from an Excel file, defining independent and dependent variables, fitting the model, and extracting the R2 value and coefficients. Key portions of the code that require modification are highlighted.

Uploaded by

ayan.sj.01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Python Codes

The document provides a simple Python code to construct a Linear Regression Model using the sklearn library. It includes steps for importing data from an Excel file, defining independent and dependent variables, fitting the model, and extracting the R2 value and coefficients. Key portions of the code that require modification are highlighted.

Uploaded by

ayan.sj.01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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_

You might also like