To fit an Ordinary Least Squares (OLS) model using scikit-learn in Python, you can follow these steps:
main.py50 chars2 lines
Prepare your data:
Create an instance of the LinearRegression class:
main.py31 chars2 lines
main.py20 chars2 lines
After fitting the model, you can access the model's coefficients using ols_model.coef_
and the intercept using ols_model.intercept_
.
Here's an example that demonstrates the complete process:
main.py477 chars19 lines
This will output:
main.py37 chars3 lines
Remember to replace X
and y
with your actual data sets.
gistlibby LogSnag