I'm aware that there are other questions with the same name, but they're all about indexing and I'm getting this error when trying to invoke func(r_curr)
. I've already checked and func is not NoneType after assignment, it is <function <lambda> at 0x000001BB1E91E510>
.
def eval_symb_reg(individual, points):
global X
global y
global size
func = toolbox.compile(expr=individual)
predict = []
for i in range(X.shape[0]):
total = 0
for j in range(size):
r_curr = X[i][j*size:(j+1)*size]
result = func(r_curr)
total += result[0]
predict.append(total)
error = np.sum((np.array(predict) - y) ** 2)
return [1 / (error / X.shape[0])]
Stack trace:
Traceback (most recent call last):
File "symbreg.py", line 298, in <module>
main()
File "symbreg.py", line 265, in main
halloffame=hof, verbose=True)
File "C:\Users\<myuser>\AppData\Local\Programs\Python\Python36\lib\site-packages\deap\algorithms.py", line 151, in eaSimple
for ind, fit in zip(invalid_ind, fitnesses):
File "symbreg.py", line 198, in eval_symb_reg
result = func(r_curr)
File "<string>", line 1, in <lambda>
TypeError: 'NoneType' object is not subscriptable