gpt4 book ai didi

pandas - 箱线图错误: 1 ndim Categorical are not supported at this time

转载 作者:行者123 更新时间:2023-11-30 09:35:51 37 4
gpt4 key购买 nike

我有两个 numpy 数组,如下

clf_scores = numpy.array(
[[ 0.66333666, 0.65634366, 0.63836164, 0.64435564, 0.658 ,
0.641 , 0.67167167, 0.66066066, 0.67167167, 0.65165165],
[ 0.6983017 , 0.70629371, 0.70529471, 0.68331668, 0.702 ,
0.688 , 0.71371371, 0.69269269, 0.70770771, 0.6996997 ],
[ 0.65934066, 0.68531469, 0.65834166, 0.66333666, 0.677 ,
0.668 , 0.68568569, 0.68668669, 0.6996997 , 0.68168168],
.... .... .... .... ....
[ 0.68731269, 0.71928072, 0.7002997 , 0.70929071, 0.723 ,
0.697 , 0.68968969, 0.71271271, 0.72672673, 0.6996997 ],
[ 0.68731269, 0.72027972, 0.6973027 , 0.70729271, 0.726 ,
0.695 , 0.68568569, 0.71271271, 0.72572573, 0.6996997 ],
[ 0.69030969, 0.71728272, 0.6983017 , 0.70929071, 0.725 ,
0.698 , 0.68668669, 0.71371371, 0.72572573, 0.6996997 ]])

Trees = numpy.array(
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65,
66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
92, 93, 94, 95, 96, 97, 98, 99, 100])

这些数组有形状 (100,10) 和 (100,)

如何使用 seaborn.boxplot 绘制这两个数组?

我尝试按如下方式对这两个 numpy 数组进行箱线图

sns.boxplot(clf_scores,Trees)

但是我遇到了以下错误

NotImplementedError: > 1 ndim Categorical are not supported at this time

请告诉我如何纠正它以获得适当的箱线图?

PS:数据集是通过查找RandomForestClassifiercross_val_score得到的,其中nTrees = 100

正确的输出如下 enter image description here

最佳答案

对我来说最简单的方法是首先将数据转换为 pandas 数据框,然后使用 seaborn 绘制它:

 import numpy as np
import pandas as pd
import seaborn as sns

df = pd.DataFrame(np.transpose(clf_scores))
sns.boxplot(data=df)

数据帧df对应于boxplot documentation中描述的“宽格式数据帧”。 。在您的方法中,seaborn 的数据格式错误并假设它是 calcategori,但事实并非如此。

关于pandas - 箱线图错误: 1 ndim Categorical are not supported at this time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43016102/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com