估计器:映射向量 ->标量的字符串或可调用对象



我正在阅读seaborn.barplot的文档,并阅读了以下内容。

estimator : string or callable that maps vector -> scalar, optional
Statistical function to estimate within each categorical bin.

我不明白callable that maps vector -> scalar是什么意思。这份声明传达了什么?

当我通过估计器='mean'时,我得到了这个错误。

TypeError: 'str' object is not callable

我们应该把什么作为字符串传递?

可调用表示一个函数。命名函数或lambda函数。一种函数,它以向量为参数并返回标量。函数是";一等公民;在Python中,因此可以作为参数传递,并且通常被视为任何其他对象。

参见此处的示例:

import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
penguin_data = sns.load_dataset("penguins")
f = plt.figure(figsize=(6, 4))
fig = sns.barplot(x="species", y="body_mass_g", palette = "flare",
estimator = np.mean, data=penguin_data)

相关内容

最新更新