Sklearn: no se pueden usar datos codificados en un clasificador de bosque aleatorio
Soy nuevo en scikit-learn. Estoy tratando de usar preprocesamiento. OneHotEncoder para codificar mi entrenamiento y datos de prueba. Después de la codificación, intenté entrenar un clasificador de bosque aleatorio utilizando esos datos. Pero me sale el siguiente error al encajar. (Aquí la traza del error)
99 model.fit(X_train, y_train)
100 preds = model.predict_proba(X_cv)[:, 1]
101
C:\Python27\lib\site-packages\sklearn\ensemble\forest.pyc in fit(self, X, y, sample_weight)
288
289 # Precompute some data
--> 290 X, y = check_arrays(X, y, sparse_format="dense")
291 if (getattr(X, "dtype", None) != DTYPE or
292 X.ndim != 2 or
C:\Python27\lib\site-packages\sklearn\utils\validation.pyc in check_arrays(*arrays, **options)
200 array = array.tocsc()
201 elif sparse_format == 'dense':
--> 202 raise TypeError('A sparse matrix was passed, but dense '
203 'data is required. Use X.toarray() to '
204 'convert to a dense numpy array.')
TypeError: A sparse matrix was passed, but dense data is required. Use X.toarray() to convert to a dense numpy array.
Intenté convertir la matriz dispersa en densa usando X.toarray () y X.todense () Pero cuando hago eso, obtengo el siguiente rastreo de error.
99 model.fit(X_train.toarray(), y_train)
100 preds = model.predict_proba(X_cv)[:, 1]
101
C:\Python27\lib\site-packages\scipy\sparse\compressed.pyc in toarray(self)
548
549 def toarray(self):
--> 550 return self.tocoo(copy=False).toarray()
551
552 ##############################################################
C:\Python27\lib\site-packages\scipy\sparse\coo.pyc in toarray(self)
236
237 def toarray(self):
--> 238 B = np.zeros(self.shape, dtype=self.dtype)
239 M,N = self.shape
240 coo_todense(M, N, self.nnz, self.row, self.col, self.data, B.ravel())
ValueError: array is too big.
¿Alguien puede ayudarme a arreglar esto?
Gracias