Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the weight vector in Logistic Regression?

I have a X feature matrix and a y label matrix and I am using binary logistic regression how can I get the weight vector w given matrix X feature and Y label matrix. I am a bit confused as to how achieve this within sklean.

How do I solve the problem?

like image 535
bluemoon718 Avatar asked Nov 11 '17 21:11

bluemoon718


People also ask

What does the weights mean in logistic regression?

The interpretation of the weights in logistic regression differs from the interpretation of the weights in linear regression, since the outcome in logistic regression is a probability between 0 and 1. The weights do not influence the probability linearly any longer.

What is the weight vector?

A weight of the representation V is a linear functional λ such that the corresponding weight space is nonzero. Nonzero elements of the weight space are called weight vectors. That is to say, a weight vector is a simultaneous eigenvector for the action of the elements of. , with the corresponding eigenvalues given by λ.

How are weights updated in logistic regression?

The predict method simply plugs in the value of the weights into the logistic model equation and returns the result. This returned value is the required probability. The model is trained for 300 epochs or iterations. The partial derivatives are calculated at each iterations and the weights are updated.

How weights are calculated in linear regression?

The data are weighted by the reciprocal of this variable raised to a power. The regression equation is calculated for each of a specified range of power values and indicates the power that maximizes the log-likelihood function. This is used in conjunction with the weight variable to compute weights.

Does logistic regression have b weights?

The Logistic Curve The value of a yields P when X is zero, and b adjusts how quickly the probability changes with changing X a single unit (we can have standardized and unstandardized b weights in logistic regression, just as in ordinary linear regression).


1 Answers

If i understand correctly you are looking for the coef_ attribute:

lr = LogisticRegression(C=1e5)
lr.fit(X, Y)

print(lr.coef_) # returns a matrix of weights (coefficients)

The shape of coef_ attribute should be: (# of classes, # of features)

If you also need an intercept (AKA bias) column, then use this:

np.hstack((clf.intercept_[:,None], clf.coef_))

this will give you an array of shape: (n_classes, n_features + 1)

like image 112
MaxU - stop WAR against UA Avatar answered Sep 22 '22 13:09

MaxU - stop WAR against UA