题解 | 单神经元
单神经元
https://www.nowcoder.com/practice/8903b7c94c6f4f4f963b7d05e1e397c7
import math
import numpy as np
def single_neuron_model(features, labels, weights, bias):
y_pred = np.dot(features, weights) + bias
probabilities = 1 / (1 + np.exp(-y_pred))
mse = np.mean(np.power(probabilities-labels, 2))
return np.round(probabilities, 4).tolist(), np.round(mse, 4)
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))
