'I can't express a plt.plot
import numpy as np
import matplotlib.pyplot as plt
x = np.array([173, 175, 162.5, 178, 160])
y = np.array([166, 164, 154, 169, 152])
class Neuron :
def __init__(self) :
self.w = 0.000001
self.i = 0.000001
def forpass(self, x):
y_hat = self.w * x + self.i
return y_hat
def backprop(self, x, err) :
w_grad = x*err
i_grad = 1*err
return w_grad, i_grad
def fit(self, x, y, epochs = 2000):
for i in range(epochs):
for x_i, y_i in zip(x, y):
y_hat = self.forpass(x_i)
err = -(y_i - y_hat)
w_grad, i_grad = self.backprop(x_i, err)
self.w -= w_grad
self.i -= i_grad
neuron = Neuron()
neuron.fit(x, y)
plt.scatter(x, y)
pt1 = (150, 150 * neuron.w + neuron.i)
pt2 = (180, 180 * neuron.w + neuron.i)
plt.plot([pt1[0], pt2[0]], [pt1[1], pt2[1]])
plt.show()
RuntimeWarning: overflow encountered in double_scalars
There is an overflow error and the plt.plot function cannot be output. I also tried logsumexp, but I still can't print it out. What code should I change to print out the plt.plot function?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
