我正在尝试构建一个机器学习模型,该模型可以从一系列数字中预测单个数字。我正在使用 Tensorflow 的 keras API 中的顺序模型。
你可以想象我的数据集看起来像这样:
| 指数 | x 数据 | y 数据 |
|---|---|---|
| 0 | np.ndarray(shape (1209278,) ) |
numpy.float32 |
| 1 | np.ndarray(shape (1211140,) ) |
numpy.float32 |
| 2 | np.ndarray(shape (1418411,) ) |
numpy.float32 |
| 3 | np.ndarray(shape (1077132,) ) |
numpy.float32 |
| ... | ... | ... |
这是我的第一次尝试:
我尝试使用 numpy ndarray ,其中包含 numpy ndarrays ,最终包含浮点数作为我的 xdata ,所以像这样:
array([
array([3.59280851, 3.60459062, 3.60459062, ..., 4.02911493])
array([3.54752101, 3.56740332, 3.56740332, ..., 4.02837855])
array([3.61048168, 3.62152741, 3.62152741, ..., 4.02764217])
])
Run Code Online (Sandbox Code Playgroud)
我的 y 数据是一个包含浮点数的 numpy ndarray,看起来像这样
array([2.9864411, 3.0562437, ... , 2.7750807, 2.8712902], dtype=float32)
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用它来训练模型时,model.fit()会产生以下错误:
ValueError: Failed to …Run Code Online (Sandbox Code Playgroud) 我最近刚刚了解到,你可以在Python中指定函数的参数和返回类型,如下所示:
def myDef(a: int, b: int) -> int:
return a+b
Run Code Online (Sandbox Code Playgroud)
考虑到速度,这是否有任何优势,或者是否有其他原因说明这可能有用?
想象我有一个这样的课程:
public:
A(const int a);
A& operator = (const A&);
};
Run Code Online (Sandbox Code Playgroud)
为什么“=”运算符的返回类型必须是“A&”而不是简单的“A”?