ecdf: 创建经验累积分布函数图
一个方便地绘制经验累积分布函数的函数。
from mlxtend.ecdf import ecdf
概述
一个方便地绘制经验累积分布函数 (ECDF) 并添加百分位数阈值以进行探索性数据分析的函数。
参考资料
- -
示例 1 - ECDF
from mlxtend.data import iris_data
from mlxtend.plotting import ecdf
import matplotlib.pyplot as plt
X, y = iris_data()
ax, _, _ = ecdf(x=X[:, 0], x_label='sepal length (cm)')
plt.show()
示例 2 - 多个 ECDF
from mlxtend.data import iris_data
from mlxtend.plotting import ecdf
import matplotlib.pyplot as plt
X, y = iris_data()
# first ecdf
x1 = X[:, 0]
ax, _, _ = ecdf(x1, x_label='cm')
# second ecdf
x2 = X[:, 1]
ax, _, _ = ecdf(x2, ax=ax)
plt.legend(['sepal length', 'sepal width'])
plt.show()
示例 3 - 带百分位数阈值的 ECDF
from mlxtend.data import iris_data
from mlxtend.plotting import ecdf
import matplotlib.pyplot as plt
X, y = iris_data()
ax, threshold, count = ecdf(x=X[:, 0],
x_label='sepal length (cm)',
percentile=0.8)
plt.show()
print('Feature threshold at the 80th percentile:', threshold)
print('Number of samples below the threshold:', count)
Feature threshold at the 80th percentile: 6.5
Number of samples below the threshold: 120
API
ecdf(x, y_label='ECDF', x_label=None, ax=None, percentile=None, ecdf_color=None, ecdf_marker='o', percentile_color='black', percentile_linestyle='--')
绘制经验累积分布函数
参数
-
x
: 数组或列表, shape=[n_samples,]包含特征值的类数组对象
-
y_label
: str (默认='ECDF')y 轴的文本标签
-
x_label
: str (默认=None)x 轴的文本标签
-
ax
: matplotlib.axes.Axes (默认: None)现有的 matplotlib Axes 对象。如果 ax=None 则创建一个。
-
percentile
: float (默认=None)0 到 1 之间的浮点数,用于绘制百分位数阈值线
-
ecdf_color
: matplotlib 颜色 (默认=None)ECDF 图的颜色;如果为 None,则使用 matplotlib 默认值
-
ecdf_marker
: matplotlib 标记 (默认='o')ECDF 图的标记样式
-
percentile_color
: matplotlib 颜色 (默认='black')如果 percentile 不为 None,则为百分位数阈值的颜色
-
percentile_linestyle
: matplotlib 线型 (默认='--')如果 percentile 不为 None,则为百分位数阈值的线型
返回值
-
ax
: matplotlib.axes.Axes 对象 -
percentile_threshold
: float百分位数处的特征阈值,如果
percentile=None
则为 None -
percentile_count
: 如果 percentile 不为 None,则为数量样本数量,其特征小于或等于百分位数阈值处的特征阈值;如果
percentile=None
则为 None
示例
有关使用示例,请参阅 https://mlxtend.cn/mlxtend/user_guide/plotting/ecdf/