KagChi commited on
Commit
ebd3a5d
·
verified ·
1 Parent(s): 5697faf

chore: update matrix

Browse files
Files changed (1) hide show
  1. main.py +4 -4
main.py CHANGED
@@ -198,13 +198,14 @@ async def confusion_matrix_image(model_type: str):
198
  if hf_dataset_cache is None:
199
  raise HTTPException(status_code=500, detail="Dataset not loaded")
200
 
 
201
  filtered_samples = [
202
  sample for sample in hf_dataset_cache
203
- if sample.get("text") and sample.get("label") == 1 and sample["text"].strip()
204
  ]
205
 
206
  if not filtered_samples:
207
- raise HTTPException(status_code=400, detail="No valid gambling samples found.")
208
 
209
  texts = [sample["text"] for sample in filtered_samples]
210
  labels = [sample["label"] for sample in filtered_samples]
@@ -213,7 +214,6 @@ async def confusion_matrix_image(model_type: str):
213
  X = vectorizer.fit_transform(texts)
214
  y = labels
215
 
216
- # For consistency, even though all y == 1, we still fit
217
  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
218
 
219
  if model_type == "naive-bayes":
@@ -226,7 +226,7 @@ async def confusion_matrix_image(model_type: str):
226
  clf.fit(X_train, y_train)
227
  y_pred = clf.predict(X_test)
228
 
229
- cm = confusion_matrix(y_test, y_pred, labels=[0, 1]) # keep both classes for consistency
230
  disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=["Bukan Judi", "Judi"])
231
 
232
  buf = io.BytesIO()
 
198
  if hf_dataset_cache is None:
199
  raise HTTPException(status_code=500, detail="Dataset not loaded")
200
 
201
+ # Include all labeled samples (both 0 and 1)
202
  filtered_samples = [
203
  sample for sample in hf_dataset_cache
204
+ if sample.get("text") and sample["text"].strip()
205
  ]
206
 
207
  if not filtered_samples:
208
+ raise HTTPException(status_code=400, detail="No valid samples found.")
209
 
210
  texts = [sample["text"] for sample in filtered_samples]
211
  labels = [sample["label"] for sample in filtered_samples]
 
214
  X = vectorizer.fit_transform(texts)
215
  y = labels
216
 
 
217
  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
218
 
219
  if model_type == "naive-bayes":
 
226
  clf.fit(X_train, y_train)
227
  y_pred = clf.predict(X_test)
228
 
229
+ cm = confusion_matrix(y_test, y_pred, labels=[0, 1])
230
  disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=["Bukan Judi", "Judi"])
231
 
232
  buf = io.BytesIO()