@@ -98,6 +98,38 @@ def _infer_target_types(self):
9898 return types
9999
100100 def select (self , target ):
101+ """Selects one of the target variables.
102+
103+ Args:
104+ target (str): The name of the target column.
105+
106+ Returns:
107+ lt (LabelTimes): A label times object that contains a single target.
108+
109+ Examples:
110+ Create a label times object that contains multiple target variables.
111+
112+ >>> entity = [0, 0, 1, 1]
113+ >>> labels = [True, False, True, False]
114+ >>> time = ['2020-01-01', '2020-01-02', '2020-01-03', '2020-01-04']
115+ >>> data = {'entity': entity, 'time': time, 'A': labels, 'B': labels}
116+ >>> lt = LabelTimes(data=data, target_entity='entity', target_columns=['A', 'B'])
117+ >>> lt
118+ entity time A B
119+ 0 0 2020-01-01 True True
120+ 1 0 2020-01-02 False False
121+ 2 1 2020-01-03 True True
122+ 3 1 2020-01-04 False False
123+
124+ Select a single target from the label times.
125+
126+ >>> lt.select('B')
127+ entity time B
128+ 0 0 2020-01-01 True
129+ 1 0 2020-01-02 False
130+ 2 1 2020-01-03 True
131+ 3 1 2020-01-04 False
132+ """
101133 assert not self ._is_single_target , 'only one target exists'
102134 if not isinstance (target , str ): raise TypeError ('target name must be string' )
103135 assert target in self .target_columns , 'target "%s" not found' % target
@@ -405,52 +437,62 @@ def sample(self, n=None, frac=None, random_state=None, replace=False, per_instan
405437 LabelTimes : Random sample of labels.
406438
407439 Examples:
408- These are the label values for the examples .
440+ Create a label times object .
409441
410- >>> lt = LabelTimes({'labels': list('AABBBAA')})
442+ >>> entity = [0, 0, 1, 1]
443+ >>> labels = [True, False, True, False]
444+ >>> data = {'entity': entity, 'labels': labels}
445+ >>> lt = LabelTimes(data=data, target_entity='entity', target_columns=['labels'])
411446 >>> lt
412- labels
413- 0 A
414- 1 A
415- 2 B
416- 3 B
417- 4 B
418- 5 A
419- 6 A
447+ entity labels
448+ 0 0 True
449+ 1 0 False
450+ 2 1 True
451+ 3 1 False
420452
421- Sample a number of examples.
453+ Sample a number of the examples.
422454
423455 >>> lt.sample(n=3, random_state=0)
424- labels
425- 1 A
426- 2 B
427- 6 A
456+ entity labels
457+ 1 0 False
458+ 2 1 True
459+ 3 1 False
428460
429- Sample a number of examples for specific labels .
461+ Sample a fraction of the examples .
430462
431- >>> n_per_label = {'A': 1, 'B': 2}
432- >>> lt.sample(n=n_per_label, random_state=0)
433- labels
434- 3 B
435- 4 B
436- 5 A
463+ >>> lt.sample(frac=.25, random_state=0)
464+ entity labels
465+ 2 1 True
437466
438- Sample a fraction of the examples.
467+ Sample a number of the examples for specific labels .
439468
440- >>> lt.sample(frac=.4, random_state=2)
441- labels
442- 1 A
443- 3 B
444- 4 B
469+ >>> n = {True: 1, False: 1}
470+ >>> lt.sample(n=n, random_state=0)
471+ entity labels
472+ 2 1 True
473+ 3 1 False
445474
446475 Sample a fraction of the examples for specific labels.
447476
448- >>> frac_per_label = {'A': .5, 'B': .34}
449- >>> lt.sample(frac=frac_per_label, random_state=2)
450- labels
451- 4 B
452- 5 A
453- 6 A
477+ >>> frac = {True: .5, False: .5}
478+ >>> lt.sample(frac=frac, random_state=0)
479+ entity labels
480+ 2 1 True
481+ 3 1 False
482+
483+ Sample a number of the examples from each entity group.
484+
485+ >>> lt.sample(n={True: 1}, per_instance=True, random_state=0)
486+ entity labels
487+ 0 0 True
488+ 2 1 True
489+
490+ Sample a fraction of the examples from each entity group.
491+
492+ >>> lt.sample(frac=.5, per_instance=True, random_state=0)
493+ entity labels
494+ 1 0 False
495+ 3 1 False
454496 """ # noqa
455497 self ._assert_single_target ()
456498
0 commit comments