Agentic-MachineLearningEngineer / Technical_README.md
AaronTekle's picture
Create Technical_README.md
ad20200 verified
|
Raw
History Blame Contribute Delete
39.3 kB

Agentic Machine Learning Engineer (Traditional ML Engineering) - Qwen3-Coder-30B-A3B-Instruct

Note 1: Do not upload confidential, regulated, proprietary, customer, or personally identifiable production data into a public Hugging Face Space

Note 2: This project is an automated traditional machine learning engineering experiment focused on supervised classification and regression workflows

Note 3: This project uses a bounded single-agent function-calling / tool-use loop rather than an unlimited autonomous agent


(this) Bounded Tool-Calling Agent vs Open-Ended Autonomous Agent

Bounded Tool-Calling Agent (my agent)

β€œReason about the task, call the available ML tools when needed, and stop within a controlled number of steps.”

Open-Ended Autonomous Agent

β€œContinue deciding and acting until the broader goal is achieved.”

Bounded Tool-Calling Agent Open-Ended Autonomous Agent
Consistency higher because tools and loop limits are controlled can vary more between runs
Traceability tool calls and observations are exposed can become harder to trace across long runs
Resource control hard max agent-step limit may require additional stopping logic
Decision-making dynamic tool selection within a constrained toolset can make broader autonomous decisions
Flexibility controlled higher
Risk of runaway loops reduced through MAX_AGENT_STEPS param higher without explicit limits

bounded agent decides which ML operation to perform inside a controlled tool loop, while a fully open-ended autonomous agent may continue planning and acting without the same fixed execution boundary.


Agent Goals:

  • agentic machine learning engineering app for profiling datasets, automated supervised-learning modeling, preprocessing data, training baseline models, comparing algorithms, evaluating real model performance, and generating reusable scikit-learn pipelines

  • agent loads a real-world dataset, creates the modeling context, gives a Qwen3-Coder agent access to machine-learning tools, and allows the model to decide which tools to call before producing a final ML assessment and reusable pipeline code

  • reduce repetitive setup work when starting supervised machine learning experiments

  • ground model-performance claims in actual scikit-learn execution

  • expose tool calls and observations for auditability

  • demonstrate how an LLM can orchestrate traditional machine learning workflows without performing the numerical fitting itself


Machine Learning Agent - Tasks

Machine Learning Agent can analyze datasets and execute supervised-learning workflows by first understanding the dataset, target, feature types, and modeling objective.

Dataset inspection

inspect_dataset tool can analyze:

  • Shape: number of rows and columns
  • Columns: available feature / target candidates
  • Types: pandas data types
  • Numeric features: identified numerical columns
  • Categorical features: identified categorical columns
  • Nulls: missing-value information
  • Cardinality: number of unique values per column
  • Examples: representative values from each column
  • Targets: possible prediction-target columns

Modeling tasks

the ML workflow can:

  • inspect the dataset
  • identify a prediction target
  • infer classification vs regression
  • separate numeric and categorical features
  • construct preprocessing transformations
  • train baseline estimators
  • calculate holdout metrics
  • compare compatible algorithms
  • inspect feature importance / coefficients where supported
  • generate reusable scikit-learn pipeline code
  • export fitted pipelines as Joblib artifacts

findings can then be converted into:

 Dataset assessment
        ↓
Recommended modeling setup
        ↓
Preprocessing pipeline
        ↓
 Model training
        ↓
Holdout evaluation
        ↓
Algorithm comparison
        ↓
Reusable scikit-learn pipeline

What, Why, and General Objectives

What

Tool-using Machine Learning Engineering AI agent that profiles datasets, determines supervised-learning setup, trains real scikit-learn models, compares algorithms, evaluates model performance, and generates reusable ML pipelines.

Why

Machine learning engineers repeatedly perform the same early-stage workflow when starting supervised learning related tasks/projects:

load dataset
     ↓
inspect features + target
     ↓
determine problem type
     ↓
build preprocessing
     ↓
select algorithm
     ↓
train model
     ↓
evaluate performance
     ↓
compare alternatives
     ↓
generate reusable pipeline

automating this workflow reduces repetitive machine learning setup, baseline experimentation, preprocessing, evaluation, and pipeline-generation work

General Objectives

  • automate traditional ML modeling

  • make model evaluation traceable through tool outputs

  • provide a consistent preprocessing and model-training workflow

  • compare baseline algorithms quickly

  • calculate metrics from real fitted models rather than LLM estimates

  • generate reusable scikit-learn pipeline code

  • expose tool calls and observations for auditability

  • demonstrate how an LLM agent can orchestrate traditional machine learning tools

  • keep local ML execution lightweight enough for Hugging Face Spaces

LLM / Agent Stack

  • Agent LLM: Qwen/Qwen3-Coder-30B-A3B-Instruct

  • Inference: huggingface_hub.InferenceClient

  • Provider routing: Hugging Face Inference Providers using provider="auto" by default

  • Agent pattern: bounded single-agent function-calling / tool-use loop

  • Tool routing: tool_choice="auto"

  • Maximum agent steps: 4 by default

    • Prevent Infinite Loops: keeps the agent from repeatedly calling the same tool or getting stuck in an unsuccessful reasoning loop

    • Control Costs: limits unnecessary inference-provider requests and token usage

    • Manage Context Windows: prevents tool observations from growing indefinitely inside the conversation context

    • Reduce Latency: prevents unnecessarily long tool-calling runs

    • Improve Debuggability: provides a predictable execution boundary when analyzing the tool trace

  • Local ML execution: scikit-learn

  • Dataset processing: pandas

  • Model artifact export: Joblib

  • Parquet support: PyArrow

  • Excel support: OpenPyXL

  • HF sample dataset: scikit-learn/adult-census-income

Goal:

machine learning engineering is not only model generation

a usable supervised ML workflow requires:

  • understanding the dataset

  • selecting a prediction target

  • deciding whether the task is classification or regression

  • identifying numerical and categorical features

  • preprocessing missing and categorical data

  • selecting an estimator

  • training models on real data

  • calculating ML evaluation metrics

  • comparing alternatives options (ML models)

  • packaging preprocessing + model logic into reusable code

doing this manually for every new dataset creates repetitive experimentation and setup work.

this Machine Learning Engineering Agent is designed to:

  • reduce time spent manually inspecting new datasets

  • establish a consistent supervised-learning baseline workflow

  • identify numerical and categorical feature requirements

  • infer or use a selected classification / regression problem type

  • allow the LLM to call machine-learning execution functions

  • train real models through scikit-learn

  • calculate real holdout evaluation metrics

  • compare compatible baseline algorithms

  • generate production-oriented scikit-learn pipelines

  • export fitted pipelines as Joblib artifacts

  • expose the agent's tool calls through a trace for auditability

goal of the app is to combine:

LLM reasoning
      +
ML execution
      +
tool calling
      +
reusable pipeline generation

Agentic Workflow:

Dataset
   ↓
 app.py
   ↓
Dataset loading + session state
   ↓
Dataset profile
   ↓
Target selection
   ↓
Problem-type inference / selection
   ↓
Algorithm selection
   ↓
MachineLearningAgent
   ↓
Qwen3-Coder-30B-A3B-Instruct
   ↓
HF InferenceClient
   ↓
tool_choice="auto"
   ↓
Agent decides which ML tool(s) to call
   ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ inspect_dataset                              β”‚
β”‚ recommend_modeling_setup                     β”‚
β”‚ train_candidate_model                        β”‚
β”‚ compare_algorithms                           β”‚
β”‚ generate_pipeline_code                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   ↓
Tool observations returned to Qwen
   ↓
Agent evaluates whether another tool is needed
   ↓
Bounded tool-use loop
   ↓
ML assessment
   ↓
Modeling risks
   ↓
Recommended modeling setup
   ↓
Evaluation findings
   ↓
Model comparison
   ↓
Generated scikit-learn pipeline
   ↓
Tool Trace + Diagnostics

Agent Loop Type

Bounded Single-Agent Function-Calling / Tool-Use Loop

  • agentic pattern where one AI agent can autonomously choose from external ML tools, process their outputs, and repeat the process inside a strictly defined step limit

  • unlike open-ended agents that can continue indefinitely, this bounded loop places a hard-fixed limit on execution

  • the project uses a single agent, not a multi-agent architecture

Architecture:

observe task β†’ choose tool β†’ execute ML operation β†’ return observation β†’ repeat if needed β†’ synthesize final answer

the LLM does not directly calculate every machine learning result itself

MachineLearningAgent exposes Python / scikit-learn tools to Qwen through Hugging Face function calling

the model receives:

  • system instructions

  • user machine learning task

  • dataset profile

  • selected target

  • inferred or selected problem type

  • selected algorithm

  • available tool definitions

the model can then request one or more tool calls.

Example Input Workflow

Qwen
  ↓
inspect_dataset()
  ↓
dataset profile returned to Qwen
  ↓
recommend_modeling_setup()
  ↓
recommended setup returned to Qwen
  ↓
train_candidate_model()
  ↓
real training metrics returned to Qwen
  ↓
compare_algorithms()
  ↓
algorithm leaderboard returned to Qwen
  ↓
generate_pipeline_code()
  ↓
scikit-learn pipeline code returned to Qwen
  ↓
Final ML response

loop is bounded by:

MAX_AGENT_STEPS = 4

if the model does not finish within the configured tool loop, the application moves toward final response synthesis rather than allowing unlimited additional tool calls.

this makes the architecture a controlled bounded tool-calling machine learning agent.

Agent Architecture:

                         USER
                           β”‚
                           β–Ό
                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                  β”‚     app.py      β”‚
                  β”‚   Gradio UI     β”‚
                  β”‚ Session state   β”‚
                  β”‚ Dataset loading β”‚
                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
                           β”‚ task + dataset + target
                           β–Ό
               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
               β”‚ MachineLearningAgent   β”‚
               β”‚       agent.py         β”‚
               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
                            β–Ό
               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
               β”‚ Qwen3-Coder 30B A3B    β”‚
               β”‚ HF InferenceClient     β”‚
               β”‚ tool_choice="auto"     β”‚
               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
                     decides which tool
                        to execute
                            β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚                   β”‚                    β”‚
        β–Ό                   β–Ό                    β–Ό
 inspect_dataset   recommend_modeling_setup   train_candidate_model
        β”‚                   β”‚                    β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
                            β–Ό
                    compare_algorithms
                            β”‚
                            β–Ό
                  generate_pipeline_code
                            β”‚
                            β–Ό
                     Tool observation
                            β”‚
                            β–Ό
               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
               β”‚ Observation added back β”‚
               β”‚    to LLM context      β”‚
               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
                            β–Ό
                     More tools needed?
                       /           \
                     yes            no
                      β”‚              β”‚
                      └──────┐       β”‚
                             β”‚       β”‚
                             β–Ό       β–Ό
                         Tool loop   Final synthesis
                                         β”‚
                                         β–Ό
                                  ML assessment
                                  Modeling risks
                                  Recommended setup
                                  Evaluation findings
                                  Model comparison
                                  Pipeline code
                                  Tool trace

Core Architectural Pattern:

app.py
   ↓
agent.py
   ↓
MachineLearningAgent
   ↓
Qwen3-Coder + HF tool calling
   ↓
ml_engine.py
   ↓
ML operations
   ↓
tool observations
   ↓
agent.py
   ↓
final ML assessment + pipeline code

Agent Tools

1. inspect_dataset

analyzes the loaded dataset and returns structural information used by the agent before modeling

typical outputs include:

  • source

  • row count

  • column count

  • column names

  • feature types

  • pandas dtypes

  • null information

  • unique-value information

  • possible target columns

  • example values

used when the agent needs to understand the structure of the dataset before recommending a modeling approach


2. recommend_modeling_setup

evaluates the dataset and selected target to recommend a supervised-learning configuration

recommendation can include:

  • target column

  • inferred problem type

  • candidate algorithms

  • dataset characteristics relevant to modeling

  • preprocessing expectations

  • numerical feature information

  • categorical feature information

goal: setup a reasonable baseline modeling configuration before training


3. train_candidate_model

builds and trains the selected scikit-learn pipeline using the actual loaded dataset

training workflow:

dataset
   ↓
feature / target split
   ↓
train / holdout split
   ↓
numeric preprocessing
   ↓
categorical preprocessing
   ↓
selected estimator
   ↓
  fit
   ↓
holdout prediction
   ↓
holdout evaluation

the agent receives metrics produced by the trained model

the agent is instructed not to invent performance values


4. compare_algorithms

trains compatible baseline algorithms and returns a comparison leaderboard based on real holdout results.

classification, candidate algorithms include:

  • Logistic Regression

  • Random Forest Classifier

  • SGD Classifier

  • Linear SVM Classifier

for regression, candidate algorithms include:

  • Ridge Regression

  • Random Forest Regressor

  • SGD Regressor

this allows the agent to compare alternatives using actual evaluation results instead of guessing which model performs best.


5. generate_pipeline_code

generates reusable scikit-learn pipeline code grounded in:

  • loaded dataset

  • target column

  • problem type

  • selected algorithm

  • numeric features

  • categorical features

generated code includes preprocessing and estimator construction so the workflow can be moved beyond the interactive application.

App Fallback

app also includes a non-agent fallback path.

HF_TOKEN configured?
        β”‚
    β”Œβ”€β”€β”€β”΄β”€β”€β”€β”
    β”‚       β”‚
   yes      no
    β”‚       β”‚
    β–Ό       β–Ό
Qwen agent  fallback
tool loop      β”‚
    β”‚          β”œβ”€β”€ inspect dataset
    β”‚          β”œβ”€β”€ infer modeling setup
    β”‚          β”œβ”€β”€ train baseline model
    β”‚          β”œβ”€β”€ calculate real metrics
    β”‚          └── generate pipeline code
    β”‚
    └──────────┬──────────
               β–Ό
            UI output

fallback can also be used if the Hugging Face model request fails.

this means the application can still:

  • profile the dataset

  • infer a modeling setup

  • train the selected baseline

  • calculate real holdout metrics

  • generate scikit-learn pipeline code

without requiring the Qwen agent to successfully complete the tool-calling workflow.

Dataset Support

app can preload a public Hugging Face dataset or accept a user-uploaded dataset.

uploaded dataset files can include:

  1. CSV
  2. Parquet
  3. JSON
  4. JSONL
  5. XLSX
  6. XLS

the app profiles the dataset before exposing it to the ML workflow.

Hugging Face Example Dataset

default public example dataset:

scikit-learn/adult-census-income

default prediction target:

income

the sample dataset is intended for binary classification.

users can replace the preloaded example with their own supported dataset through the upload interface.

Preprocessing Pipeline

the scikit-learn workflow separates numerical and categorical processing.

numeric features
      ↓
median imputation
      ↓
scaling when appropriate


categorical features
      ↓
most-frequent imputation
      ↓
one-hot encoding


numeric + categorical features
      ↓
ColumnTransformer
      ↓
selected estimator
      ↓
trained Pipeline

this keeps preprocessing and model inference inside the same reusable scikit-learn pipeline.

Model Lab

Classification Algorithms

  • Logistic Regression

  • Random Forest Classifier

  • SGD Classifier

  • Linear SVM Classifier

Regression Algorithms

  • Ridge Regression

  • Random Forest Regressor

  • SGD Regressor

the selected algorithm is trained locally through automated scikit-learn pipelines.

Evaluation

Classification Metrics

classification evaluation can include:

Regression Metrics

regression evaluation includes:

  • MAE

    • ml regression evaluation metric used to measure the average magnitude of prediction errors in machine learning regression models
  • RMSE

    • ml regression evaluation metric used to measure the average magnitude of error in regression machine learning models
  • RΒ²

    • ml regression evaluation metric that measures the goodness of fit for a regression model by showing the proportion of variance in the dependent target variable that is explained by the independent features

note: evaluation values are produced by the local scikit-learn execution layer rather than estimated by the LLM.

Agent Outputs

final agent response is designed to contain:

  1. ML assessment
  2. Modeling risks
  3. Recommended modeling setup
  4. Evaluation findings
  5. Model comparison
  6. Pipeline recommendation
  7. Generated scikit-learn code
  8. Tool trace

app separately exposes structured modeling outputs such as:

  • metrics

  • leaderboard

  • feature importance / coefficients

  • pipeline code

  • model artifact

  • tool trace

  • runtime diagnostics

Agent Metrics / UI

1. Dataset Workspace

dataset workspace shows:

Dataset source

  • Hugging Face example-dataset loading

  • local file upload

Data preview

  • preview of the currently loaded dataset

Inferred schema / feature information

  • column

  • pandas dtype

  • numeric / categorical feature information

  • null information

  • unique-value information

  • example values

  • possible target columns


2. Model Lab

model workspace allows the user to configure:

Target column

  • selected prediction target

Problem type

  • classification

  • regression

Algorithmic Selection:

classification:

  • Logistic Regression

    • classification based supervised ML algorithm used to predict the probability of a categorical target variable
  • Random Forest Classifier

    • ensemble ML algorithm that builds multiple decision trees and combines their predictions to improve accuracy and reduce overfitting
  • SGD Classifier

    • efficient ML estimator that optimizes regularized linear models using a first-order optimization routine. Instead of a distinct machine learning algorithm itself, it represents an optimization methodology used to train traditional linear models like Support Vector Machines (SVM) or Logistic Regression
  • Linear SVM Classifier

    • supervised ML algorithm used to sort data into discrete categories by drawing a straight decision boundary

regression:

  • Ridge Regression

    • L2 regularization, is a modified version of linear regression designed to improve a model's stability and prevent overfitting.
    • standard linear regression only focuses on minimizing the difference between predicted and actual values, it often becomes unstable when dealing with highly correlated variables (multicollinearity) or a large number of features. Ridge regression fixes this by penalizing the model for having excessively large coefficients, forcing them to shrink toward zero.
  • Random Forest Regressor

    • ensemble machine learning algorithm used to predict continuous numerical values (e.g. housing prices, temperatures, or stock trends). algorithm works by building multiple independent decision trees at training time and outputting the average prediction of all the individual trees. this method, known as Bootstrap Aggregating (Bagging), reduces overfitting and improves model accuracy
  • SGD Regressor:

    • linear regression model trained using Stochastic Gradient Descent (SGD), an iterative optimization technique that updates model parameters one sample at a time rather than using the entire dataset at once
    • how SGD Regressor Works
      • Sample-by-Sample Updates: estimates the gradient of the loss function using a single randomly chosen data point (or a small mini-batch) per step, then adjusts the weights immediately.
      • Loss Functions: supports ordinary least squares (squared_error), robust regression (huber), and linear support vector regression (epsilon_insensitive).
      • Regularization: includes penalties like L2 (ridge), L1 (lasso), or a mix of both (elasticnet) to shrink weights and avoid overfitting.
      • Key Advantages:
        • Speed with Big Data: trains much faster than traditional batch gradient descent when dealing with massive datasets containing over 10,000 samples.
        • Online Learning: supports partial_fit, meaning it can continuously learn from real-time data streams as new information arrives.
        • Escaping Local Minima: inherent noise in single-sample updates helps the algorithm jump out of shallow local minimums in complex cost surfaces.

app can then expose:

  • fitted model metrics

  • feature importance or coefficients

  • generated pipeline artifact

  • generated pipeline code


3. Model Comparison

comparison workflow trains compatible baseline estimators and returns a leaderboard using real holdout results.

this provides a comparison layer that the LLM can reference during final synthesis.

the comparison values are derived from actual model execution instead of LLM-generated estimates.


4. Machine Learning Agent

agent workspace accepts a natural-language ML engineering task.

Qwen agent can then:

  • inspect the dataset

  • recommend a modeling setup

  • train a candidate model

  • compare algorithms

  • generate pipeline code

  • synthesize findings from tool observations


5. Tool Trace

every agent tool invocation is appended to the tool trace.

Example trace:

[
  {
    "tool": "inspect_dataset",
    "arguments": {},
    "result": {
      "rows": 32561,
      "columns": 15
    }
  },
  {
    "tool": "train_candidate_model",
    "arguments": {
      "target": "income",
      "algorithm": "Logistic Regression"
    },
    "result": {
      "metrics": "holdout metrics"
    }
  }
]

trace allows the user to analyze / inspect:

  • which tools were called

  • arguments passed to each tool

  • tool observations

  • number of tool calls

  • modeling operations performed during the agent loop


6. Diagnostics

runtime diagnostics can include:

  • model

  • provider

  • HF token configured

  • tool-call count

  • tools used

  • selected algorithm

  • problem type

  • target

Example:

{
  "model": "Qwen/Qwen3-Coder-30B-A3B-Instruct",
  "provider": "HF automatic routing",
  "hf_token_configured": true,
  "tool_calls": 4,
  "tools_used": [
    "inspect_dataset",
    "recommend_modeling_setup",
    "train_candidate_model",
    "compare_algorithms"
  ],
  "target": "income",
  "problem_type": "classification",
  "algorithm": "Logistic Regression"
}

the provider can appear as:

HF automatic routing

when a specific inference provider is not explicitly configured.

Local ML Execution Model

model training is performed directly inside the application with scikit-learn.

Loaded dataset
      ↓
pandas DataFrame
      ↓
feature / target split
      ↓
scikit-learn preprocessing
      ↓
scikit-learn estimator
      ↓
local CPU training
      ↓
holdout predictions
      ↓
evaluation metrics
      ↓
Joblib artifact

Qwen3-Coder does not perform the numerical model fitting itself.

Qwen3-Coder
    ↓
reasoning + tool selection + synthesis

scikit-learn
    ↓
preprocessing + training + prediction + evaluation

this keeps model-performance claims grounded in real execution.

Machine Learning Execution Separation

Qwen3-Coder

responsible for:

  • understanding the user's ML task

  • selecting appropriate tools

  • interpreting dataset observations

  • reasoning about modeling risks

  • deciding whether additional tools are required

  • synthesizing the final response

scikit-learn

responsible for:

  • preprocessing

  • train / holdout splitting

  • fitting estimators

  • making predictions

  • calculating evaluation metrics

  • model comparison

  • fitted-pipeline generation

conceptually:

User task
   ↓
Qwen3-Coder
   ↓
Select ML operation
   ↓
scikit-learn tool
   ↓
Real execution result
   ↓
Qwen3-Coder
   ↓
Interpret result / select next tool
   ↓
Final ML assessment

File Descriptions

agent.py

main agent implementation.

contains the logic for:

  • system prompt

  • tool schemas

  • MachineLearningAgent

  • tool dispatch

  • fallback

  • bounded agent loop

  • HF InferenceClient requests

  • tool_choice="auto"

  • tool observations

  • final response synthesis

architecturally:

agent.py
   ↓
decides WHAT ML action is needed
   ↓
ml_engine.py
   ↓
executes the ML operation

ml_engine.py

machine learning execution layer.

contains:

  • dataset loading

  • dataset profiling

  • target inference

  • problem-type inference

  • feature separation

  • preprocessing construction

  • algorithm construction

  • train / holdout splitting

  • model fitting

  • prediction

  • evaluation

  • model comparison

  • feature importance / coefficients

  • pipeline-code generation

  • Joblib artifact generation

architecturally:

agent.py
   ↓
decides WHAT ML action is needed
   ↓
ml_engine.py
   ↓
executes preprocessing / training / evaluation
   ↓
returns structured observation

app.py

responsibilities include:

  • session state

  • Hugging Face sample loading

  • local dataset upload

  • dataset preview

  • target controls

  • problem-type controls

  • algorithm controls

  • training callbacks

  • comparison callbacks

  • generated-code display

  • downloadable model artifact

  • agent execution

  • tool-trace display

  • runtime diagnostics


config.py

agent and application runtime configuration.

controls values such as:

HF_MODEL_ID

HF_PROVIDER

HF_TOKEN

MAX_UPLOAD_MB

MAX_PROFILE_ROWS

MAX_TRAIN_ROWS

MAX_AGENT_STEPS

DEFAULT_MAX_TOKENS

RANDOM_STATE

Modeling Guardrails

application separates LLM reasoning from numerical machine learning execution.

Qwen agent can decide which operation should be performed, but:

training

prediction

evaluation

metric calculation

model comparison

are handled by scikit-learn execution tools.

this architecture helps prevent fabricated model-performance claims.

additional controls include:

  • bounded agent steps

  • configurable maximum model tokens

  • fixed random state by default

  • controlled algorithm list

  • maximum training-row limit

  • deterministic / structured preprocessing behavior

  • fallback execution path

  • tool trace

  • structured model observations

Model Performance Grounding

the system is designed so the LLM does not invent model metrics.

Dataset
   ↓
scikit-learn model training
   ↓
Prediction
   ↓
Metric calculation
   ↓
Structured tool observation
   ↓
Qwen3-Coder
   ↓
Final interpretation

performance values should only be presented as real model results when the associated training / evaluation tool successfully executes.

if the tool does not run successfully, the final response should not claim that a model was trained or evaluated.

Model Artifact

trained preprocessing + estimator pipelines can be serialized through Joblib.

Numeric preprocessing
        +
Categorical preprocessing
        +
Estimator
        ↓
scikit-learn Pipeline
        ↓
fit
        ↓
Joblib serialization
        ↓
.joblib artifact

this allows the fitted pipeline to be reused later without manually rebuilding preprocessing and estimator logic.

Agent Pattern Workflow:

Single Agent
    +
Function Calling
    +
Machine Learning Tools
    +
Bounded Tool Loop
    +
Tool Observations
    +
Final LLM Synthesis

full execution:

USER
 ↓
Gradio / app.py
 ↓
MachineLearningAgent / agent.py
 ↓
Qwen3-Coder
 ↓
tool_choice="auto"
 ↓
ML Tool
 ↓
ml_engine.py
 ↓
Observation
 ↓
Qwen3-Coder
 ↓
repeat up to MAX_AGENT_STEPS
 ↓
Final ML Assessment
 ↓
Recommended modeling setup
 ↓
Evaluation findings
 ↓
Model comparison
 ↓
Pipeline code
 ↓
Tool Trace

Core Runtime Components

scikit-learn

What it is:

scikit-learn ml framework used to build preprocessing pipelines, estimators, training workflows, predictions, and evaluation metrics.

Why it is used in this project:

the application needs a real ML execution layer so model-performance values come from fitted models rather than LLM estimates.

How it is used here:

Dataset
   ↓
Preprocessing
   ↓
Estimator
   ↓
scikit-learn Pipeline
   ↓
Training
   ↓
Holdout prediction
   ↓
Holdout evaluation
   ↓
Metrics + fitted artifact

scikit-learn is used to:

  • build numeric preprocessing

  • build categorical preprocessing

  • combine transformations through ColumnTransformer

  • build estimator pipelines

  • split datasets into train and holdout sets

  • fit models

  • generate predictions

  • calculate classification metrics

  • calculate regression metrics

  • compare candidate estimators

  • expose supported feature importance / coefficient values

  • produce reusable fitted model pipelines

pandas

Why it is used in this project:

the application needs a lightweight in-memory tabular representation before datasets can be profiled and passed into scikit-learn.

How it is used here:

  • load supported dataset formats

  • hold the active dataset in memory

  • inspect columns and pandas data types

  • determine numerical and categorical features

  • analyze null values

  • inspect unique values

  • separate prediction target from model features

  • provide training data to scikit-learn

workflow:

Uploaded / HF dataset
        ↓
pandas DataFrame
        ↓
Dataset profiling
        ↓
Feature + target identification
        ↓
scikit-learn

Joblib

What it is:

Joblib is used to serialize fitted Python machine learning objects

Why it is used in this project:

a trained model is more useful when the complete preprocessing + estimator pipeline can be reused outside the interactive session.

How it is used here:

Fitted preprocessing
        +
Fitted estimator
        ↓
scikit-learn Pipeline
        ↓
Joblib
        ↓
.joblib model artifact

after training, the fitted preprocessing + estimator pipeline can be exported as a .joblib artifact for later reuse.

PyArrow

What it is:

PyArrow provides support for Apache Arrow / Parquet-based data interchange.

How it is used here:

PyArrow supports loading Parquet datasets into the application's pandas-based dataset workflow.

Parquet file
     ↓
PyArrow support
     ↓
pandas DataFrame
     ↓
ML workflow

OpenPyXL

What it is:

OpenPyXL provides Python support for reading Excel workbook formats used by the dataset upload workflow.

How it is used here:

XLSX dataset
     ↓
OpenPyXL
     ↓
pandas
     ↓
Dataset profile
     ↓
ML workflow

HF Automatic Routing

What it is:

Hugging Face automatic routing allows InferenceClient to route the Qwen model request through an available Hugging Face Inference Provider when a specific provider is not explicitly configured.

Why it is used:

it avoids coupling the application to one inference backend and simplifies deployment of the agent.

How it is used here:

MachineLearningAgent
      ↓
huggingface_hub.InferenceClient
      ↓
provider="auto"
      ↓
Hugging Face Inference Provider
      ↓
Qwen3-Coder
      ↓
tool request or final synthesis

model configuration is controlled through:

HF_MODEL_ID

HF_PROVIDER

HF_TOKEN

within this project:

  • HF_MODEL_ID identifies the Qwen model

  • HF_PROVIDER can configure provider behavior

  • automatic routing can be used when a specific backend is not forced

  • the routed model performs tool selection, reasoning, and final synthesis

  • scikit-learn performs the actual numerical ML operations

Training / Evaluation Architecture

Dataset
    ↓
pandas
    ↓
Feature / target split
    ↓
Train / holdout split
    ↓
ColumnTransformer
    ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Numeric preprocessing      β”‚
β”‚                            β”‚
β”‚ median imputation          β”‚
β”‚ optional scaling           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              +
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Categorical preprocessing  β”‚
β”‚                            β”‚
β”‚ most-frequent imputation   β”‚
β”‚ one-hot encoding           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    ↓
Estimator
    ↓
scikit-learn Pipeline
    ↓
   fit
    ↓
holdout prediction
    ↓
evaluation metrics
    ↓
Agent observation

Classification Workflow

Classification Dataset
        ↓
 Target Selection
        ↓
 Preprocessing
        ↓
Candidate classifier
        ↓
    Training
        ↓
Holdout predictions
        ↓
    accuracy
weighted precision
 weighted recall
   weighted F1
ROC-AUC where supported
        ↓
Agent interpretation

supported baseline classifiers include:

  • Logistic Regression

  • Random Forest Classifier

  • SGD Classifier

  • Linear SVM Classifier

Regression Workflow

Regression dataset
        ↓
Target selection
        ↓
  Preprocessing
        ↓
Candidate regressor
        ↓
    Training
        ↓
Holdout predictions
        ↓
       MAE
      RMSE
       RΒ²
        ↓
Agent interpretation

supported baseline regressors include:

  • Ridge Regression

  • Random Forest Regressor

  • SGD Regressor