import math
import numpy as np
def single_neuron_model(features, labels, weights, bias):
#注意 广播机制
res = np.dot(features, weights) + bias
probabilities = 1 / (1 + np.exp(-res))
mse = np.mean((probabilities - labels)**2)
return list(np.round(probabilities,4)), 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))
- 使用Numpy广播机制实现



京公网安备 11010502036488号