Jaccard index: Difference between revisions

Add emacs lisp
(Added Quackery.)
(Add emacs lisp)
Line 59:
0 0 0 0.2 0 1
┘</pre>
 
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">
(let* ((v1 '(A ()
B (1 2 3 4 5)
C (1 3 5 7 9)
D (2 4 6 8 10)
E (2 3 5 7)
F (8)))
(keys1 (seq-filter (lambda (x) (not (null x)))
(cl-loop for s1 being the elements of v1
using (index idx)
collect (if (= (% idx 2) 0) s1 nil)))))
 
(switch-to-buffer-other-window "*similarity result*")
(erase-buffer)
(defun similarity (p1 p2)
(if (and (null p1) (null p2)) 1
(/ (float (seq-length (seq-intersection p1 p2)))
(float (seq-length (seq-uniq (seq-union p1 p2))))) ) )
 
(insert (format " %s\n"
(cl-loop for s1 being the elements of keys1 concat
(format " %s" s1))))
(cl-loop for s1 in keys1 do
(insert (format "%s %s\n" s1
(cl-loop for s2 in keys1 concat
(format " %3.3f" (similarity (plist-get v1 s1) (plist-get v1 s2) ))))))
)
</syntaxhighlight>
{{out}}
<pre>
A B C D E F
A 1.000 0.000 0.000 0.000 0.000 0.000
B 0.000 1.000 0.429 0.250 0.500 0.000
C 0.000 0.429 1.000 0.000 0.500 0.000
D 0.000 0.250 0.000 1.000 0.125 0.200
E 0.000 0.500 0.500 0.125 1.000 0.000
F 0.000 0.000 0.000 0.200 0.000 1.000
</pre>
 
=={{header|Factor}}==
59

edits