Skip to main content
Glama

target_encode

Transform high-cardinality categorical columns into smoothed target means, enabling better model performance. Use on training data after splitting to prevent leakage.

Instructions

Target-encode high-cardinality categorical columns. Each category is replaced by the smoothed mean of the target variable. Good for columns with many unique values. Best for high-cardinality (>10 categories). IMPORTANT: to avoid data leakage, split data first with train_test_split, then encode training set only. Example: target_encode(columns=["AgentCode","OriginCode"], target_column="Log_Revenue", smoothing=10.0)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
columnsYes
df_nameNo
smoothingNo
target_columnYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden of behavioral disclosure. It accurately describes the transformation (smoothed mean replacement), introduces the smoothing parameter, and warns about the data leakage pitfall. It does not explicitly state whether the operation mutates the dataframe in place or returns a new one, but the phrase 'Each category is replaced' implies in-place modification.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences plus an example, all of which are informative and directly relevant. It does not waste words and the example provides a clear, concrete usage pattern. Every sentence earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description covers the tool's purpose, usage conditions, a critical warning, and includes a concrete example. With an output schema present, return values need not be explained. The only notable gap is the undocumented df_name parameter, but overall the description is well-rounded for a tool of this complexity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It mentions the columns, target_column, and smoothing parameters in the example and text, but does not describe df_name at all. The meaning of smoothing is only partially explained as 'smoothed mean' without detailing how the numeric value affects the encoding, leaving ambiguity about its exact role.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states a specific action ('Target-encode high-cardinality categorical columns') and explains the mechanism ('Each category is replaced by the smoothed mean of the target variable'), distinguishing it from sibling encoding tools like one_hot_encode, label_encode, and frequency_encode. The mention of 'high-cardinality' and 'smoothed mean' makes the purpose unmistakable.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear usage context: 'Good for columns with many unique values. Best for high-cardinality (>10 categories).' It also gives a critical procedural guideline about data leakage: 'split data first with train_test_split, then encode training set only.' However, it does not explicitly mention when not to use the tool or name alternative encoding methods, so it falls short of a 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/AstyanM/mcp-data-science'

If you have feedback or need assistance with the MCP directory API, please join our Discord server