seg1d.Segmenter.set_target¶
-
Segmenter.
set_target
(t, copy=True)[source]¶ Sets the target data by overiding any existing target. If the target is not a dict, it will be converted to one.
Parameters: - tdict or ndarray
- Dictionary containing labeled features as keys and values as 1-D arrays (must be same size).ndarray of dimension 1 will be used as a single feature for the target.ndarray of n-dimensions will use rows as unique features.
- copybool, optional
If True, will make a deepcopy of the passed parameter (Default True)
Returns: - None
See also
add_reference
- Add a reference item
Notes
This is the recommended method for adding a feature. You can also set the target directly through the Attribute t by
`Segmenter.t = `
however, this method ensures the data labels and length or stored properly. Setting t directly must be done with a dictionary.Examples
Target data can be set to a single numpy array.
>>> import numpy as np >>> import seg1d >>> >>> s = seg1d.Segmenter() >>> t = np.linspace(0,1,4) >>> s.set_target(t) >>> s.t {'0': array([0. , 0.33333333, 0.66666667, 1. ])}
Alternatively, you can pass a 2-dimensional array representing multiple features.
>>> s = seg1d.Segmenter() >>> t = np.linspace(0,1,6).reshape(2,3) >>> s.set_target(t) >>> s.t {'0': array([0. , 0.2, 0.4]), '1': array([0.6, 0.8, 1. ])}