我有一个通过使用 for 循环按列扩展的数据框。现在我想以某种方式存储不断发展的 DF 的某些“阶段”,我认为最好使用字典。
给你一张图片:
df_dict={}
for i in range(1,13):
df=pd.read_csv('./test.csv').iloc[:,0:i*4-1]
Run Code Online (Sandbox Code Playgroud)
所以我想将其存储为 df 的“第一阶段”:
col1 col2 col3 col4
1 3 5 7
2 4 6 8
Run Code Online (Sandbox Code Playgroud)
在“第二阶段”:
col1 col2 col3 col4 col5 col6 col7 col8
1 3 5 7 9 11 13 15
2 4 6 8 10 12 14 16
Run Code Online (Sandbox Code Playgroud)
第三阶段包含 12 列:
col1 col2 col3 col4 col5 col6 col7 col8 ...
1 3 5 7 9 11 13 15 ...
2 4 6 8 10 12 14 …Run Code Online (Sandbox Code Playgroud) 我有一个带有非常小的数字的混淆矩阵,但我找不到改变它们的方法。
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, rf_predictions)
ax = plt.subplot()
sns.set(font_scale=3.0) #edited as suggested
sns.heatmap(cm, annot=True, ax=ax, cmap="Blues", fmt="g"); # annot=True to annotate cells
# labels, title and ticks
ax.set_xlabel('Predicted labels');
ax.set_ylabel('Observed labels');
ax.set_title('Confusion Matrix');
ax.xaxis.set_ticklabels(['False', 'True']);
ax.yaxis.set_ticklabels(['Flase', 'True']);
plt.show()
Run Code Online (Sandbox Code Playgroud)
我不介意手动更改分类的编号,但我真的不想为标签也这样做。
干杯