To calculate the R-squared value using scikit-learn library in Python, you can follow these steps:
main.py37 chars2 lines
Prepare your actual and predicted values. Let's assume you have actual values in a list y_actual
and predicted values in a list y_pred
.
Calculate the R-squared value:
main.py44 chars2 lines
Here is an example demonstrating how to calculate the R-squared value using scikit-learn:
main.py253 chars12 lines
The output will be:
main.py36 chars2 lines
Note: R-squared measures the goodness of fit of a regression model. A value of 1 means a perfect fit, while a value of 0 or negative means the model does not fit the data well.
Remember to import the necessary libraries and use the r2_score()
function from sklearn.metrics
to calculate the R-squared value.
gistlibby LogSnag