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?
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
)