I have a dataframe of X values and one with the y values in what I think is the proper format. I took the single feature y and converted it to dummies so it's binary and is m rows by n features.

from sklearn.model_selection import train_test_split

X = df.drop('target',axis=1)
y = pd.get_dummies(df['target'], sparse=True, drop_first=True)

X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=99, train_size=0.60

I've been trying to figure out how exactly the data should look from the documentation but am not having much luck.

I first tried the following:

import skmultilearn.problem_transform import BinaryRelevance
from sklearn.naive_bayes import GaussianNB

classifier = BinaryRelevance(GaussianNB())
classifier.fit(X_train, y_train)

where X, y train sets are pandas dataframes. This results in the following error:

TypeError: no suppoerted conversion for types: (dytype('O'),)

Then I converted to matrices:

X_train = X_train.asmatrix()
y_train = y_train.asmatrix()

I received the same error. Then I tried

X_train = np.matrix(X_train)
y_train = np.matrix(y_train)

Same error again. Is there an easy way to go from dataframe to proper format for skmultilearn models?


Some of the features were categorical, so they had to be converted to integers.

Then, I ran this to get the data in the right format:

import scipy.sparse as sp
X_train = sp.csr_matrix(X_train)
y_train = sp.csr_matrix(y_train)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.