Agent skill

Teradata K-Nearest Neighbors Analytics

K-Nearest Neighbors for classification and regression

Stars 6
Forks 0

Install this agent skill to your Project

npx add-skill https://github.com/teradata-labs/claude-cookbooks/tree/main/skills/analytics/td-knn

SKILL.md

Teradata K-Nearest Neighbors Analytics

Property Value
Skill Name Teradata K-Nearest Neighbors Analytics
Description K-Nearest Neighbors for classification and regression
Category Machine Learning
Primary Function TD_KNN
Framework SQLE

Core Capabilities

  • Automated table structure analysis via DBC.ColumnsV
  • Dynamic SQL generation for TD_KNN
  • Complete workflow from data preparation to results interpretation
  • Data quality validation and preprocessing guidance
  • Parameter optimization and tuning

Key Parameters

  • ResponseColumn: Target variable in training data
  • IDColumn: Unique row identifier in test data
  • DistanceFeatures: Feature columns for distance computation
  • NumberOfNeighbors: K value (default 5)
  • VotingMethod: 'UNIFORM' (equal weight) or 'DISTANCE' (inverse-distance)
  • DistanceMethod: 'EUCLIDEAN', 'MANHATTAN', 'COSINE'
  • Accumulate: Columns to pass through to output

Use Cases

  1. Classification based on proximity
  2. Regression with local averaging
  3. Anomaly detection via distance
  4. Recommendation systems
  5. Pattern recognition

Example Usage

sql
-- TD_KNN execution
SELECT * FROM TD_KNN (
    ON {USER_DATABASE}.{TRAIN_TABLE} AS TrainTable
    ON {USER_DATABASE}.{TEST_TABLE} AS TestTable DIMENSION
    USING
    ResponseColumn ('{TARGET_COLUMN}')
    IDColumn ('{ID_COLUMN}')
    DistanceFeatures ('{FEATURE_COLUMNS}')
    NumberOfNeighbors (5)
    VotingMethod ('UNIFORM')           -- 'UNIFORM' or 'DISTANCE'
    DistanceMethod ('EUCLIDEAN')       -- 'EUCLIDEAN','MANHATTAN','COSINE'
    Accumulate ('{ID_COLUMN}')
) AS dt;

Scripts Included

Core Analytics Scripts

  • table_analysis.sql: Automatic table structure discovery
  • preprocessing.sql: Data preparation and feature engineering
  • model_training.sql: TD_KNN execution
  • evaluation.sql: Results analysis and metrics
  • complete_workflow_template.sql: End-to-end workflow

Utility Scripts

  • data_quality_checks.sql: Comprehensive data validation
  • parameter_tuning.sql: Parameter optimization
  • diagnostic_queries.sql: Results diagnostics and interpretation

Best Practices

  • Always run table_analysis.sql first to understand your data structure
  • Validate data quality before executing the analytical function
  • Use parameter_tuning.sql to find optimal configuration
  • Review diagnostic_queries.sql output for model/results validation

Limitations

  • Requires Teradata Vantage 17.20+ with ClearScape Analytics
  • Input data must meet function-specific requirements
  • Results depend on data quality and parameter configuration

Teradata K-Nearest Neighbors Analytics - ClearScape Analytics skill for Teradata Vantage

Expand your agent's capabilities with these related and highly-rated skills.

Didn't find tool you were looking for?

Be as detailed as possible for better results