Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. (ns numerai.exploit
  2. (:require [clojure-csv.core :as csv])
  3. (:require [clustering.core.k-means :as k-means]))
  4.  
  5. ;;
  6. ;; Read in data, define output directories
  7. ;;
  8. (def evol-dir (str "results/week" 99 "/"))
  9. (def outp-dir (str "results/week" 99 "/"))
  10.  
  11. (def tournament (rest (csv/parse-csv (slurp "data/numerai_tournament_data.csv"))))
  12. (def predictions (into {} (rest (csv/parse-csv (slurp "data/example_predictions.csv")))))
  13.  
  14. (def ids (map first tournament))
  15.  
  16.  
  17. ;;
  18. ;; Helper Functions
  19. ;;
  20. (defn logloss [coll]
  21. (let [scores (map (fn [[g s]] (if (= "1" g) s (- 1.0 s))) coll)]
  22. (float (/ (reduce + (map #(Math/log %) scores)) (* -1 (count scores))))))
  23.  
  24.  
  25. ;;
  26. ;; How big is live
  27. ;;
  28. (count (filter #(= (nth % 2) "live") tournament))
  29. ;;
  30. ;; live is 4386 entries.
  31. ;;
  32. ;; What happens if we randomly predict all live scores to be wrong, except the final one.
  33. ;;
  34. (logloss (map vector (repeat 4386 "1") (conj (repeat 4385 0.49999) 0.9)))
  35. ;;
  36. ;; We still pass logloss. So if we submit two predictions, one with the final live score as "0.9" and one with "0.1", we can't lose.
  37. ;; We use the default predictions for all but the last tournament entry, but put the prediction limits to 0.49999 and 0.50001.
  38.  
  39.  
  40.  
  41.  
  42. (def goals (map #(if (= (nth % 2) "live")
  43. (min 0.50001 (max 0.49999 (read-string (predictions (first %)))))
  44. (min 0.50001 (max 0.49999 (read-string (predictions (first %))))))
  45. tournament))
  46.  
  47.  
  48. (spit (str outp-dir "JINX-pos" ".csv")
  49. (csv/write-csv (concat (list ["id" "probability"])
  50. (map #(list (str %1) (str %2))
  51. ids
  52. (concat (butlast goals) [0.9])))))
  53.  
  54. (spit (str outp-dir "JINX-neg" ".csv")
  55. (csv/write-csv (concat (list ["id" "probability"])
  56. (map #(list (str %1) (str %2))
  57. ids
  58. (concat (butlast goals) [0.1])))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement