Skip to content

Instantly share code, notes, and snippets.

View shark8me's full-sized avatar

Kiran Karkera shark8me

View GitHub Profile
@shark8me
shark8me / get-job-status.clj
Created September 15, 2020 11:26
Get the job status
(get-job-status "pi")
;;{:startTime "2020-09-15T08:33:44Z", :active 1}
;;wait for a few seconds
(get-job-status "pi")
;;{:conditions [{:type "Complete", :status "True", :lastProbeTime "2020-09-15T08:33:55Z",
;;:lastTransitionTime "2020-09-15T08:33:55Z"}], :startTime "2020-09-15T08:33:44Z",
;;:completionTime "2020-09-15T08:33:55Z", :succeeded 1}
@shark8me
shark8me / create-job.clj
Created September 15, 2020 11:24
Create a k8s job
;;set the REST endpoint for K8S
(core/set-api-context {:base-url "http://localhost:8080"})
;;create a job with the given spec.
;;we'll use the default K8s namespace.
(create-namespaced-job "default" pi-job-spec)
@shark8me
shark8me / pi-job-spec.clj
Last active September 15, 2020 11:24
Running a Kubernetes Job from the Clojure Repl
(def pi-job-spec
{:apiVersion "batch/v1"
:kind "Job"
:metadata {:name "pi"}
:spec {:ttlSecondsAfterFinished 200
:template
{:spec
{:containers
[{:name "pi"
:imagePullPolicy "Always"
@shark8me
shark8me / confuse.clj
Last active March 16, 2018 01:38
Example of binary and multi-class classification metrics using the Confuse library
(:require
[confuse.binary-class-metrics :refer :all]
[confuse.multi-class-metrics :refer :all])
;;list of predicted labels: they could be numbers or keywords
(def pred [1 0 1 1 0])
;;list of actual labels/ground truth
(def ac [1 1 1 1 0])
;;assume the positive class is 1
(true-positives ac pred 1)
(ns ;...
(:require [tfevent-sink.event-io :as eio]))
(let [file-path "/tmp/run/tfevents.log"
;;create a scalar event with a name and value
ev (eio/make-event "loss/mean-squared-error" (double 0.09))]
;;create and initialize the event stream
(eio/create-event-stream file-path)
;;append event to stream
(eio/append-events file-path [ev])
@shark8me
shark8me / gbrt_calibration.py
Created April 28, 2016 16:31
Comparison of classifiers (GBRT vs Logistic) on the probability calibration scale.
print(__doc__)
# Author: Alexandre Gramfort <alexandre.gramfort@telecom-paristech.fr>
# Jan Hendrik Metzen <jhm@informatik.uni-bremen.de>
# License: BSD Style.
%matplotlib inline
import matplotlib.pyplot as plt
from sklearn import datasets
;adds 2 children to a leaf node
(defn add-children [{x :self :as m}]
(assoc m :cren [ {:self (inc x)} {:self (dec x)}]))
(def xroot {:self 20 :cren [
{:self 10 }
{:self 30 }
]})
;the nodes 10 and 30 now have 2 children: 11,9 and 31,29
;this returns the value of :self nodes from the root to the leaf
(defn gpath [n]
"returns that path from the parent till the leaf"
(conj (vec (map :self (zip/path n))) (-> n zip/node :self)))
;path from root to leaf.
(is (= '([20 10 11] [20 10 12] [20 30 31] [20 30 32])
(map (comp gpath) (leafnodes (mzipper mroot)))))
;the root of the tree.
;each node has a :self key, the value of which is its own value, and a vector
;that contains children.
(def mroot {:self 20 :cren [
{:self 10 :cren [{:self 11} {:self 12}]}
{:self 30 :cren [{:self 31} {:self 32}]}
]})
;create a zipper from the mroot tree.
(defn mzipper [root]
;a sample zipper
(def v2 (zip/vector-zip [[2 3] [4]]))
(defn editfn [x]
"returns a vector with 2 numbers"
(let [a (* x 10)]
[(inc a) (dec a)]))
(defn inext [node-edit loc ]
"Adds children if loc is a leaf, else returns the next node"