Question

In: Electrical Engineering

knn based classification with pcasvd reduction technique apply it for classification.function parts are nedded. Write a...

knn based classification with pcasvd reduction technique apply it for classification.function parts are nedded.

Write a matlab code

if you know the answer then only write.or else leave it for others.

image processing ELETRICAL

Solutions

Expert Solution

ans:

function result = knnclassification(testsamplesX,samplesX, samplesY, Knn,type)

% Classify using the Nearest neighbor algorithm

% Inputs:

% samplesX - Train samples

% samplesY - Train labels

% testsamplesX - Test samples

% Knn - Number of nearest neighbors

%

% Outputs

% result - Predicted targets

if nargin < 5

type = '2norm';

end

L = length(samplesY);

Uc = unique(samplesY);

if (L < Knn),

error('You specified more neighbors than there are points.')

end

N = size(testsamplesX, 1);

result = zeros(N,1);

switch type

case '2norm'

for i = 1:N,

dist = sum((samplesX - ones(L,1)*testsamplesX(i,:)).^2,2); %rowwise sum

[m, indices] = sort(dist);  

n = hist(samplesY(indices(1:Knn)), Uc);

[m, best] = max(n);

result(i) = Uc(best);

end

case '1norm'

for i = 1:N,

dist = sum(abs(samplesX - ones(L,1)*testsamplesX(i,:)),2);

[m, indices] = sort(dist);

n = hist(samplesY(indices(1:Knn)), Uc);

[m, best] = max(n);

result(i) = Uc(best);

end

case 'match'

for i = 1:N,

dist = sum(samplesX == ones(L,1)*testsamplesX(i,:),2);

[m, indices] = sort(dist);

n = hist(samplesY(indices(1:Knn)), Uc);

[m, best] = max(n);

result(i) = Uc(best);

end

otherwise

error('Unknown measure function');

end

%% RUN command:- result = knnclassification(featureVectorNorm,featureVectorNorm, targetVector, 1,'2norm')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% this is sometimes faster than the transpose eigenvalue method with

% very large dimensions and small no. of examples

function [U,d] = pcasvd(X,n,smallest)

% X : nt x n, where nt examples of feature vecs of size n

% n returns n dimensions

% smallest is 1 when we want the evecs assoc with the smallest evals

% % U is evecs, d is diagonals

% Copyright (c) 2013, Vipin Vijayan.

if nargin < 3, smallest = 0; end;

[U,S] = svd(X,'econ');

s = diag(S);

if ~smallest,

tol = max(size(X)) * max(s) * eps(class(X));

n = min(n, sum(s > tol));

U = U(:,1:n);

s = s(1:n);

else

n = min(n, size(U,2));

U = U(:,end:-1:end-n+1);

s = s(end:-1:end-n+1);

end

d = s.^2; % D = diag(s.^2);

end


Related Solutions

A classification technique is a systematic approach to building classification models. Examples include, but are not...
A classification technique is a systematic approach to building classification models. Examples include, but are not limited to, decision trees, neural networks, and naïve Bayes and Bayesian approaches. Examine some data in an organization you are familiar with, that is a candidate for classification. Describe the data under consideration. Which classification technique did you select and why? How can your organization benefit from using this classification model?
A classification technique (or classifier) is a systematic approach to building classification models from an input...
A classification technique (or classifier) is a systematic approach to building classification models from an input data set. Examples include decision tree classifiers, rule-based classifiers, neural networks, support vector machines, and naïve Bayes classifiers. In your own words, describe each of these techniques and provide a scenario in which each technique would be most appropriate. Use your textbook and outside resources in the formulation of your response. Cite the sources you use to make your response.
kNN Function: Create a function called predictKNN(). Your function will return the classification of your data-pointIn...
kNN Function: Create a function called predictKNN(). Your function will return the classification of your data-pointIn addition to any parameters you see fit, your function should accept: k a data-point: a vector of r numbers a dataframe with r columns. Run your function at least 5 times with different parameters. If your data does not have a classification column, use the results from your unsupervised learning as the classification. sl_no gender ssc_p ssc_b hsc_p hsc_b hsc_s degree_p degree_t workex etest_p...
Using R Question 3. kNN Classification 3.1 Read in iris dataset using “data(iris)”. Describe the features...
Using R Question 3. kNN Classification 3.1 Read in iris dataset using “data(iris)”. Describe the features in the data using summary 3.2 Randomize the iris data set, mix it up and normalize it 3.3 split data into training & testing (70/30 split) 3.4 Train model in data and use crosstable function to evaluate the results 3.5 Rerun your code for K=10 and 100. Compare results and explain
This is a maching learning question. Using the Kaggle diamonds dataset, build a KNN based estimator...
This is a maching learning question. Using the Kaggle diamonds dataset, build a KNN based estimator for estimating the price of a diamond and propose an appropriate K value. Please use python and google colab format. Thank you!
Discuss cost classification based on variability and controllability..
Discuss cost classification based on variability and controllability..
write down the classification order of ferrites
write down the classification order of ferrites
Methodology (with images) How to apply staining technique for animal and plant cells?
Methodology (with images) How to apply staining technique for animal and plant cells?
Apply the classification algorithm to the following set of data records. Draw a decision tree. The...
Apply the classification algorithm to the following set of data records. Draw a decision tree. The class attribute is Repeat Customer. RID Age City Gender Education Repeat Customer 101 20..30 NY F College YES 102 20..30 SF M Graduate YES 103 31..40 NY F College YES 104 51..60 NY F College NO 105 31..40 LA M High school NO 106 41..50 NY F College YES 107 41..50 NY F Graduate YES 108 20..30 LA M College YES 109 20..30 NY...
A battery is constructed based on the oxidation of magnesium and the reduction of Cu2+. The...
A battery is constructed based on the oxidation of magnesium and the reduction of Cu2+. The initial concentrations of Mg2+ and Cu2+ are 1.2×10−4 M and 1.5 M , respectively, in 1.0-liter half-cells. A)What is the initial voltage of the battery?    B)What is the voltage of the battery after delivering 5.0 A for 8.0 h ? C) What are the concentrations of Mg2+ and Cu2+ when the cell is dead? D)  How long can the battery deliver 5.0 A before...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT