题解 | 单神经元

单神经元

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

import math
import numpy as np
def sigmoid(x):
    return 1/(1+np.exp(-x))
def single_neuron_model(features, labels, weights, bias):
    single = np.dot(features,weights)+bias
    pred = sigmoid(single)
    probabilities = np.round(pred,4).tolist()
    mse = np.sum((pred-labels)**2)/len(pred)
    mse = np.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))

全部评论

相关推荐

牛客78682892...:直接点还好,总比要了简历也不回的强
点赞 评论 收藏
分享
陌夏微秋:一线城市25w左右吧,17×15=255
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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