Skip to content

Instantly share code, notes, and snippets.

@joycex99
Last active June 1, 2020 21:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joycex99/fec2c0f9e6af8a8725e9152c277940e4 to your computer and use it in GitHub Desktop.
Save joycex99/fec2c0f9e6af8a8725e9152c277940e4 to your computer and use it in GitHub Desktop.
(ns fraud-detection.core
(:require [clojure.java.io :as io]
[clojure.string :as string]
[clojure.data.csv :as csv]
[clojure.core.matrix :as mat]
[clojure.core.matrix.stats :as matstats]
[cortex.nn.layers :as layers]
[cortex.nn.network :as network]
[cortex.nn.execute :as execute]
[cortex.optimize.adadelta :as adadelta]
[cortex.optimize.adam :as adam]
[cortex.metrics :as metrics]
[cortex.util :as util]
[cortex.experiment.util :as experiment-util]
[cortex.experiment.train :as experiment-train]))
(def orig-data-file "resources/creditcard.csv")
(def log-file "training.log")
(def network-file "trained-network.nippy")
;; Read input csv and create a vector of maps {:data [...] :label [..]},
;; where each map represents one training instance in the data
(defonce create-dataset
(memoize
(fn []
(let [credit-data (with-open [infile (io/reader orig-data-file)]
(rest (doall (csv/read-csv infile))))
data (mapv #(mapv read-string %) (map #(drop 1 %) (map drop-last credit-data))) ; drop label and time
labels (mapv #(util/idx->one-hot (read-string %) 2) (map last credit-data))
dataset (mapv (fn [d l] {:data d :label l}) data labels)]
dataset))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment