-1

I am trying to create multinomial logistic regression, I have never done this. I am trying to follow the tutorial:
Multinomial Logistic Regression With Python.

I am trying to take the data, and predict gambling (binary) from the alcohol dependence (binary) using sex and age as covariates.

So far I have:

# define dataset
X = data2["SEX"] + data2["AGE"] + data2["alcdep"]+data2["PRS"]
y = data2["Gambling"]
# summarize the dataset
print(X.shape, y.shape)
model.fit(X, y)

But I keep getting errors:

ValueError: Expected 2D array, got 1D array instead:

I also don't know if what I am doing is correct or the steps forward from here.

Here is the dummy data (ignore the yes and zeroes).

data = {
    'IID': {0: 'Yale_0001', 1: 'Yale_0004', 2: 'Yale_0006', 3: 'Yale_0007', 4: 'Yale_0008'},
    'SEX': {0: 2, 1: 1, 2: 2, 3: 1, 4: 1},
    'AGE': {0: 27, 1: 39, 2: 41, 3: 45, 4: 44},
    'alcdep': {0: 2, 1: 2, 2: 2, 3: 1, 4: 1},
    'Gambling': {0: 1, 1: 1, 2: 2, 3: 1, 4: 2},
    'Zero': {0: 0, 1: 0, 2: 0, 3: 1, 4: 0},
    'Yes': {0: 'Yes', 1: 'Yes', 2: 'Yes', 3: 'Yes', 4: 'Yes'},
    'PRS': {0: 0.053486584299999994, 1: 0.0304387435, 2: 0.00917773968, 3: 0.016352741100000002, 4: 7.433452840000001e-05}
}

1 Answers1

0

Assuming data2 = pd.DataFrame(data), you're adding each of the individual series instead of selecting them. It's resulting in X looking like this:

>>> X
0    31.053487
1    42.030439
2    45.009178
3    47.016353
4    46.000074

Instead, you should write X = data2[["SEX", "AGE", "alcdep", "PRS"]], so that you get:

>>> X
   SEX  AGE  alcdep       PRS
0    2   27       2  0.053487
1    1   39       2  0.030439
2    2   41       2  0.009178
3    1   45       1  0.016353
4    1   44       1  0.000074

I recommend you take a look at the pandas User Guide section on data selection to get started on DataFrame manipulation.

tlgs
  • 643
  • 6
  • 16