feature_name_mapper#
- pybear.utilities.feature_name_mapper(feature_names, feature_names_in, positive=True)#
Map a vector of feature names feature_names against the full set of feature names provided by feature_names_in.
Return the index positions of the given feature names with respect to their position in feature_names_in. Can be returned as positive indices, e.g. [0,3,4], or negative indices, e.g. [-4,-2,-1], or as given.
- Parameters:
- feature_namesSequence[str] | Sequence[int] | None
The feature names to be mapped to index positions. If None, returns None. If an empty 1D sequence, returns the same. If passed as integers without a feature_names_in reference, returns the original. if passed as integers with a feature_names_in reference, the index values are validated against the dimensions of the feature_names_in vector and mapped to all positive or all negative values based on positive. If passed as strings without a feature_names_in reference, raises exception. If passed as strings with a feature_names_in reference, the string values are mapped to the index positions in the feature_names_in vector and mapped to all positive or all negative values based on positive. If passed as string values and a value is not in feature_names_in, raises exception.
- feature_names_inSequence[str] | None
If not None, a 1D list-like containing strings that are the feature names of a data-bearing container.
- positivebool | None
Whether to return the mapped indices as all positive or all negative integers. if None, leave the indices as is.
- Returns:
- indicesnumpy.ndarray[np.int32]
The given feature names mapped to index positions.
Examples
>>> from pybear.utilities import feature_name_mapper >>> import numpy as np >>> data = np.random.randint(0, 10, (5, 3)) >>> columns = np.array(['A', 'B', 'C']) >>> feature_names = np.array(['A', 'C']) >>> out = feature_name_mapper( ... feature_names, columns, positive=False ... ) >>> print(out) [-3 -1]