<commit_before>(ns analyze-data.predict
  (:require [clojure.core.matrix :as m]
            [analyze-data.dataset.create.core :refer [document-to-vector]]
            [analyze-data.knn.core :as knn]
            [analyze-data.naive-bayes.predict :as naive-bayes]))

(defmulti predict
  "Predict a label for z.

  model: previously trained model
  z: feature vector
  options: specific to the model-type
    :knn see analyze-data.knn.core/predict
    :naive-bayes see analyze-data.naive-bayes.predict/predict

  Return the predicted label."
  (fn [model z & options] (:type model)))

(defn predict-document
  "Predict a label for the given document.

  model: previously trained model
  document: string
  options: see predict

  Return the predicted label."
  [model document & options]
  (let [dataset (:dataset model)
        z (document-to-vector dataset document)]
    (apply predict model z options)))

(defmethod predict :knn [model z & options]
  (let [{{:keys [X y classes]} :dataset} model
        prediction (apply knn/predict X y z options)]
    (classes (first prediction))))

(defmethod predict :naive-bayes [model z & options]
  (let [{:keys [parameters]
         {:keys [classes]} :dataset} model
        prediction (naive-bayes/predict parameters z)]
    (classes (first prediction))))<commit_msg>Pass through options to naive-bayes/predict.<commit_after>(ns analyze-data.predict
  (:require [clojure.core.matrix :as m]
            [analyze-data.dataset.create.core :refer [document-to-vector]]
            [analyze-data.knn.core :as knn]
            [analyze-data.naive-bayes.predict :as naive-bayes]))

(defmulti predict
  "Predict a label for z.

  model: previously trained model
  z: feature vector
  options: specific to the model-type
    :knn see analyze-data.knn.core/predict
    :naive-bayes see analyze-data.naive-bayes.predict/predict

  Return the predicted label."
  (fn [model z & options] (:type model)))

(defn predict-document
  "Predict a label for the given document.

  model: previously trained model
  document: string
  options: see predict

  Return the predicted label."
  [model document & options]
  (let [dataset (:dataset model)
        z (document-to-vector dataset document)]
    (apply predict model z options)))

(defmethod predict :knn [model z & options]
  (let [{{:keys [X y classes]} :dataset} model
        prediction (apply knn/predict X y z options)]
    (classes (first prediction))))

(defmethod predict :naive-bayes [model z & options]
  (let [{:keys [parameters]
         {:keys [classes]} :dataset} model
        prediction (apply naive-bayes/predict parameters z options)]
    (classes (first prediction))))
{'fraction_non_alphanumeric': 0.11427500936680404, 'fraction_numerical': 0.0, 'mean_word_length': 3.3344155844155843, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7384935', 'n_tokens_mistral': 820, 'n_tokens_neox': 794, 'n_words': 267}