展开本页目录
开始前准备什么
- 独立练习目录及Python 3.14;系统与Node依赖以README为准。
- 离线重放无需Key;新请求使用自己的apizt Key,先核对模型权限和当前价格。
- 原创合成材料,不需要登录第三方平台账号。
- 先看文件
- 按步骤操作
- 对照真实结果
- 离线或模型复跑
默认离线重放;包含完整失败尝试与本地检查,不含Key。
1. 核对本例材料与目标文件
不同于复购率与KMeans分群,验收cohort分母固定。需人工重叠复核。
先下载合成材料在独立目录练习。原始文件、模型输入与验收答案分别保留;本地核对答案不发送给模型。
input.json(节选)
{
"definition": "只统计已完成订单,cancelled排除。每位客户第一个completed订单的月份是cohort,后续completed月份算活跃。",
"orders": [
{
"id": "1",
"customer": "A",
"month": "2026-07",
"state": "completed"
},
{
"id": "2",
"customer": "A",
"month": "2026-08",
"state": "completed"
},
{
"id": "3",
"customer": "B",
"month": "2026-07",
"state": "cancelled"
},
{
"id": "4",
"customer": "B",
"month": "2026-08",
"state": "completed"
},
{
"id": "5",
"customer": "C",
"month": "2026-07",
"state": "completed"
},
{
"id": "6",
"customer": "C",
"month": "2026-09",
"state": "completed"
}
],
"observed_through": "2026-09-30"
}2. 按顺序完成这项具体操作
本次实际使用Python 3.14,依赖版本固定在资料包。需要LibreOffice或Node的案例请先按README安装对应运行时。python run.py读取真实旧响应完成本地处理;只有显式--live才发新请求。
- 1. 查看 source-orders.csv,按原始客户ID区分已完成与cancelled订单,并确认观测窗口完整截至2026-09-30。
- 2. 让 apizt 提取统计口径:仅排除cancelled,以首个completed订单确定首购月份,后续completed月份判为活跃。
- 3. 由程序找每位客户的首次完成月份,再按cohort与相对月份统计去重客户ID;B的取消首单不决定其首购cohort。
- 4. 打开 cohort-matrix.csv,检查七月cohort分母始终为A/C两人,八月与九月各有一人活跃;同时保留每格customer_ids供回查。
- 5. 核对B归入八月而非七月,且不输出完整观测窗口以后的月份;未来未观测数据不能被填成零留存。
独立练习目录 · 默认仅离线复核
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
python run.py3. 对照真正发送的请求
只处理给定原创虚构材料,只输出JSON。把统计约定输出为exclude_statuses数组、cohort_basis和activity_basis。只排除cancelled;首购定义first_completed_order,活跃定义completed_order。不要算留存率。 输出结构:{"exclude_statuses": ["string"], "cohort_basis": "string", "activity_basis": "string"}
网页实验台只执行这一步模型字段检查。原生文件写入、坐标/公式/格式回读及负例验收由下载包负责。
request-1.json(图片Base64省略,原文件在下载包)
{
"model": "gemini-2.5-flash-lite",
"messages": [
{
"role": "system",
"content": "严格只输出单个JSON对象,不要Markdown代码围栏,不要解释。只处理给定原创虚构材料,只输出JSON。把统计约定输出为exclude_statuses数组、cohort_basis和activity_basis。只排除cancelled;首购定义first_completed_order,活跃定义completed_order。不要算留存率。 输出结构:{\"exclude_statuses\": [\"string\"], \"cohort_basis\": \"string\", \"activity_basis\": \"string\"}"
},
{
"role": "user",
"content": "任务约束(只输出JSON对象,不用代码围栏):\n只处理给定原创虚构材料,只输出JSON。把统计约定输出为exclude_statuses数组、cohort_basis和activity_basis。只排除cancelled;首购定义first_completed_order,活跃定义completed_order。不要算留存率。 输出结构:{\"exclude_statuses\": [\"string\"], \"cohort_basis\": \"string\", \"activity_basis\": \"string\"}\n待处理合成材料:\n{\"definition\": \"只统计已完成订单,cancelled排除。每位客户第一个completed订单的月份是cohort,后续completed月份算活跃。\", \"orders\": [{\"id\": \"1\", \"customer\": \"A\", \"month\": \"2026-07\", \"state\": \"completed\"}, {\"id\": \"2\", \"customer\": \"A\", \"month\": \"2026-08\", \"state\": \"completed\"}, {\"id\": \"3\", \"customer\": \"B\", \"month\": \"2026-07\", \"state\": \"cancelled\"}, {\"id\": \"4\", \"customer\": \"B\", \"month\": \"2026-08\", \"state\": \"completed\"}, {\"id\": \"5\", \"customer\": \"C\", \"month\": \"2026-07\", \"state\": \"completed\"}, {\"id\": \"6\", \"customer\": \"C\", \"month\": \"2026-09\", \"state\": \"completed\"}], \"observed_through\": \"2026-09-30\"}"
}
],
"temperature": 0,
"max_tokens": 1024,
"provider": {
"sort": "success_rate"
},
"response_format": {
"type": "json_object"
}
}4. 查看原生处理代码与实际文件
下面节选来自本次实际执行的workflow.py分支,需要结合完整脚本运行。模型输出不能代替文件解析器或业务验算。
具体产物:cohort-matrix.csv、result.json、checks.json、preview.html。
workflow.py · 本例分支节选
accepted = [r for r in data['orders'] if r['state'] not in output['exclude_statuses']]
first = {}
for r in accepted:
first[r['customer']] = min(first.get(r['customer'], r['month']), r['month'])
def delta(a, b):
return (int(b[:4]) - int(a[:4])) * 12 + int(b[5:]) - int(a[5:])
cohorts = defaultdict(set)
active = defaultdict(set)
for customer, month in first.items():
cohorts[month].add(customer)
for r in accepted:
active[first[r['customer']], delta(first[r['customer']], r['month'])].add(r['customer'])
months = sorted(cohorts)
horizon = data['observed_through'][:7]
matrix = []
for month in months:
for offset in range(delta(month, horizon) + 1):
ids = sorted(active[month, offset])
matrix.append({'cohort': month, 'month_index': offset, 'denominator': len(cohorts[month]), 'active_customers': len(ids), 'customer_ids': ids, 'retention': str(D(len(ids)) / D(len(cohorts[month])))})
check('取消首单不决定客户B所属cohort', first['B'] == '2026-08')
check('七月cohort分母始终两人', all((r['denominator'] == 2 for r in matrix if r['cohort'] == '2026-07')))
check('月份去重后同客户只算一次', next((r for r in matrix if r['cohort'] == '2026-07' and r['month_index'] == 1))['active_customers'] == 1)
cout('cohort-matrix.csv', matrix)
result = {'first_completed_month': first, 'matrix': matrix}5. 对照真实结果和检查表
实测2026-10-25T07:51:09.815213+00:00,HTTP200;请求gemini-2.5-flash-lite,返回gemini-2.5-flash-lite。本次5/5项检查通过,指本例执行及验收机制通过,不代表所有模型字段零误差。
最后一次返回用量463tokens;1份尝试记录的已知用量合计463。失败记录保留,用量缺失不按0计,本文不推算实际金额。
| 实际检查 | 结果 |
|---|---|
| 真实apizt API响应HTTP200 | 通过 |
| 模型结构化事实与原始材料一致 | 通过 |
| 取消首单不决定客户B所属cohort | 通过 |
| 七月cohort分母始终两人 | 通过 |
| 月份去重后同客户只算一次 | 通过 |
- 实际检查
- 真实apizt API响应HTTP200
- 结果
- 通过
- 实际检查
- 模型结构化事实与原始材料一致
- 结果
- 通过
- 实际检查
- 取消首单不决定客户B所属cohort
- 结果
- 通过
- 实际检查
- 七月cohort分母始终两人
- 结果
- 通过
- 实际检查
- 月份去重后同客户只算一次
- 结果
- 通过
result.json · 原生处理后实际结果
{
"first_completed_month": {
"A": "2026-07",
"B": "2026-08",
"C": "2026-07"
},
"matrix": [
{
"cohort": "2026-07",
"month_index": 0,
"denominator": 2,
"active_customers": 2,
"customer_ids": [
"A",
"C"
],
"retention": "1"
},
{
"cohort": "2026-07",
"month_index": 1,
"denominator": 2,
"active_customers": 1,
"customer_ids": [
"A"
],
"retention": "0.5"
},
{
"cohort": "2026-07",
"month_index": 2,
"denominator": 2,
"active_customers": 1,
"customer_ids": [
"C"
],
"retention": "0.5"
},
{
"cohort": "2026-08",
"month_index": 0,
"denominator": 1,
"active_customers": 1,
"customer_ids": [
"B"
],
"retention": "1"
},
{
"cohort": "2026-08",
"month_index": 1,
"denominator": 1,
"active_customers": 0,
"customer_ids": [],
"retention": "0"
}
]
}6. 替换输入前,先确认这些边界
本例只验证合成材料和本地原生文件;不连接真实客户数据,不代表第三方SaaS已运行。
修改材料后应重新制定事实断言和反例。识别错误率、混淆矩阵或拒答类教程允许保留模型实际错误;检查通过指计算和处理正确。没有调用视频模型。
怎样确认已经完成
- 真实apizt API响应HTTP200
- 模型结构化事实与原始材料一致
- 取消首单不决定客户B所属cohort
- 七月cohort分母始终两人
- 月份去重后同客户只算一次
常见问题
AI 客户留存 Cohort怎么开始?
查看 source-orders.csv,按原始客户ID区分已完成与cancelled订单,并确认观测窗口完整截至2026-09-30。按本页顺序继续,先用下载包离线重放,再替换自己的材料。
网页试跑和下载包有什么区别?
网页只复跑模型字段,不生成全部原生文件;资料包包含实际原生处理和本地验收。
这次通过结果适用于其他材料吗?
本例只验证合成材料和本地原生文件;不连接真实客户数据,不代表第三方SaaS已运行。


