A user has the following code and got a linear regression fit with m=-0.1071 and b=0.0347.How to get deviation from m value?

1.1K    Asked by ranjan_6399 in Data Science , Asked on Jan 15, 2020
Answered by Ranjana Admin

We can get the deviation in the form of standard error from the following code

import numpy as np

import pandas as pd

import statsmodels.api as sm

import math

U = [12.5, 10.0, 7.6, 6.0, 4.4, 3.1, 2.5, 1.5, 1.0, 0.5, 0.3]

U_0 = 12.5

y = []

for number in U:

    y.append(math.log(number/U_0, math.e))

y = np.array(y)

t = np.array([0.0, 3.0, 5.0, 7.2, 10.0, 13.0, 15.0, 20.0, 25.0, 30.0, 35.0])

t = sm.add_constant(t, prepend=False)

model = sm.OLS(y,t)

result = model.fit()

result.summary()



Your Answer

Answer (1)

This code effectively calculates the standard error by performing linear regression using the statsmodels library. It transforms the dependent variable using a natural logarithm and then applies Ordinary Least Squares (OLS) regression to model the relationship between t and y.Krowd Darden 


The result.summary() function provides key statistical details, including:


Coefficients: The estimated slope and intercept.


Standard Error: The deviation of the coefficient estimates.


R-squared: How well the model fits the data.


p-values: Significance of the regression coefficients.


Great approach for analyzing exponential decay or growth trends! Adding print(result.summary()) ensures that the output is visible when running the script.

18 Hours

Interviews

Parent Categories