Churn: A Scikit-learn Pipeline Connected to a Groq LLM Agent

Le brief IA que les pros lisent chaque soir
Les 7 actus IA du jour, décryptées en 5 min. Gratuit.
Inclus dès l'inscription : notre sélection des meilleurs guides & comparatifs IA.
Choisis ton rythme
Gratuit · Pas de spam · Désabonnement en 1 clic
A Python workflow combines customer attrition prediction and automated actions. The model, trained on a synthetic dataset of 500 clients, achieves 91.0% accuracy on the test set before delegating decisions to an agent powered by a LLM accessible via Groq. The entire setup can be executed for free in Google Colab or locally, with simulated intervention tools such as sending discounts or escalating to a human.
The agent triggers two simulated retention actions
Two functions serve as tools that the agent is allowed to activate. The actions are simulated through parameterized messages: one sends a 20% discount code to the targeted customer, while the other indicates the escalation of the case to a human agent for follow-up. The tutorial specifies that the cognitive core of the agent handles reasoning and execution. The agent relies on a language model accessible via the Groq library to interpret predictions and select an action. A dedicated cognition class is initiated later in the code to orchestrate this sequence.
The model is trained on 400 records and shows 91.0%
The dataset is divided into training and testing with a test_size of 0.2 and a random_state of 42. The chosen classifier is a random forest configured with 50 estimators, a maximum depth of 5, and the same random seed. After training on 400 records, the accuracy measured on the test set reaches 91.0%. The guide considers this level sufficient to proceed with the integration of the agent.
A synthetic dataset of 500 clients, two variables, and a threshold of 0.5
The dataset includes 500 clients, each described by two explanatory variables and a binary attrition target. The two features are monthly spending and the number of support tickets issued by the client, with added random noise for realism. The generation fixes the seed at 42 and n_samples at 500. Spending follows a uniform distribution between 10 and 150, while tickets obey a Poisson distribution with a mean of 1.5. The base churn risk increases by 0.15 per ticket, rises by 0.3 if spending is below 30, and decreases by 0.2 if it exceeds 100. Gaussian noise with a mean of 0 and a standard deviation of 0.1 is added, and then the value is bounded between 0 and 1. The target is 1 if this risk exceeds 0.5 (0 indicates retention, 1 indicates attrition). The matrix X assembles spending and tickets in columns.
Run for free on Colab or Jupyter and configure Groq
The entire setup can run for free in Google Colab or locally in Jupyter, provided that the necessary libraries are installed and imported. In Colab, the guide indicates that groq can be the only dependency to add, via the provided installation command. The imports include numpy, RandomForestClassifier, and train_test_split from scikit-learn, as well as Groq. Access to the LLM via Groq requires an API key: the user must generate one, integrate it into the notebook or Colab, and then store it in the Secrets section under the name GROQ_API_KEY. The code illustrates the injection of this secret into the environment variables by importing os and userdata from google.colab and assigning the corresponding value to GROQ_API_KEY.
Linking a predictive model to an LLM agent to act
The tutorial aims to combine a classic machine learning pipeline with an agentic AI system to create an autonomous retention flow. It demonstrates how to train a predictive model with scikit-learn and then pass its results to a tool-equipped agent driven by a LLM to deduce and execute actions. The approach claims to shift from a primarily reactive processing chain to a system capable of reasoning and acting with limited human guidance. The chaining is accomplished within a single Python application, with the agent accessing a LLM via the Groq library.
Brief IA — L'actualité IA en français
L'essentiel de l'actualité de l'intelligence artificielle, décrypté et expliqué chaque jour.