composeml.LabelTimes.sample¶
- LabelTimes.sample(n=None, frac=None, random_state=None, replace=False, per_instance=False)[source]¶
返回标签的随机样本。
- 参数
n (int 或 dict) – 标签的采样数量。字典返回每个标签的采样数量。不能与 frac 一起使用。
frac (float 或 dict) – 标签的采样比例。字典返回每个标签的采样比例。不能与 n 一起使用。
random_state (int) – 随机数生成器的种子。
replace (bool) – 是否进行有放回或无放回采样。默认值为 False。
per_instance (bool) – 是否对每个组应用采样。默认为 False。
- 返回值
标签的随机样本。
- 返回类型
示例
创建一个标签时间对象。
>>> entity = [0, 0, 1, 1] >>> labels = [True, False, True, False] >>> data = {'entity': entity, 'labels': labels} >>> lt = LabelTimes(data=data, target_dataframe_index='entity', target_columns=['labels']) >>> lt entity labels 0 0 True 1 0 False 2 1 True 3 1 False
对示例进行数量采样。
>>> lt.sample(n=3, random_state=0) entity labels 1 0 False 2 1 True 3 1 False
对示例进行比例采样。
>>> lt.sample(frac=.25, random_state=0) entity labels 2 1 True
对特定标签的示例进行数量采样。
>>> n = {True: 1, False: 1} >>> lt.sample(n=n, random_state=0) entity labels 2 1 True 3 1 False
对特定标签的示例进行比例采样。
>>> frac = {True: .5, False: .5} >>> lt.sample(frac=frac, random_state=0) entity labels 2 1 True 3 1 False
从每个实体组对示例进行数量采样。
>>> lt.sample(n={True: 1}, per_instance=True, random_state=0) entity labels 0 0 True 2 1 True
从每个实体组对示例进行比例采样。
>>> lt.sample(frac=.5, per_instance=True, random_state=0) entity labels 1 0 False 3 1 False