The process for creating a mask suitable for multinomial logistic regression with shapes x (n, m) and y (n) involves the following steps:
Identify the number of classes that are present in the y vector.
Create an empty mask of shape (n, c), where c represents the number of classes.
Iterate through the y vector and set the corresponding row of the mask to 1 for each class label.
Use the mask as the target variable in the multinomial logistic regression model.
Here is an example implementation in Python:
import numpy as np
# example input data
n = 100
m = 3
c = 4
x = np.random.rand(n, m)
y = np.random.randint(c, size=n)
# create mask
mask = np.zeros((n, c))
mask[np.arange(n), y] = 1
# fit multinomial logistic regression model
from sklearn.linear_model import LogisticRegression
model = LogisticRegression(multi_class='multinomial')
model.fit(x, mask)
Asked: 2021-07-15 11:00:00 +0000
Seen: 10 times
Last updated: Jan 27 '22