The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.   The best answers are voted up and moderated by our team

# Logistic Regression

0
1

I know it may be a more advanced topic, but please provide an explanation or a link to where myself and others may go to understand the linear algebra and operations of the following code:

from sklearn import linear_model
import scipy.stats as stat
class LogisticRegression_with_p_values:

def __init__(self,*args,**kwargs):
self.model = linear_model.Logisticregression(*args,**kwargs)

def fit(self,X,y):
self.model.fit(X,y)
denom = (2.0 * (1.0 + np.cosh(self.model.decision_function(X))))
denom = np.tile(denom,(X.shape,1)).T
F_ij = np.dot((X / denom).T,X)
Cramer_Rao = np.linalg.inv(F_ij)
sigma_estimates = np.sqrt(np.diagonal(Cramer_Rao))
z_scores = self.model.coef_ / sigma_estimates
p_values = [stat.norm.sf(abs(x)) * 2 for x in z_scores]
self.coef_ = self.model.coef_
self.intercept_ = self.model.intercept_
self.p_values = p_values

(taken from a video by 365 Data Science about Logistic Regression and how to add p_values to the coefficient (beta estimates) once you fit a model using Sklearn).