title: How do I calculate TF-IDF of a query?
body: <p>How do I calculate <code>tf-idf</code> for a query? I understand how to calculate tf-idf for a set of documents with following definitions:</p>
  
  <blockquote>
    <p><strong>tf</strong> = occurances in document/ total words in document</p>
    
    <p><strong>idf</strong> = log(#documents / #documents where term occurs</p>
  </blockquote>
  
  <p>But I don't understand how that correlates to queries.
  <br></p>
  
  <p><strong>For example</strong>, I read <a href="https://janav.wordpress.com/2013/10/27/tf-idf-and-cosine-similarity/" rel="noreferrer">a resource</a> that stated the values of a query "<code>life learning</code>"</p>
  
  <blockquote>
    <p>life | tf = .5 | idf =    1.405507153 | tf_idf = 0.702753576<br>
    learning | tf = .5 | idf =    1.405507153 | tf_idf = 0.702753576<br></p>
  </blockquote>
  
  <p>The <code>tf</code> values I understand, each term appears only once out of the two possible terms, thus 1/2, But I have no idea where the <code>idf</code> comes from.<br>
  I would think that #documents = 1 and occurrence = 1, log(1) = 0, so <code>idf</code> would be 0, but this doesn't seem to be the case. Is it based on whatever documents you're using? How do you calculate tf-idf for a query?</p>