Assume you have the following artificial dataset
import pandas as pd import numpy as np df = pd.DataFrame(np.random.randn(100, 4), columns=list('ABCD')) df['sex'] = [np.random.choice(['male', 'female']) for x in range(len(df))] df['weight'] = [np.random.choice(['underweight', 'normal', 'overweight', 'obese']) for x in range(len(df)) ]
This produce the following artificial dataset
df.head() Out: A B C D sex weight 0 0.955136 0.802256 0.317182 -0.708615 female normal 1 0.463615 -0.860053 -0.136408 -0.892888 male obese 2 -0.855532 -0.181905 -1.175605 1.396793 female overweight 3 -1.236216 -1.329982 0.531241 2.064822 male underweight 4 -0.970420 -0.481791 -0.995313 0.672131 male obese
I am trying to know both the sex and the weigh based on the value of the features A,B,C,D. I learned that this a multi-label classification problem and there is a nice python library that should help (e.g. scikit-multilearn ). However I do not know how this is achieved. Can someone show me how I could train a model and test its accuracy on this artificial dataset? Specifically: 1. Assuming that A,B,C,D are the feature and sex and weight are the label, how to create a test and training sets? The following will not work
X=df[list('ABCD')] y=[['sex','weight']] X_train, X_test, y_train, y_test = train_test_split(X, y)
- How to you train and test the model?