I’m a novice in python.I want to estimate about three coefficeints. I wrote down the code below. I omitted some code about some data which means two variables such as growth and age. I used tensorflow, numpy, and sklearn etc.
There is no error message but I get a warning sign. which situation causes the message, below?
how can I solve the problem?
a=df4['growth']
b=df4['age']
y=np.array(a.values.tolist())
X=np.array(b.values.tolist())
fig = plt.figure(figsize=(10,10))
plt.plot(X, y, "o")
import tensorflow as tf
import numpy as np
from sklearn.metrics import r2_score
from sklearn.metrics import mean_squared_error
import matplotlib.pyplot as plt
import scipy.stats as stats
import random
a=tf.Variable(random.random())
b=tf.Variable(random.random())
c=tf.Variable(random.random())
#d=tf.Variable(random.random())
from sklearn.metrics import classification_report
def compute_loss():
y_pred = a + (b * X * np.exp(-c*X))
loss=tf.reduce_mean((y-y_pred) **2)
return loss
def accuracy():
y_pred = a + (b * X * np.exp(-c*X))
r2=r2_score(y, y_pred)
return r2
def accuracy2():
y_pred = a + (b * X * np.exp(-c*X))
rmse=mean_squared_error(y, y_pred)**0.5
return rmse
optimizer = tf.keras.optimizers.SGD(lr=0.01, momentum=0.0, decay = 0.0, nesterov=False)
for i in range(10000):
optimizer.minimize(compute_loss, var_list=[a, b, c])
if i % 10000 == 9999:
print(i, 'a:', a.numpy(), 'b:', b.numpy(), 'c:', c.numpy(),'loss:', compute_loss().numpy(), 'r2:', accuracy(), 'rmse:', accuracy2())
WARNINIG: tensorflow: gradients do not exist for variables ['Variable:0'] when minimuzing the loss