From 98c154771a6c7c9934251834e9ed51f03ac676eb Mon Sep 17 00:00:00 2001 From: Alexander Munch-Hansen Date: Sat, 6 Apr 2019 22:39:19 +0200 Subject: [PATCH] Worst svm ever --- .../strategies/nightness_classifier.pkl | Bin 0 -> 1640 bytes server/nightr/strategies/svm_strat.py | 26 ++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 server/nightr/strategies/nightness_classifier.pkl diff --git a/server/nightr/strategies/nightness_classifier.pkl b/server/nightr/strategies/nightness_classifier.pkl new file mode 100644 index 0000000000000000000000000000000000000000..554fa03defdbfcf8ed4507e416c2bfd519a9298d GIT binary patch literal 1640 zcmZuyU2GIp6rSD6Pp4F?R#5~MExJ${%a2;1IJQMs7+G<#FbaB^nZ3I+barOW%WfCRK1ejthrY<0nD|mP_JQbw1PR$Rq?+)c;?KQjw)>;KnarJg?)}dB z&d)tF-ev@&Hr0Gb3d%*vu(cqdfw*_yun5B1$z66|huW|NkNbKamZCUE3qGaLuCyVd zpcRW6h-vxcv7ggtyI+abxHR7f9ciWo2dW5N8%dJ7aXS+Srf)f;mQ#SPNwtFsJm1wd-LkE43~ruOMJ6&d!=xmz zj#0Qp`C47ZMLb;O2(=1k2)AZbZlO$l-3=&opHY{xWl=jytdRO}+pd4uK$x#NIk!lH zPzx#C9>YlBX+DE3Kcja3M>Byt>PezUnJ!1O1L?4<+mWgqEOX7+M?n)t>prj*bSZN?obaEO$F2X8|bez(=mE;86g96vjG4A)8ow&+{ zV=UvVYgk-~aG%OUo$rVH6+uayhMp{}NwIYDj10g7nM?*f$Co06@Su+2)NI>5LRhvv zNKKY>c9@Mhd45K^wQ?k|*5rPyi=a1Ut~6Jf$nYVP@iJGNF#)R|*2e^-EIiBznEyB3 zr<)C1g1{N_frUuo(%aA|J)XXxL${?*y@SLI*+Sa;}f_a*uFE0;ca=S{ZGO6<8Nw|}$!jZc64US2O=J3jON zv^=kO`lCc~#q^B4t#V>(<-~=$-c5y$*^9r;$X{OUWluwI@1ak|zes*n*L$IBq}p?K zNEpABID$y*`zhY~A?tRi6W z@NyEq1ACPuuZZXIENSv;1numLV1JVxwZ%>x5LSD<&yl9EzJS;lBREjU@~|FU0A0VQ e=dglF?H@u|^W*;rcnN*)lQwLTHp0s#UHTU&;REXc literal 0 HcmV?d00001 diff --git a/server/nightr/strategies/svm_strat.py b/server/nightr/strategies/svm_strat.py index 78a760c..58a17f6 100644 --- a/server/nightr/strategies/svm_strat.py +++ b/server/nightr/strategies/svm_strat.py @@ -6,10 +6,11 @@ import json import numpy as np -from server.nightr.strategies.strat_utils import write_json +from .strat_utils import write_json +from ..util import Context, Prediction -def find_data(time): +def write_data(time): write_json("https://portal.opendata.dk/api/3/action/datastore_search?resource_id=2a82a145-0195-4081-a13c-b0e587e9b89c", "parking_aarhus", time) def load_data(): @@ -18,7 +19,7 @@ def load_data(): Y = [] for filename in glob.glob("parking_aarhus*"): - p_class = '2330' in filename + p_class = '2235' in filename with open(filename) as file: data = json.load(file) @@ -32,13 +33,26 @@ def load_data(): def train(): X, Y = load_data() - classifier = svm.SVC(C=10, gamma=0.01, probability=True) + classifier = svm.SVC(gamma=0.01, probability=True) classifier.fit(X, Y) joblib.dump(classifier, "nightness_classifier.pkl") def predict(X): classifier = joblib.load("nightness_classifier.pkl") - prob = classifier.predict_proba(X) + prob = classifier.predict_proba(np.array(X).reshape(1, -1)) return prob[0, 1] -train() + +def perform_svm_pred(context: Context) -> Prediction: + p = Prediction() + data = requests.get('https://portal.opendata.dk/api/3/action/datastore_search?resource_id=2a82a145-0195-4081-a13c-b0e587e9b89c') + + records = data.json()['result']['records'] + X = [house['vehicleCount'] / house['totalSpaces'] for house in records] + X = [min(x, 1) for x in X] + p.reasons.append("Since we only have two data points") + p.reasons.append("Since our only two data points have 11 dimensions") + p.reasons.append("Since we are using a SVM") + + p.probability = predict(X) + return p