how to get column names of a trained model< in python

If you have trained a model using scikit-learn in Python, you can access the column names of the features used in the model using the feature_names_ attribute. Here's how you can do it:

main.py
from sklearn.tree import DecisionTreeClassifier

# Assuming you have already trained a model
model = DecisionTreeClassifier()
model.fit(X_train, y_train)

# Get the column names
column_names = list(X_train.columns)

print(column_names)
236 chars
11 lines

Replace X_train with your input features and y_train with your target variable. X_train.columns assumes that your input features are provided as a pandas DataFrame.

Note: This method is specific to scikit-learn models. Different libraries or models may have different ways to access the column names.

gistlibby LogSnag