0
votes

I'm using Decision Tree Classifier with class weights {0:0.2, 1:0.8}, but I got an error "Class label 1 not present.", can anyone help me to fix this problem? thank you.

There is the link to my code: https://colab.research.google.com/drive/1riuGXWXKnfH8GbqlpFV1RC41gn2mMtIn?usp=sharing

# Drop dependent variable from dataframe and create the X(independent variable) matrix
x = data.drop(columns = 'BAD')
# Create dummy variables for the categorical variables - Hint: use the get_dummies() function
x = pd.get_dummies(x, drop_first = True)
# Create y(dependent varibale)
y = data['BAD']

# Split the data into training and test set
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.3, random_state = 1) 

#Defining Decision tree model with class weights class_weight={0: 0.2, 1: 0.8}
d_tree =  DecisionTreeClassifier(class_weight = {0:0.2, 1:0.8})

#fitting Decision tree model
d_tree.fit(x_train, y_train)

enter image description here

Did you understand where class label 1 is missing? - mkrieger1
Stack Overflow prefers you AVOID screenshots of code and external links to your code: meta.stackoverflow.com/questions/285551/… Please cut & paste the relevant code here. We cannot tell the order in which you're executing cells in an external notebook. Please help us help you by putting all your code in the question. - Sarah Messer