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?
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.
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 λ.
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.
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.
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).
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
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With