matroid / dlwithtf

TensorFlow for Deep Learning Book
http://shop.oreilly.com/product/0636920065869.do
321 stars 160 forks source link

Type mismath in ch5/tox21_rf.py under python3 #24

Open alex-mashin opened 3 years ago

alex-mashin commented 3 years ago

python3 ch5/tox21_rf.py outputs:

About to fit model on train set.
Traceback (most recent call last):
  File "tox21_rf.py", line 25, in <module>
    sklearn_model.fit(train_X, train_y)
  File "/home/alexander/env/tf/lib/python3.8/site-packages/sklearn/ensemble/_forest.py", line 330, in fit
    y, expanded_class_weight = self._validate_y_class_weight(y)
  File "/home/alexander/env/tf/lib/python3.8/site-packages/sklearn/ensemble/_forest.py", line 558, in _validate_y_class_weight
    check_classification_targets(y)
  File "/home/alexander/env/tf/lib/python3.8/site-packages/sklearn/utils/multiclass.py", line 172, in check_classification_targets
    raise ValueError("Unknown label type: %r" % y_type)
ValueError: Unknown label type: 'unknown'

It helps to replace line 14:

train_y = train_y[:, 0]

with

train_y = train_y[:, 0].astype('int')