Найти - Пользователи
Полная версия: fmin_bfgs - Desired error not neccessarily achieved due to precision loss
Начало » Python для новичков » fmin_bfgs - Desired error not neccessarily achieved due to precision loss
1
vladimircape
Добрый день,
Использую scipy для нахождения минимума функции стоимости и выпадает такая ошибка, т.к. почему-то функция стоимости получается nan
Может ли кто-то обьяснить в чем причина ошибки вычисления и как исправить
def compute_cost(theta,X,y): 
    m = X.shape[0]    
    theta = num.reshape(theta,(len(theta),1))        
    J = (1./m) * (-num.transpose(y).dot(num.log(sigmoid(X.dot(theta)))) - num.transpose(1-y).dot(num.log(1-sigmoid(X.dot(theta)))))
    return J		
def grad(theta, X, y):
    p_1 = sigmoid(num.dot(X, theta))
    error = p_1 - y 
    grad = num.dot(error, X_1) / y.size # gradient vector
    return grad
theta_1 = opt.fmin_bfgs(compute_cost, theta, fprime=grad, args=(X_1, y))
py.user.next
vladimircape
grad = num.dot(error, X_1) / y.size # gradient vector

Попробуй так:
grad = float(num.dot(error, X_1)) / y.size # gradient vector
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB