Create the feature matrix and target vector
X = df[“Project description”]
y = df[“category”]
create LabelEncoder object
le = LabelEncoder()
encode categorical labels into numerical labels
y = le.fit_transform(y)
Vectorize the features
vectorizer = CountVectorizer()
X = vectorizer.fit_transform(X)
Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
Convert the y_train and y_test to a sparse matrix format
y_train_sparse = csr_matrix(y_train)
y_test_sparse = csr_matrix(y_test)
Fit and predict using Binary Relevance
br = BinaryRelevance(MLPClassifier(max_iter=1000))
br.fit(X_train, y_train_sparse)
y_pred_br = br.predict(X_test)
Create a new column in the test set with the predicted labels from Binary Relevance
y_test_br = y_test.copy()
y_test_br[“predicted_labels”] = list(y_pred_br.toarray())
print(“y_test shape:”, y_test.shape)
print(“y_pred_br shape:”, y_pred_br.shape)
Print the classification report for Binary Relevance
print(“Binary Relevance”)
print(classification_report(y_test_br, y_pred_br))
This is my code not understanding this error help me to resolve it please