title: What is the significance of fit() in CountVectorizer?
body: <p>I have code that implements a naivebayes spam classifier and it implemts a CountVectorizer which goes like</p>
  
  <pre><code>from sklearn.feature_extraction.text import CountVectorizer
  vect=CountVectorizer(stop_words='english')
  vect.fit(x_train)
  vect.vocabulary_
  x_train_transformed=vect.transform(x_train)
  y_train_transformed=vect.transform(x_test)
  print(type(x_train_transformed))
  print(x_train_transformed)
  </code></pre>
  
  <p>What is the significance of fit() here?Why we are fitting only <strong>x_train</strong> and not <strong>x_test</strong> but transforming both <strong>x_train and x_test</strong>?</p>
  
  <p>I know the transform method of CountVectorizer convert the dataframe into bag of words(as they say) But what is the significance of the fit() method here?</p>