- Best AI Text Generators for High Quality Content Writing
- Tensorflow Error on Macbook M1 Pro - NotFoundError: Graph execution error
- How does GPT-like transformers utilize only the decoder to do sequence generation?
- How to set all tensors to cuda device?
- How should I use torch.compile properly?
- How do I check if PyTorch is using the GPU?
- WARNING:tensorflow:Using a while_loop for converting cause there is no registered converter for this op
- How to use OneCycleLR?
- Error in Python script "Expected 2D array, got 1D array instead:"?
- How to save model in .pb format and then load it for inference in Tensorflow?
- Top 6 AI Logo Generator Up Until Now- Smarter Than Midjourney
- Best 9 AI Story Generator Tools
- The Top 6 AI Voice Generator Tools
- Best AI Low Code/No Code Tools for Rapid Application Development
- YOLOV8 how does it handle different image sizes
- Best AI Tools For Email Writing & Assistants
- 8 Data Science Competition Platforms Beyond Kaggle
- Data Analysis Books that You Can Buy
- Robotics Books that You Can Buy
- Data Visualization Books that You can Buy
How to print intercept and slope of a simple linear regression in Python with scikit-learn?
Written by- Aionlinecourse1177 times views
To print the intercept and slope of a simple linear regression model in Python using scikit-learn, you can use the intercept_ and coef_ attributes of the LinearRegression object. Here's an example:
Alternatively, you can also use the get_params method to print the intercept and slope, as well as other parameters of the model:
This will print a dictionary containing the parameters of the model, including the intercept and slope.
from sklearn.linear_model import LinearRegressionThis will print the intercept and slope of the fitted linear regression model.
# fit a linear regression model
X = [[1], [2], [3], [4]]
y = [1, 2, 3, 4]
model = LinearRegression().fit(X, y)
# print the intercept and slope
print("Intercept:", model.intercept_)
print("Slope:", model.coef_)
Alternatively, you can also use the get_params method to print the intercept and slope, as well as other parameters of the model:
print(model.get_params())
This will print a dictionary containing the parameters of the model, including the intercept and slope.