Knn score distance, Probablity density function, Histogram
7 views (last 30 days)
Show older comments
I am presently running a knnscoredistance test using two sets of data- a test and model set. I have then normalized the data using the norm command and plotted it as a histogram. However, I need to plot the data with the probability density function taken to really make the information meaningful. I have been unsuccessful at this for many days now and was curious if there is a method or command to do this. Also I think it could be interesting to run this test using various K values (1-10 at first) to generate 10 separate histograms but in the same plot. Do you know if this is an option. As of now I am doing this rewriting the code with the new value, but is a more concise method id available that would be ideal. I sincerely appreciate your time and help.
% INPUTS:
% xref = dataset of Training Set in evrimodel=.
% xtest = a dataset of testset in evrimodel.
xtest=importdata('Model_TestSet-Fixed.mat');
xref= importdata('Model_TrainingSet.mat');
%k=number of components
k=3;
%%creates a predicitive model based off training and test set
model=[knnscoredistance(xref,k)]
model_2=[knnscoredistance(xtest,k)]
model=model/norm(model)%%normalize data by plotting frequency on Y-axis
model_2=model_2/norm(model_2)
%%create histogram comparing both models
clf %clear figure window
hist(model,18)%create histogram with (data,nbins)
hold on
hist(model_2,18)
%%Training set in red and Test set in Green
h = findobj(gca,'Type','patch');
display(h)
set(h(1),'FaceColor','r','EdgeColor','k');
set(h(2),'FaceColor','g','EdgeColor','k');
set(gca,'xscale','log');%%log of x-axis
%%Labeling the histogram
xlabel('Standardized Distance (log)');
ylabel('#');
title('Knn Score Distance of Training and Test Set');
legend('Training Set','Test Set');
figure(1)
0 Comments
Answers (0)
See Also
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!