Question
Visualize the data, display it on a 2-dimensional plot by calling the function plotData to display a 1, where the axes are the two exam
Visualize the data, display it on a 2-dimensional plot by calling the function plotData to display a 1, where the axes are the two exam scores, and the positive and negative examples are shown with different markers. = 1) examples and o indicating (y = 0) % Plot the data with + indicating (y examples. plotData(x, y); % Labels and Legend xlabel('Exam 1 score') ylabel('Exam 2 score') % Specified in plot order legend('Admitted', 'Not admitted') function plotData(x, y) %PLOTDATA Plots the data points X and y into a new figure % PLOTDATA(x,y) plots the data points with + for the positive examples % and o for the negative examples. X is assumed to be a Mx2 matrix. % Create New Figure; hold on; % Instructions: Plot the positive and negative examples on a % 2D plot, using the option 'k+' for the positive % examples and 'ko' for the negative examples. % % Find Indices of Positive and negative Examples pos = find(y==1); neg = find(y == 0); % Plot Examples plot(X(pos, 1), X(pos, 2), 'k+', 'LineWidth', 2, 'MarkerSize', 7); plot(X(neg, 1), X(neg, 2), 'ko', 'MarkerFaceColor', 'y', 'MarkerSize', 7); hold off; end
Sol64:
The code is written in MATLAB/Octave and consists of two functions: plotData and main. The main function loads the data from a text file, calls the plotData function to display the data, and then sets the labels and legend for the plot.
The plotData function takes two arguments, x and y, which represent the feature values and labels, respectively. The function first finds the indices of the positive and negative examples based on the label values. It then creates a new figure and uses the plot function to display the positive examples as black crosses ('k+') and negative examples as yellow circles ('ko') with a black border.
Finally, the hold off command is used to stop adding elements to the current figure, and the function ends.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started