-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredict_minimal.py
More file actions
48 lines (39 loc) · 1.47 KB
/
predict_minimal.py
File metadata and controls
48 lines (39 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
predict_minimal.py
------------------
Eğitilmiş minimal model ile tek bir e-postayı puanlar ve süreyi ölçer.
Kullanım:
python predict_minimal.py --subject "başlık" --text "gövde" --model spam_model_min.joblib
"""
import argparse
import joblib
import time
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--subject", required=True, help="E-posta başlığı")
ap.add_argument("--text", required=True, help="E-posta gövdesi")
ap.add_argument("--model", default="spam_model_min.joblib", help="Model dosyası")
ap.add_argument("--threshold", type=float, default=0.65, help="Spam eşiği (0-1)")
args = ap.parse_args()
# Modeli yükle
pipe = joblib.load(args.model)
# Subject + text birleştir
text = (args.subject or "") + " \n " + (args.text or "")
# Zaman ölçümü başla
start_time = time.time()
# Tahmin
if hasattr(pipe, "predict_proba"):
p = pipe.predict_proba([text])[:,1][0]
etiket = int(p >= args.threshold)
result = f"Olasılık (spam): {p:.4f} | Eşik: {args.threshold:.2f} | Tahmin: {'SPAM' if etiket else 'NORMAL'}"
else:
y = pipe.predict([text])[0]
result = f"Tahmin: {'SPAM' if int(y)==1 else 'NORMAL'} (Not: olasılık desteği yok)"
# Zaman ölçümü bitir
elapsed = time.time() - start_time
print(result)
print(f"Geçen süre: {elapsed:.4f} saniye")
if __name__ == "__main__":
main()