set_feature_names

Set names for all features in the model.

Method call format

set_feature_names(feature_names)

Parameters

Parameter Possible types Description Default value
feature_names
  • ndarray
  • list

A one-dimensional array of feature names for each feature. The order and number of specified names must match the ones used in the dataset.

Required parameter.
Parameter Possible types Description Default value
feature_names
  • ndarray
  • list

A one-dimensional array of feature names for each feature. The order and number of specified names must match the ones used in the dataset.

Required parameter.

Example

The following example outputs the original feature names, changes them and then outputs the updated names.

from catboost import CatBoost

train_data = [[1, 4, 5, 6],
              [4, 5, 6, 7],
              [30, 40, 50, 60]]

eval_data = [[2, 4, 6, 8],
             [1, 4, 50, 60]]

train_labels = [10, 20, 30]

model = CatBoost()

model.fit(train_data,
          train_labels,
          verbose=False)

print("Original feature names:")
print(model.feature_names_)
print("Changed feature names:")
model.set_feature_names(["feature_1", "feature_2", "feature_3", "feature_4"])
print(model.feature_names_)

Output:

Original feature names:
['0', '1', '2', '3']
Changed feature names:
['feature_1', 'feature_2', 'feature_3', 'feature_4']