【发布时间】:2018-03-05 13:54:25
【问题描述】:
机器学习新手在这里。在对训练数据进行权重训练后,我试图计算线性模型的 0/1 损失。我在这里看到了很多使用 for 循环的答案。有没有办法对其进行矢量化?我的尝试如下:
prob = np.dot(X_train,w)>=0
pred = [int(i) for i in prob]
error = np.sum(pred)/X_train.shape[0]
其中 w 是训练的权重,X_train 的形状为样本数 x 特征数
【问题讨论】:
-
请花点时间学习如何格式化你的代码(真的很简单);这是公平的,因为您在这里要求我们的时间
标签: python python-3.x numpy machine-learning