# Machine LearningMethodLogistic Classifier

Sample use In Octave:

```X = [m rows of training data, where each row is a vector of n input values.]
y = [is a vector of m correct values between 0 and num_labels]
num_labels = the number of possible different lables to find for the data
lambda = 0.1;
m = size(X, 1);
n = size(X, 2);
class_thetas = zeros(num_labels, n + 1);
X = [ones(m, 1) X]; %add a column of ones.
options = optimset('MaxIter', 50);
guess = zeros(n+1, 1);

for k = 1:num_labels;
[theta] = fmincg (@(t)(Cost(t, X, (y==k), lambda)), guess, options);
class_thetas(k,:)=theta';
end
```

At this point, we have a set of thetas to classify each label. To use those, given XX; a new matrix of test data, with rows of n input values:

```[confidence, label] = max(sigmoid( XX * class_thetas'), [], 2);
```

This example uses the standard Logistic Cost function, with Regularization.

```function [J, S] = cost(theta, X, y)
m = length(y);
hyp = sigmoid(X*theta);
%make a guess based on the sigmoid of our training data times our current paramaters.
costs = -y' * log(hyp) - (1-y)' * log(1-hyp); %cost with sigmoid function
J = sum(costs)/m + (lambda * sum(theta(2:end).^2) / (2*m)); %mean cost + regularization
err = (hyp .- y); %actual error.   %Note this happens to be the derivative of our cost function.
S = (X' * err)./m + (lambda .* [0;theta(2:end)] ./ m ); %slope of the error + regularization
end
```

 file: /Techref/method/ai/LogisticClassifier.htm, 1KB, , updated: 2015/8/29 11:50, local time: 2021/11/26 16:03, TOP NEW HELP FIND:  54.234.191.202:LOG IN

 ©2021 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?Please DO link to this page! Digg it! / MAKE! Machine Learning Method Logistic Classifier

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
 Did you find what you needed? "No. I'm looking for: " "No. Take me to the search page." "No. Take me to the top so I can drill down by catagory" "No. I'm willing to pay for help, please refer me to a qualified consultant" "No. But I'm interested. me at when this page is expanded."

 PICList 2021 contributors: o List host: MIT, Site host massmind.org, Top posters @20211126 Neil, Harold Hallikainen, Alan Pearce, RussellMc, Bob Blick, Allen Mulvey, Justin Richards, Dwayne Reid, madscientistatlarge, Sean Breheny, * Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr.

.