Segui o código da aula:
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.preprocessing import StandardScaler
padronizador = StandardScaler()
padronizador.fit(valores_exames_v1)
valores_exames_v2 = padronizador.transform(valores_exames_v1)
valores_exames_v2 = pd.DataFrame(data = valores_exames_v2,
columns=valores_exames_v1.keys())
dados_plot = pd.concat([diagnostico, valores_exames_v2.iloc[:, 0:10]], axis = 1)
dados_plot = pd.melt(dados_plot,
id_vars="diagnostico",
var_name="exames",
value_name="valores")
print(dados_plot.info())
plt.figure(figsize=(10,10))
sns.violinplot(x="exames",
y="valores",
hue="diagnostico",
data=dados_plot,
split=True)
sns.xticks(rotation=90)
Eis a mensagem de erro:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[44], line 20
16 print(dados_plot.info())
18 plt.figure(figsize=(10,10))
---> 20 sns.violinplot(x="exames",
21 y="valores",
22 hue="diagnostico",
23 data=dados_plot,
24 split=True)
26 sns.xticks(rotation=90)
File ~\anaconda3\lib\site-packages\seaborn\categorical.py:2392, in violinplot(x, y, hue, data, order, hue_order, bw, cut, scale, scale_hue, gridsize, width, inner, split, dodge, orient, linewidth, color, palette, saturation, ax, **kwargs)
2389 if ax is None:
2390 ax = plt.gca()
-> 2392 plotter.plot(ax)
2393 return ax
File ~\anaconda3\lib\site-packages\seaborn\categorical.py:1091, in _ViolinPlotter.plot(self, ax)
1089 def plot(self, ax):
1090 """Make the violin plot."""
-> 1091 self.draw_violins(ax)
1092 self.annotate_axes(ax)
1093 if self.orient == "h":
File ~\anaconda3\lib\site-packages\seaborn\categorical.py:883, in _ViolinPlotter.draw_violins(self, ax)
881 # Handle the special case where we have one observation
882 elif support.size == 1:
--> 883 val = np.asscalar(support)
884 d = np.asscalar(density)
885 if self.split:
File ~\anaconda3\lib\site-packages\numpy\__init__.py:311, in __getattr__(attr)
308 from .testing import Tester
309 return Tester
--> 311 raise AttributeError("module {!r} has no attribute "
312 "{!r}".format(__name__, attr))
AttributeError: module 'numpy' has no attribute 'asscalar'
Pelo que entendi, a função sns.violinplot() está utilizando um atributo deprecado do numpy. Como resolvo isso?
Estou fazendo pelo Jupyter Notebook 6.5.2