label_encode_categorical_columns
Convert categorical columns into numerical labels for machine learning model training. Simplifies data preprocessing within the Linear Regression MCP pipeline, ensuring compatibility with regression algorithms.
Instructions
This function label encodes all the categorical columns.
Returns: String which confirms success of encoding process.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- server.py:99-120 (handler)The handler function for the 'label_encode_categorical_columns' tool. It identifies categorical columns in the global data context, applies LabelEncoder to each, transforming them into numerical labels, and confirms success.@mcp.tool() def label_encode_categorical_columns() -> str: """ This function label encodes all the categorical columns. Returns: String which confirms success of encoding process. """ categorical_columns = context.get_data().select_dtypes(include=["object", "category"]).columns if len(categorical_columns) == 0: return "No categorical columns found to encode." # Initialize the LabelEncoder encoder = LabelEncoder() # Iterate over each categorical column and apply label encoding for column in categorical_columns: context.get_data()[column] = encoder.fit_transform(context.get_data()[column]) return "All categorical columns have been label encoded successfully."