ageron / ageron/handson-ml2

Chapter 13 : TypeError in cell #102

未关闭
#348 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Jupyter Notebook
星标
30k
派生
13.1k
PR 合并指标
30 天内没有已合并 PR

描述

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
>
> ```

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。