Using fminunc() for logistic regression

6 ビュー (過去 30 日間)
Sree Bhargavi Moganti
Sree Bhargavi Moganti 2020 年 3 月 3 日
編集済み: Matt J 2020 年 3 月 3 日
I've been using fminunc to get parameters for logistic regression for a while now and it was working fine. However, everytime I convert one column of my data into log of that data, it shows the following error: "Objective function is undefined at initial point. Fminunc cannot continue"
Can someone tell me why this is happening?
x is a matrix and I wanted to include log of one of the columns to calculate my parameters theta. It works fine if I don't convert it into log values.
In_cost is a function I wrote to calculate cost and gradient vector.
lambda = 0;
theta_i = zeros(size(x,2),1);
options = optimoptions(@fminunc,'Algorithm','Quasi-Newton','GradObj', 'on', 'MaxIter', 1000);
[theta, J, exit_flag] = fminunc(@(t)(in_cost(t, x, y, lambda)), theta_i, options);
  1 件のコメント
the cyclist
the cyclist 2020 年 3 月 3 日
Could you upload your in_cost function and a small dataset that will exhibit the error?

サインインしてコメントする。

採用された回答

Matt J
Matt J 2020 年 3 月 3 日
編集済み: Matt J 2020 年 3 月 3 日
Can someone tell me why this is happening?
The problem has nothing to do with fminunc. As the error message says, your objective function is not returning a valid value at the initial point. You simply need to call your function with the initial point and observe the output to verify what the message is telling you.

その他の回答 (1 件)

the cyclist
the cyclist 2020 年 3 月 3 日
編集済み: the cyclist 2020 年 3 月 3 日
Is there a zero in x, such that the log is undefined?
  1 件のコメント
Sree Bhargavi Moganti
Sree Bhargavi Moganti 2020 年 3 月 3 日
No zeros and no negative values

サインインしてコメントする。

製品


リリース

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by