因此,我尝试构建回归模型,但出现“ TypeError:无法将序列乘以'float'类型的非整数”错误。 我的代码如下:
dataset_path = keras.utils.get_file("nursery.data",
"path",
cache_subdir="local_path")
column_names = ['parents', 'has_nurs', 'form', 'children', 'housing',
'finance', 'social', 'health', 'result']
raw_dataset = pd.read_csv(dataset_path, names=column_names,
na_values="?", comment='\t',
sep=",", skipinitialspace=True)
在这之后,以及将值从字符串更改为整数的过程,我用于训练的X数据框如下所示:
parents has_nurs form children housing finance social health
6966 1 1 3 2 2 1 2 2
12445 0 0 2 3 1 1 0 1
8358 1 0 1 3 0 1 0 2
10538 0 2 3 4 2 1 0 0
3931 2 0 1 1 0 1 0 1
然后我要用权重制作点积:
def propagate(w, b, X, Y):
m = X.shape[1]
A = relu(pd.DataFrame.dot(X, w) + b) # compute activation
cost = (- 1 / m) * np.sum(Y - A) # compute cost
dw = (1 / m) * np.dot(X, (A - Y).T)
db = (1 / m) * np.sum(A - Y)
assert (dw.shape == w.shape)
assert (db.dtype == float)
cost = np.squeeze(cost)
assert (cost.shape == ())
grads = {"dw": dw,
"db": db}
return grads, cost
在此功能中。问题是无论如何尝试,我都会收到“ TypeError:无法将序列乘以'float'类型的非整数”错误。我相信这可能是因为我的列名中包含字符串,但是我不知道如何摆脱那些列名。
W这是X的正确形状(total_rows,8),W的是正确的形状(8,1)。请帮助我,我对如何处理此形状一无所知