【问题标题】:How to efficiently find 0/1 loss for a linear classification model?如何有效地找到线性分类模型的 0/1 损失?
【发布时间】: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


【解决方案1】:

我不确定您要做什么。但这应该会有所帮助:

prob = np.dot(X_train,w)>=0  

pred = [int(i) for i in prob]  
z0= [1 if y_val[i,0]!=pred[i] else 0 for i in range(len(pred)) ]
error = sum(z0)/len(z0)

【讨论】:

    猜你喜欢
    • 2014-10-21
    • 2017-10-02
    • 1970-01-01
    • 1970-01-01
    • 2018-08-22
    • 2018-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多