ageron / ageron/handson-ml2

Chapter 13 : TypeError in cell #102

Open
#348 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
30k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

Hi,

Executing the cell 102 of the chapter 13 handbook raises TypeError Exception (see traceback below). The workaround i used is to change `value=[x]` to `value=[*x]` (and the same for `y`) as the values returned are arrays (`[15.]`) and not simple values.
We could also be using directly the `filepath_dataset` created earlier and parse it "the good way", reshaping `X_train`, or else.. ?

> ```
> ---------------------------------------------------------------------------
> TypeError Traceback (most recent call last)
> in
> 2 for x, y in zip(X_train[:, 1:2], y_train):
> 3 example = Example(features=Features(feature={
> ----> 4 "housing_median_age": Feature(float_list=FloatList(value=[x])),
> 5 "median_house_value": Feature(float_list=FloatList(value=[y]))
> 6 }))
>
> ~\anaconda3\lib\site-packages\google\protobuf\internal\python_message.py in init(self, **kwargs)
> 551 field_value = [_GetIntegerEnumValue(field.enum_type, val)
> 552 for val in field_value]
> --> 553 copy.extend(field_value)
> 554 self._fields[field] = copy
> 555 elif field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
>
> ~\anaconda3\lib\site-packages\google\protobuf\internal\containers.py in extend(self, elem_seq)
> 280 raise
> 281
> --> 282 new_values = [self._type_checker.CheckValue(elem) for elem in elem_seq_iter]
> 283 if new_values:
> 284 self._values.extend(new_values)
>
> ~\anaconda3\lib\site-packages\google\protobuf\internal\containers.py in (.0)
> 280 raise
> 281
> --> 282 new_values = [self._type_checker.CheckValue(elem) for elem in elem_seq_iter]
> 283 if new_values:
> 284 self._values.extend(new_values)
>
> ~\anaconda3\lib\site-packages\google\protobuf\internal\type_checkers.py in CheckValue(self, proposed_value)
> 283 message = ('%.1024r has type %s, but expected one of: numbers.Real' %
> 284 (proposed_value, type(proposed_value)))
> --> 285 raise TypeError(message)
> 286 converted_value = float(proposed_value)
> 287 # This inf rounding matches the C++ proto SafeDoubleToFloat logic.
>
> TypeError: array([15.]) has type , but expected one of: numbers.Real
>
> ```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.