题解 | 单神经元

单神经元

https://www.nowcoder.com/practice/8903b7c94c6f4f4f963b7d05e1e397c7

import math
import numpy as np
def softmax(x):
    return 1/(1+math.exp(-1*x))


def single_neuron_model(features, labels, weights, bias):
    probabilities = []
    diff = 0
    for i in range(len(features)):
        z = 0
        for j in range(len(features[i])):
            z += features[i][j] * weights[j]
        z = softmax(z + bias)
        z = round(z,4)
        probabilities.append(z)
        diff += (z - labels[i])**2
    mse = diff / len(features)
    mse = round(mse, 4)
    return probabilities, mse


if __name__ == "__main__":
    features = np.array(eval(input()))
    labels = np.array(eval(input()))
    weights = np.array(eval(input()))
    bias = float(input())
    print(single_neuron_model(features, labels, weights, bias))

全部评论

相关推荐

11-23 15:14
中原工学院 Java
程序员花海_:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务