1
I’m having trouble in the following code. I don’t understand what is wrong. I believe it is in the function sigmoid where she appears not to be receiving values float
.
import numpy as np
# sigmoid function
def nonlin(x,deriv=False):
if(deriv==True):
return x*(1-x)
return 1/(1+np.exp(-x))
# Valores de Entradas
X = np.array([[488457.495,6673006.568,68.624],[488458.287,6673008.192,68.621],
[488459.073,6673009.798,68.618], [488456.712,6673004.978,66.558]],dtype=object)# Entrada_Estação_Total_Aba_8_Reg_01
# saidas
y = np.array([[488457.500,6673006.571,68.624],[488458.281,6673008.199,68.617],
[488459.071,6673009.807,68.615],[488456.722,6673004.980,66.566]],dtype=object).T#Registro_C1_Nuvem_Aba_*_REG_1
# seed random numbers to make calculation
# deterministic (just a good practice)
np.random.seed(1)
# initialize weights randomly with mean 0
syn0 = 2*np.random.random((3,1)) - 1
for iter in range(10000):
# forward propagation
l0 = X
l1 = nonlin(np.dot(l0,syn0))
# how much did we miss?
l1_error = (y - l1)
# multiply how much we missed by the
# slope of the sigmoid at the values in l1
l1_delta = l1_error * nonlin(l1,True)
# update weights
syn0 += np.dot(l0.T,l1_delta)
print("\n")
print ("Saidas depois do treinamento:")
print("\n")
print (l1)
print("\n")
print("Pesos_Ajustados: ")
print("\n")
print(np.around(syn0,decimals=3))
The following error message appears:
Traceback (most recent call last):
File "G:\Perceptron_PE_TLS\Perceptron_TLS_Ajustado2.py", line 34, in <module>
l1 = nonlin(np.dot(l0,syn0))
File "G:\Perceptron_PE_TLS\Perceptron_TLS_Ajustado2.py", line 7, in nonlin
return 1/(1+np.exp(-x))
AttributeError: 'float' object has no attribute 'exp'