Getting p-value, r-squared and adjusted r-squared value in python

linear_regression
machine_learning
data_science

#1

How to calculate the p value, r squared and adjusted r squared value in a linear regression model in python??

model:

regr=linear_model.LinearRegression()
regr.fit(x_train,y_train)
regr.predict(y_test)

is there any predefined function for calculating the above mentioned values apart from using OLS??


#2

Hi shubhiverma,

try below

import statsmodels.api as sm
from statsmodels.sandbox.regression.predstd import wls_prediction_std

model1=sm.OLS(y_train,x_train)

result=model1.fit()

print(result.summary())

Regards,
Tony


#3

I’ve used this approach but I want to get the p-value without using OLS. Is there another way we can find the p-value in python?


#4

@shubhiverma: You can check out my blog https://www.kaviglobal.com/linear-regression-analysis-python-quick-start-guide/ for calculating r-squared and adjusted r-squared. To calculate the pvalue, even I have used statsmodel.


#5

Thanks!