Я пытаюсь написать код для набора данных клуба карате Захари. Теперь я застрял в строке
y_true_val = list(y_true.values())
Мой код:
nmi_results = []
ars_results = []
y_true_val = list(y_true.values())
# Append the results into lists
for y_pred in results:
nmi_results.append(normalized_mutual_info_score(y_true_val, y_pred))
ars_results.append(adjusted_rand_score(y_true_val, y_pred))
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, sharey=True, figsize=(16, 5))
x = np.arange(len(y_pred))
avg = [sum(x) / 2 for x in zip(nmi_results, ars_results)]
xlabels = list(algorithms.keys())
sns.barplot(x, nmi_results, palette='Blues', ax=ax1)
sns.barplot(x, ars_results, palette='Reds', ax=ax2)
sns.barplot(x, avg, palette='Greens', ax=ax3)
ax1.set_ylabel('NMI Score')
ax2.set_ylabel('ARS Score')
ax3.set_ylabel('Average Score')
# # Add the xlabels to the chart
ax1.set_xticklabels(xlabels)
ax2.set_xticklabels(xlabels)
ax3.set_xticklabels(xlabels)
# Add the actual value on top of each bar
for i, v in enumerate(zip(nmi_results, ars_results, avg)):
ax1.text(i - 0.1, v[0] + 0.01, str(round(v[0], 2)))
ax2.text(i - 0.1, v[1] + 0.01, str(round(v[1], 2)))
ax3.text(i - 0.1, v[2] + 0.01, str(round(v[2], 2)))
# Show the final plot
plt.show()
Вывод:
y_true_val = list(y_true.values())
AttributeError: 'list' object has no attribute 'values'