Generation

generate functionMon, 13 Mar 2023

This code does not work and gives the following error: ValueError: Target is multiclass but average='binary'. Please choose another average setting, one of [None, 'micro', 'macro', 'weighted']. Fix it! from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(data, data_class, random_state=42) from sklearn.discriminant_analysis import LinearDiscriminantAnalysis lda.fit(X_train, y_train) from sklearn.metrics import f1_score y_pred = lda.predict(X_test) f1_score(y_test, y_pred) Write code to evaluate its quality with F1 measure

from sklearn.model_selection import train_test_split from sklearn.discriminant_analysis import LinearDiscriminantAnalysis from sklearn.metrics import f1_score from sklearn.preprocessing import LabelEncoder from sklearn.metrics import confusion_matrix from sklearn.metrics import classification_report le = LabelEncoder() le.fit(data_class) data_class = le.transform(data_class) X_train, X_test, y_train, y_test = train_test_split(data, data_class, random_state=42) lda = LinearDiscriminantAnalysis() lda.fit(X_train, y_train) y_pred = lda.predict(X_test) f1 = f1_score(y_test, y_pred, average='macro') # average='macro' print('F1:', f1) #confusion_matrix(y_test, y_pred) print(classification_report(y_test, y_

Questions about programming?Chat with your personal AI assistant