title: How to fix 'numpy.ndarray' error while making training data-set using CountVectorizer?
body: <p>I am making a text classifier on the data I have. On the basis of some observations I need to identify the target variable. I started with bag of words and tf/idf approach.</p>
  
  <p>I have made the classifier with "one" feature, but when I am trying to incorporate more "features" say 7 to predict the label, the Count Vectorizer throws error for fit_transform.
  Following is the code</p>
  
  <pre><code>from sklearn import preprocessing
  from sklearn.feature_extraction.text import CountVectorizer    
  from sklearn.feature_extraction.text import TfidfTransformer
  from sklearn.linear_model import LogisticRegression
  
  bow = CountVectorizer()
  # working fine for one feature
  #observation = df_all_null_removed['Observation'].values
  # selecting feature set of 7 variables
  observation = df_all_null_removed[features].values
  
  train_obs, test_obs,y_train, y_test =train_test_split(observation,
                                 df_all_null_removed['HazardType'],                                                       
                                 test_size=0.12,
                                 random_state=42)
  bow_matrix = bow.fit_transform(observation) # throws error - screen shot attached.
  </code></pre>
  
  <p>I think its because "observation" is a 2 dimensional numpy array of shape [8150,7] and we need to convert it into 8150 rows of 1 column array.</p>
  
  <pre><code>AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-140-d75b27bd1080&gt; in &lt;module&gt;()
  ----&gt; 1 bow_matrix = bow.fit_transform(observation)
        2 print("The vocabulary of the bow",len(bow.vocabulary_))
  
  ~/anaconda3/lib/python3.6/site-packages/sklearn/feature_extraction/text.py in fit_transform(self, raw_documents, y)
      867 
      868         vocabulary, X = self._count_vocab(raw_documents,
  --&gt; 869                                           self.fixed_vocabulary_)
      870 
      871         if self.binary:
  
  ~/anaconda3/lib/python3.6/site-packages/sklearn/feature_extraction/text.py in _count_vocab(self, raw_documents, fixed_vocab)
      790         for doc in raw_documents:
      791             feature_counter = {}
  --&gt; 792             for feature in analyze(doc):
      793                 try:
      794                     feature_idx = vocabulary[feature]
  
  ~/anaconda3/lib/python3.6/site-packages/sklearn/feature_extraction/text.py in &lt;lambda&gt;(doc)
      264 
      265             return lambda doc: self._word_ngrams(
  --&gt; 266                 tokenize(preprocess(self.decode(doc))), stop_words)
      267 
      268         else:
  
  ~/anaconda3/lib/python3.6/site-packages/sklearn/feature_extraction/text.py in &lt;lambda&gt;(x)
      230 
      231         if self.lowercase:
  --&gt; 232             return lambda x: strip_accents(x.lower())
      233         else:
      234             return strip_accents
  
  AttributeError: 'numpy.ndarray' object has no attribute 'lower'
  </code></pre>