Liking cljdoc? Tell your friends :D

clj-synapses.codec

A codec can encode and decode every data point.

One hot encoding is a process that turns discrete attributes into a list of 0.0 and 1.0. Minmax normalization scales continuous attributes into values between 0.0 and 1.0.

(require '[clj-synapses.codec :as codec])

There are two ways to create a codec:

  1. By providing a list of pairs that define the name and the type of each attribute:
(def preprocessor
  (codec/->codec
    [["petal_length" false]
     ["species" true]]
    [{"petal_length" "1.5"
      "species"      "setosa"}
     {"petal_length" "3.8"
      "species"      "versicolor"}]))
  1. By providing its JSON representation.
(def preprocessor
  (codec/json->
    "[{"Case" : "SerializableContinuous",
        "Fields" : [{"key" : "petal_length","min" : 1.5,"max" : 3.8}]},
       {"Case" : "SerializableDiscrete",
        "Fields" : [{"key" : "species","values" : ["setosa","versicolor"]}]}]"))

EXAMPLES

Encode a data point:

(codec/encode
  preprocessor
  {"petal_length" "1.5"
   "species" "setosa"})
;;=> [0.0, 1.0, 0.0]

Decode a data point:

(codec/decode
  preprocessor
  [0.0, 1.0, 0.0])
;;=> {"petal_length" "1.5", "species" "setosa"}

Get the JSON representation of the codec:

(codec/->json
  preprocessor)
A codec can encode and decode every data point.

One hot encoding is a process that turns discrete attributes into a list of 0.0 and 1.0.
Minmax normalization scales continuous attributes into values between 0.0 and 1.0.

```clojure
(require '[clj-synapses.codec :as codec])
```

There are two ways to create a codec:

1. By providing a list of pairs that define the name and the type of each attribute:

```clojure
(def preprocessor
  (codec/->codec
    [["petal_length" false]
     ["species" true]]
    [{"petal_length" "1.5"
      "species"      "setosa"}
     {"petal_length" "3.8"
      "species"      "versicolor"}]))
```

2. By providing its JSON representation.

```clojure
(def preprocessor
  (codec/json->
    "[{"Case" : "SerializableContinuous",
        "Fields" : [{"key" : "petal_length","min" : 1.5,"max" : 3.8}]},
       {"Case" : "SerializableDiscrete",
        "Fields" : [{"key" : "species","values" : ["setosa","versicolor"]}]}]"))
```

EXAMPLES

Encode a data point:

```clojure
(codec/encode
  preprocessor
  {"petal_length" "1.5"
   "species" "setosa"})
;;=> [0.0, 1.0, 0.0]
```

Decode a data point:

```clojure
(codec/decode
  preprocessor
  [0.0, 1.0, 0.0])
;;=> {"petal_length" "1.5", "species" "setosa"}
```

Get the JSON representation of the codec:

```clojure
(codec/->json
  preprocessor)
```
raw docstring

->codecclj

(->codec attributes data-points)

Returns a codec that can encode and decode every data point. attributes is a vector of pairs that define the name and the type (discrete or not) of each attribute.

(codec/->codec
  [["petal_length" false]
   ["species" true]]
  [{"petal_length" "1.5"
    "species"      "setosa"}
   {"petal_length" "3.8"
    "species"      "versicolor"}])
Returns a codec that can encode and decode every data point.
`attributes` is a vector of pairs that define the name and the type (discrete or not) of each attribute.

```clojure
(codec/->codec
  [["petal_length" false]
   ["species" true]]
  [{"petal_length" "1.5"
    "species"      "setosa"}
   {"petal_length" "3.8"
    "species"      "versicolor"}])
```
sourceraw docstring

->jsonclj

(->json codec)

Returns the JSON representation of the codec.

Returns the JSON representation of the codec.
sourceraw docstring

decodeclj

(decode codec encoded-values)

Accepts the encoded-values as a vector of numbers between 0.0 and 1.0 and returns the decoded data point as a map of strings.

Accepts the `encoded-values` as a vector of numbers between 0.0 and 1.0
and returns the decoded data point as a map of strings.
sourceraw docstring

encodeclj

(encode codec data-point)

Accepts the data-point as a map of strings and returns the encoded data point as a vector of numbers between 0.0 and 1.0.

Accepts the `data-point` as a map of strings
and returns the encoded data point as a vector of numbers between 0.0 and 1.0.
sourceraw docstring

json->clj

(json-> json)

Returns a codec that can encode and decode every data point. json is the JSON representation of a codec.

(codec/json->
  "[{"Case" : "SerializableContinuous",
      "Fields" : [{"key" : "petal_length","min" : 1.5,"max" : 3.8}]},
     {"Case" : "SerializableDiscrete",
      "Fields" : [{"key" : "species","values" : ["setosa","versicolor"]}]}]")
Returns a codec that can encode and decode every data point.
`json` is the JSON representation of a codec.

```clojure
(codec/json->
  "[{"Case" : "SerializableContinuous",
      "Fields" : [{"key" : "petal_length","min" : 1.5,"max" : 3.8}]},
     {"Case" : "SerializableDiscrete",
      "Fields" : [{"key" : "species","values" : ["setosa","versicolor"]}]}]")
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close