Zhou Zhihua Watermelon Book Exercise 3.3

Source: Internet
Author: User

Title: Programming to achieve rate regression, data set given.
Emmm, there are few datasets, I'm using Newton's iteration. Also given in the formula book, the proof is not very complicated, omitted.

x = Load ("Input.txt");
y = Load ("output.txt");

theta = Zeros (3, 1);

m = Size (x, 1);
x = [x, ones (Size (x, 1), 1)];
%y

for i = 0:10 first
    = Zeros (3, 1);
    Second = zeros (3, 3);
    For j = 1:m
        xx = (x (j,:)) ';        
        First = First-xx * (Y (j, 1)-(exp (theta ' * xx)/(1 + exp (theta ' * xx))));
        Second = second + xx * xx ' * (exp (theta ' * xx)/((1 + exp (theta ' * xx)) * (1 + exp (theta ' * xx))));
    End
    theta = THETA-INV (second) * FIRST;
End for

i = 1:m
    if y (i) = = 1
        plot (x (I, 1), X (I, 2), ' X ');
        Hold on;
    else
        plot (x (I, 1), X (I, 2), ' O ');
        Hold on;
    End
End

% Three paragraphs not original, I paste myself from http://blog.csdn.net/icefire_tyh/article/details/52068844
% To verify that my results are the same as the big Guy's.
%ply =-(0.1 * THETA (1) + theta (3))/theta (2);
%pry =-(0.9 * THETA (1) + theta (3))/theta (2);
%line ([0.1 0.9], [ply pry]);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.