label_encode_categorical_columns
Convert categorical data columns into numerical format for linear regression model training by applying label encoding to prepare datasets.
Instructions
This function label encodes all the categorical columns.
Returns: String which confirms success of encoding process.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "label_encode_categorical_columns"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- server.py:99-99 (registration)Registers the label_encode_categorical_columns function as an MCP tool using the FastMCP decorator.
@mcp.tool() - server.py:100-120 (handler)The handler function implements the logic to identify categorical columns in the global data context and apply label encoding to each using LabelEncoder from scikit-learn.
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."