set_labels() | FeatureGroup Method | Teradata Package for Python - set_labels() - Teradata Package for Python

Teradata® Package for Python User Guide

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Product
Teradata Package for Python
Release Number
20.00
Published
March 2025
ft:locale
en-US
ft:lastEdition
2025-12-05
dita:mapPath
nvi1706202040305.ditamap
dita:ditavalPath
plt1683835213376.ditaval
dita:id
rkb1531260709148
Product Category
Teradata Vantage

Use the set_labels() method to set labels for the FeatureGroup. This method is helpful when working with analytic functions to consume the features.

Required Parameter

labels
Specifies the names of the features to refer as labels.

Example setup

>>> from teradataml import DataSource, Entity, Feature, FeatureGroup, load_example_data
>>> load_example_data("dataframe", "admissions_train")

Create a DataFrame.

>>> df = DataFrame("admissions_train")

Create the features.

>>> masters_feature = Feature("masters", df.masters)
>>> gpa_feature = Feature("gpa", df.gpa)
>>> stats_feature = Feature("stats", df.stats)
>>> admitted_feature = Feature("admitted", df.admitted)

Create an entity.

>>> entity = Entity("id", df.id)

Create a data source.

>>> data_source = DataSource("admissions_source", df)

Create a feature group.

>>> fg = FeatureGroup('Admissions',
...                   features=[masters_feature, gpa_feature, stats_feature, admitted_feature],
...                   entity=entity,
...                   data_source=data_source)

Example 1: Set feature 'admitted' as label

Set the 'admitted' feature as the label.

>>> fg.set_labels('admitted')
True

Get the labels from the feature group.

>>> fg.labels
Feature(name=admitted)

Example 2: Set multiple features as labels

Set features 'masters' and 'gpa' as labels.

>>> fg.set_labels(['masters', 'gpa'])
True

Get the labels from the feature group.

>>> fg.labels
[Feature(name=masters), Feature(name=gpa)]