Hi I have 2 lists of numbers and I want to get the R^2 from a regular linear regression. I think the question has been posted a lot, but I just cannot find this somewhere.
My lists:
my_y = [2,5,6,10]
my_x = [19,23,22,30]
I have tried to change it to numpy arrays and then use sklearn to regress and get what I need, but I did not succeed. I used the following code:
from sklearn.linear_model import LinearRegression
import numpy as np
my_y = np.array([2,5,6,10]).reshape(1, -1)
my_x = np.array([19,23,22,30]).reshape(1,-1)
lm = LinearRegression()
result = lm.score(my_x, my_y)
print(result)
Does anyone have a fast way to get the R^2 from doing a linear regression between those 2 variables?
My expected output from this regression is: R^2=0.930241