Ask Your Question
2

What is the process for creating a mask suitable for multinomial logistic regression with shapes x (n, m) and y (n,)?

asked 2021-07-15 11:00:00 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-01-27 19:00:00 +0000

woof gravatar image

The process for creating a mask suitable for multinomial logistic regression with shapes x (n, m) and y (n) involves the following steps:

  1. Identify the number of classes that are present in the y vector.

  2. Create an empty mask of shape (n, c), where c represents the number of classes.

  3. Iterate through the y vector and set the corresponding row of the mask to 1 for each class label.

  4. 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)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-07-15 11:00:00 +0000

Seen: 10 times

Last updated: Jan 27 '22