Created
February 18, 2013 20:30
-
-
Save dvreed77/4980426 to your computer and use it in GitHub Desktop.
Difference between Matlab's classify and ClassificationDiscriminant functions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Balanced Classes, easily seperable | |
data = [randn(2500, 1) ; 1 + randn(2500, 1)]; | |
labels = [zeros(2500, 1) ; ones(2500, 1)]; | |
y_pred = classify(data, data, labels); | |
TP1 = sum(y_pred == 1 & labels == 1); | |
temp = ClassificationDiscriminant.fit(data, labels); | |
y_pred2 = temp.predict(data); | |
TP2 = sum(y_pred2 == 1 & labels == 1); | |
fprintf('Data Easily Seperable (Balanced Classes): classify = %i, ClassificationDiscriminant = %i\n', TP1, TP2) | |
%% Unbalanced Classes, easily seperable | |
N1 = 3500; N2 = 1500; | |
data = [randn(N1, 1) ; 1 + randn(N2, 1)]; | |
labels = [zeros(N1, 1) ; ones(N2, 1)]; | |
y_pred = classify(data, data, labels); | |
TP1 = sum(y_pred == 1 & labels == 1); | |
temp = ClassificationDiscriminant.fit(data, labels); | |
y_pred2 = temp.predict(data); | |
TP2 = sum(y_pred2 == 1 & labels == 1); | |
fprintf('Data Easily Seperable (Unbalanced Classes): classify = %i, ClassificationDiscriminant = %i\n', TP1, TP2) | |
%% Same Distribution | |
data = randn(5000, 1); | |
labels = [zeros(N1, 1) ; ones(N2, 1)]; | |
y_pred = classify(data, data, labels); | |
TP1 = sum(y_pred == 1 & labels == 1); | |
temp = ClassificationDiscriminant.fit(data, labels); | |
y_pred2 = temp.predict(data); | |
TP2 = sum(y_pred2 == 1 & labels == 1); | |
fprintf('Data drawn from same distribution (Unbalanced Classes): classify = %i, ClassificationDiscriminant = %i\n', TP1, TP2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment