forge
Explore
Log in

Don't you dare go Hollow

hezarfen_zeka

Clone
★ 0

0 watching0 forksPython1.9 MiBe01a4faAhmet Kaan Gümüş2 months ago25 commits

pvalue_probe.py48 lines, 2.0 KiBHistoryRawDownload
1"""Ampirik madde zorlugunu (p-degeri) hesaplayabiliyor muyuz? Kucuk olcekli sinama."""
2import base64, json, time, urllib.request
3
4def sql(q, db="zeka"):
5 r = urllib.request.Request("http://hzk-surreal:8000/sql", data=q.encode("utf-8"))
6 r.add_header("Accept", "application/json")
7 r.add_header("Content-Type", "text/plain; charset=utf-8")
8 r.add_header("surreal-ns", "hezarfen"); r.add_header("surreal-db", db)
9 r.add_header("Authorization", "Basic " + base64.b64encode(b"root:root").decode())
10 with urllib.request.urlopen(r, timeout=600) as resp:
11 return json.loads(resp.read().decode("utf-8"))
12
13t0 = time.time()
14qs = sql("SELECT id, correct, subject, text FROM exam_question WHERE kind = 'choice' LIMIT 400;")[0]["result"]
15key = {q["id"]: q.get("correct") for q in qs}
16ids = list(key)
17print("soru cekildi: %d (%.1fs)" % (len(ids), time.time() - t0))
18
19t1 = time.time()
20rows = []
21CH = 100
22for i in range(0, len(ids), CH):
23 part = ids[i:i + CH]
24 lst = ", ".join(part)
25 res = sql("SELECT question, selected FROM exam_answer WHERE question IN [%s];" % lst)
26 rows.extend(res[0]["result"])
27print("cevap cekildi: %d (%.1fs)" % (len(rows), time.time() - t1))
28
29agg = {}
30for r in rows:
31 q = r.get("question")
32 if q is None:
33 continue
34 n, c = agg.get(q, (0, 0))
35 ok = 1 if r.get("selected") is not None and r.get("selected") == key.get(q) else 0
36 agg[q] = (n + 1, c + ok)
37
38ps = sorted((c / n) for n, c in agg.values() if n >= 10)
39if ps:
40 import statistics
41 print("p-degeri hesaplanan soru: %d" % len(ps))
42 print(" min %.2f | %%25 %.2f | medyan %.2f | %%75 %.2f | max %.2f"
43 % (ps[0], ps[len(ps)//4], statistics.median(ps), ps[3*len(ps)//4], ps[-1]))
44 print(" cok zor (p<0.30): %d | cok kolay (p>0.90): %d"
45 % (sum(1 for p in ps if p < .30), sum(1 for p in ps if p > .90)))
46 n_per = [n for n, _ in agg.values()]
47 print(" soru basina gozlem: min %d medyan %d max %d"
48 % (min(n_per), statistics.median(n_per), max(n_per)))