title: OneHotEncoding mapping issue between training data and test data
body: <p>I've transformed training and test data set by sklearn OneHotEncoding method. However, trnsformed results have different type shape. So It is impossible to apply to other algorithms like logistic regression. </p>
  
  <p>How do I reshape the test data in accordance with the training data set's shape? </p>
  
  <p>Best Regardings, Chris </p>
  
  <pre><code>import pandas as pd
  import numpy as np
  from sklearn.preprocessing import OneHotEncoder, LabelEncoder 
  
  def data_transformation(data, dummy):  
      le = LabelEncoder()
  
      # Encoding the columns with multiple categorical levels
      for col1 in dummy:
          le.fit(data[col1])
          data[col1] = le.transform(data[col1])
  
      dummy_data = np.array(data[dummy])
      enc = OneHotEncoder()
      enc.fit(dummy_data)
  
      dummy_data = enc.transform(dummy_data).toarray() 
  
  if __name__ == '__main__': 
      data = pd.read_csv('train.data', delimiter=',') 
      data_test = pd.read_csv('test.data', delimiter=',')
  
      dummy_columns = ['Column1', 'Column2'] 
      data = data_transformation(data, dummy_columns)
      data_test = data_transformation(data_test, dummy_columns)
  
  # result 
  # data shape : (200000, 71 ) 
  # data_test shape : ( 15000, 32) 
  </code></pre>