1

我想运行监督学习算法与一个指定的假设有一个参数theta在一个不寻常的位置。我想运行一个监督学习算法与一个指定的假设,其参数theta在一个不寻常的位置

Y = theta1 *(EXP(theta2 * X))+ theta0

我使用梯度下降用下面的函数尝试:

代码:

m = length(y); 
num_iters = 500; 
J_history = zeros(num_iters, 1); 
alpha = 0.1; 
theta = zeros(3, 1); 
for q = 1:m 
    A(q,:) = [2, (2*exp(theta(3, 1) * X(q, 1))), (2*theta(2, 1)*X(q, 1)*exp(theta(3, 1) * X(q, 1)))]; 
end  
for iter = 1:num_iters 
    num_theta = length(theta); 

    for j = 1:num_theta 
     inner_sum = 0; 
     for i = 1:m 
      inner_sum = inner_sum + (theta(2, 1)*(exp(X(i, 1)*theta(3, 1))) + theta(1, 1) - y(i, 1)) * A(i, j); 
     end 
     theta(j, 1) = theta(j, 1) - (alpha * inner_sum/m) 
    end 
    J_history(iter) = compute_cost(X, y); 
end 

    % Save the cost J in every iteration  
J_history(iter) = compute_cost(X, y); 
end 

其中compute_cost是我的成本功能是:

predictions = theta(2, 1)*(exp(X*theta(3, 1))) + theta(1, 1); %hypothesis    
sqrErrors = (predictions - y).^2;  
J = sum(sqrErrors)/(2*m); 

现在,这是我到达了一个断层,因为我的theta (3,1)==当θ的初始值为零时,theta2变为零(3,1) ,当我的初始θ值为1时,它取值无限(3,1)

因此,我可以使用这个假设进行线性回归,还是可以使用其他类似的假设函数来代替当前的假设。

+0

这里A是3 * 1矩阵,其是可变的,并且在梯度下降被用来证明J'(THETA),即相对于theta0,theta1,theta2偏微分 –

回答

相关问题