Haicaji commited on
Commit
9f14291
·
1 Parent(s): 21352a0

Retrain model from records csv

Browse files
Files changed (4) hide show
  1. README.md +5 -4
  2. timeout_model.json +43 -43
  3. timeout_risk_model.py +6 -1
  4. train.py +1 -1
README.md CHANGED
@@ -10,10 +10,11 @@ from the order time.
10
 
11
  ## Data Assumption
12
 
13
- `timeout_records.csv` in the Dataset repository only stores timeout orders, so
14
- the first model artifact is a positive-only time-risk model. After users submit
15
- both timeout and non-timeout records through the Space, retraining will switch to
16
- `labeled_empirical_bayes`, which is closer to a calibrated probability model.
 
17
 
18
  ## Train
19
 
 
10
 
11
  ## Data Assumption
12
 
13
+ `records.csv` in the Dataset repository stores the manually maintained base
14
+ records. When both timeout and non-timeout samples are present, retraining uses
15
+ `labeled_empirical_bayes`, which is closer to a calibrated probability model. If
16
+ only timeout samples are available, the artifact remains a positive-only
17
+ time-risk model.
18
 
19
  ## Train
20
 
timeout_model.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "base_probability": 0.35,
3
- "generated_at": "2026-05-23T18:07:51.470272+00:00",
4
  "hour_probabilities": {
5
  "0": {
6
  "positive_count": 0,
@@ -14,53 +14,53 @@
14
  },
15
  "10": {
16
  "positive_count": 0,
17
- "probability": 0.1391,
18
- "smoothed_density": 0.028
19
  },
20
  "11": {
21
  "positive_count": 0,
22
- "probability": 0.1963,
23
- "smoothed_density": 0.1121
24
  },
25
  "12": {
26
  "positive_count": 1,
27
- "probability": 0.3043,
28
- "smoothed_density": 0.271
29
  },
30
  "13": {
31
  "positive_count": 1,
32
- "probability": 0.3043,
33
- "smoothed_density": 0.271
34
  },
35
  "14": {
36
- "positive_count": 0,
37
- "probability": 0.1963,
38
- "smoothed_density": 0.1121
39
  },
40
  "15": {
41
  "positive_count": 0,
42
- "probability": 0.2153,
43
- "smoothed_density": 0.1402
44
  },
45
  "16": {
46
  "positive_count": 0,
47
- "probability": 0.406,
48
- "smoothed_density": 0.4206
49
  },
50
  "17": {
51
- "positive_count": 4,
52
  "probability": 0.8,
53
  "smoothed_density": 1.0
54
  },
55
  "18": {
56
  "positive_count": 3,
57
- "probability": 0.7301,
58
- "smoothed_density": 0.8972
59
  },
60
  "19": {
61
- "positive_count": 0,
62
- "probability": 0.3679,
63
- "smoothed_density": 0.3645
64
  },
65
  "2": {
66
  "positive_count": 0,
@@ -68,19 +68,19 @@
68
  "smoothed_density": 0.0
69
  },
70
  "20": {
71
- "positive_count": 0,
72
- "probability": 0.1772,
73
- "smoothed_density": 0.0841
74
  },
75
  "21": {
76
  "positive_count": 0,
77
- "probability": 0.12,
78
- "smoothed_density": 0.0
79
  },
80
  "22": {
81
  "positive_count": 0,
82
- "probability": 0.12,
83
- "smoothed_density": 0.0
84
  },
85
  "23": {
86
  "positive_count": 0,
@@ -132,19 +132,19 @@
132
  "optional product name"
133
  ],
134
  "non_timeout_records": 0,
135
- "timeout_records": 9,
136
- "training_records": 9
137
  },
138
  "mode": "positive_only_time_density",
139
  "model_version": 1,
140
  "product_probabilities": {},
141
  "time_bucket_probabilities": {
142
  "afternoon": {
143
- "positive_count": 0,
144
- "probability": 0.16
145
  },
146
  "dinner": {
147
- "positive_count": 7,
148
  "probability": 0.7
149
  },
150
  "late_night": {
@@ -153,21 +153,21 @@
153
  },
154
  "lunch": {
155
  "positive_count": 2,
156
- "probability": 0.3143
157
  },
158
  "morning": {
159
  "positive_count": 0,
160
  "probability": 0.16
161
  },
162
  "night": {
163
- "positive_count": 0,
164
- "probability": 0.16
165
  }
166
  },
167
  "weekday_probabilities": {
168
  "0": {
169
- "positive_count": 0,
170
- "probability": 0.18
171
  },
172
  "1": {
173
  "positive_count": 0,
@@ -178,8 +178,8 @@
178
  "probability": 0.29
179
  },
180
  "3": {
181
- "positive_count": 1,
182
- "probability": 0.29
183
  },
184
  "4": {
185
  "positive_count": 4,
@@ -190,8 +190,8 @@
190
  "probability": 0.51
191
  },
192
  "6": {
193
- "positive_count": 0,
194
- "probability": 0.18
195
  }
196
  }
197
  }
 
1
  {
2
  "base_probability": 0.35,
3
+ "generated_at": "2026-05-25T08:33:53.609270+00:00",
4
  "hour_probabilities": {
5
  "0": {
6
  "positive_count": 0,
 
14
  },
15
  "10": {
16
  "positive_count": 0,
17
+ "probability": 0.1357,
18
+ "smoothed_density": 0.0231
19
  },
20
  "11": {
21
  "positive_count": 0,
22
+ "probability": 0.1828,
23
+ "smoothed_density": 0.0923
24
  },
25
  "12": {
26
  "positive_count": 1,
27
+ "probability": 0.3031,
28
+ "smoothed_density": 0.2692
29
  },
30
  "13": {
31
  "positive_count": 1,
32
+ "probability": 0.3658,
33
+ "smoothed_density": 0.3615
34
  },
35
  "14": {
36
+ "positive_count": 2,
37
+ "probability": 0.392,
38
+ "smoothed_density": 0.4
39
  },
40
  "15": {
41
  "positive_count": 0,
42
+ "probability": 0.3083,
43
+ "smoothed_density": 0.2769
44
  },
45
  "16": {
46
  "positive_count": 0,
47
+ "probability": 0.4338,
48
+ "smoothed_density": 0.4615
49
  },
50
  "17": {
51
+ "positive_count": 5,
52
  "probability": 0.8,
53
  "smoothed_density": 1.0
54
  },
55
  "18": {
56
  "positive_count": 3,
57
+ "probability": 0.732,
58
+ "smoothed_density": 0.9
59
  },
60
  "19": {
61
+ "positive_count": 1,
62
+ "probability": 0.4914,
63
+ "smoothed_density": 0.5462
64
  },
65
  "2": {
66
  "positive_count": 0,
 
68
  "smoothed_density": 0.0
69
  },
70
  "20": {
71
+ "positive_count": 1,
72
+ "probability": 0.3188,
73
+ "smoothed_density": 0.2923
74
  },
75
  "21": {
76
  "positive_count": 0,
77
+ "probability": 0.1828,
78
+ "smoothed_density": 0.0923
79
  },
80
  "22": {
81
  "positive_count": 0,
82
+ "probability": 0.1357,
83
+ "smoothed_density": 0.0231
84
  },
85
  "23": {
86
  "positive_count": 0,
 
132
  "optional product name"
133
  ],
134
  "non_timeout_records": 0,
135
+ "timeout_records": 14,
136
+ "training_records": 14
137
  },
138
  "mode": "positive_only_time_density",
139
  "model_version": 1,
140
  "product_probabilities": {},
141
  "time_bucket_probabilities": {
142
  "afternoon": {
143
+ "positive_count": 2,
144
+ "probability": 0.28
145
  },
146
  "dinner": {
147
+ "positive_count": 9,
148
  "probability": 0.7
149
  },
150
  "late_night": {
 
153
  },
154
  "lunch": {
155
  "positive_count": 2,
156
+ "probability": 0.28
157
  },
158
  "morning": {
159
  "positive_count": 0,
160
  "probability": 0.16
161
  },
162
  "night": {
163
+ "positive_count": 1,
164
+ "probability": 0.22
165
  }
166
  },
167
  "weekday_probabilities": {
168
  "0": {
169
+ "positive_count": 2,
170
+ "probability": 0.4
171
  },
172
  "1": {
173
  "positive_count": 0,
 
178
  "probability": 0.29
179
  },
180
  "3": {
181
+ "positive_count": 2,
182
+ "probability": 0.4
183
  },
184
  "4": {
185
  "positive_count": 4,
 
190
  "probability": 0.51
191
  },
192
  "6": {
193
+ "positive_count": 2,
194
+ "probability": 0.4
195
  }
196
  }
197
  }
timeout_risk_model.py CHANGED
@@ -22,6 +22,7 @@ MODEL_VERSION = 1
22
  CSV_FIELDS = [
23
  "product_name",
24
  "order_time",
 
25
  "is_timeout",
26
  "expected_latest_time",
27
  "actual_arrival_time",
@@ -133,7 +134,11 @@ def read_csv_records(path: Path, forced_timeout: bool | None = None) -> list[Tra
133
 
134
  def load_dataset_records(dataset_dir: str | Path) -> list[TrainingRecord]:
135
  dataset_path = Path(dataset_dir)
136
- records = read_csv_records(dataset_path / "timeout_records.csv", forced_timeout=True)
 
 
 
 
137
 
138
  tmp_dir = dataset_path / "tmp"
139
  if tmp_dir.exists():
 
22
  CSV_FIELDS = [
23
  "product_name",
24
  "order_time",
25
+ "timeout",
26
  "is_timeout",
27
  "expected_latest_time",
28
  "actual_arrival_time",
 
134
 
135
  def load_dataset_records(dataset_dir: str | Path) -> list[TrainingRecord]:
136
  dataset_path = Path(dataset_dir)
137
+ records_path = dataset_path / "records.csv"
138
+ if records_path.exists():
139
+ records = read_csv_records(records_path, forced_timeout=None)
140
+ else:
141
+ records = read_csv_records(dataset_path / "timeout_records.csv", forced_timeout=True)
142
 
143
  tmp_dir = dataset_path / "tmp"
144
  if tmp_dir.exists():
train.py CHANGED
@@ -25,7 +25,7 @@ def download_dataset_snapshot(repo_id: str) -> Path:
25
  repo_id=repo_id,
26
  repo_type="dataset",
27
  local_dir=str(target_dir),
28
- allow_patterns=["timeout_records.csv", "tmp/*.csv"],
29
  )
30
  return target_dir
31
 
 
25
  repo_id=repo_id,
26
  repo_type="dataset",
27
  local_dir=str(target_dir),
28
+ allow_patterns=["records.csv", "timeout_records.csv", "tmp/*.csv"],
29
  )
30
  return target_dir
31