Skip to content

Commit f52c69d

Browse files
author
Quinn Liu
committed
added code for ploting input training set
1 parent 51c7795 commit f52c69d

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

supervisedLearning/logisticRegression/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Using Logistic Regression For Prediction
33

44
This specific folder contains an example of using logistic regression to predict
55
whether a student gets admitted into a university or not. But understand that by
6-
just giving a different ```inputTrainingSet.txt``` file you can easily use logistic
6+
just giving a different ```ex2data1.txt``` file you can easily use logistic
77
regression to predict something you want!
88

99
<h2>How to use this code:</h2>

supervisedLearning/logisticRegression/ex2.m

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,26 @@
55

66
%% Load Data
77
% The first two columns contains the exam scores and the third column
8-
% contains the label.
8+
% contains the label
99

1010
data = load('ex2data1.txt');
11-
X = data(:, [1, 2]); y = data(:, 3);
12-
13-
%% ==================== Part 1: Plotting ====================
14-
% We start the exercise by first plotting the data to understand the
15-
% the problem we are working with.
11+
X = data(:, [1, 2]); % X is a #OfExamScores x 2 matrix
12+
y = data(:, 3); % y is a #OfExamScores x 1 matrix
1613

14+
% It's always a good idea to first plot the problem to solve
1715
fprintf(['Plotting data with + indicating (y = 1) examples and o ' ...
1816
'indicating (y = 0) examples.\n']);
19-
2017
plotData(X, y);
2118

2219
% Put some labels
2320
hold on;
2421
% Labels and Legend
22+
title('Acceptance of Previous Students Based on Scores on 2 Exams')
2523
xlabel('Exam 1 score')
2624
ylabel('Exam 2 score')
2725

2826
% Specified in plot order
29-
legend('Admitted', 'Not admitted')
27+
legend('Admitted Students', 'Not admitted Students')
3028
hold off;
3129

3230
fprintf('\nProgram paused. Press enter to continue.\n');

supervisedLearning/logisticRegression/plotData.m

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@ function plotData(X, y)
1212
% examples and 'ko' for the negative examples.
1313
%
1414

15-
16-
17-
18-
19-
20-
21-
22-
23-
% =========================================================================
24-
25-
15+
% Find indices of positive and negative examples
16+
indicesOfPositiveLabels = find(y == 1);
17+
indicedOfNegativeLabels = find(y == 0);
18+
19+
plot(X(indicesOfPositiveLabels, 1), X(indicesOfPositiveLabels, 2),
20+
'k+', 'LineWidth', 2, 'MarkerSize', 7);
21+
plot(X(indicedOfNegativeLabels, 1), X(indicedOfNegativeLabels, 2),
22+
'ko', 'MarkerFaceColor', 'y', 'MarkerSize', 7);
2623

2724
hold off;
2825

0 commit comments

Comments
 (0)