TypeError: 'SparseTensor' object is not subscriptable #42
-
I am getting this error while running the model. https://www.kaggle.com/adityadesai13/used-car-dataset-ford-and-mercedes?select=vw.csv from sklearn.compose import make_column_transformer X = Car_Data.drop("price",axis=1) ct = make_column_transformer((MinMaxScaler(),["mileage","tax","mpg","engineSize","year"]), X_train_1,X_test_1,y_train_1,y_test_1 = train_test_split(X,y,test_size=0.15,random_state=42) ct.fit(X_train_1) tf.random.set_seed car_model_Normalized = tf.keras.Sequential([ WARNING:tensorflow:Keras is training/fitting/evaluating on array-like data. Keras may not be optimized for this format, so if your input data format is supported by TensorFlow I/O (https://github.com/tensorflow/io) we recommend using that to load a Dataset instead.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @murlisingh,
|
Beta Was this translation helpful? Give feedback.
Hey @murlisingh,
Looks like your model is having trouble fitting on a sparse tensor.
This probably starts with a sparse array created by
make_column_transformer
orOneHotEncoder
.I'd look into the following parameters:
sparse_threshold
in https://scikit-learn.org/stable/modules/generated/sklearn.compose.make_column_transformer.htmlsparse=True
(try setting this to False) in https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.htmlIn essence, you want to make sure once your data is encoded it's not in the form of a sparse array/tensor.
To verify this, I'd print the outputs of your data preprocessing methods and make sure it isn't sparse before passing it …