问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501
你好,欢迎来到懂视!登录注册
当前位置: 首页 - 正文

文本分类器(基于KNN算法),语言最好是Matlab的,有测试数据集。。。。

发布网友 发布时间:2022-04-24 02:31

我来回答

3个回答

热心网友 时间:2023-10-22 04:03

function [ccr,pgroupt]=knnt(x,group,K,dist,xt,groupt)
%#
%# AIM: to classify test set objects or unknown objects with the
%#K Nearest Neighbour method
%#
%# PRINCIPLE: KNN is a supervised, deterministic, non-parametric
%#classification method. It uses the majority rule to
%#assign new objects to a class.
%#It is assumed that the number of objects in each class
%#is similar.
%# There are no assumptions about the data distribution and
%#the variance-covariance matrices of each class.
%#There is no limitation of the number of variables when
%#the Euclidean distance is used.
%#However, when the correlation coefficient is used, the
%#number of variables must be larger than 1.
%#Ref: Massart D. L., Vandeginste B. G. M., Deming S. N.,
%#Michotte Y. and Kaufman L., Chemometrics: a textbook,
%#Chapter 23, 395-397, Elsevier Science Publishers B. V.,
%#Amsterdam 1988.
%#
%# INPUT:x: (mxn) data matrix with m objects and n variables,
%# containing samples of several classes (training set)
%#group: (mx1) column vector labelling the m objects from the
%#training set
%# K:integer, number of nearest neighbours
%# dist:integer,
%#= 1, Euclidean distance
%#= 2, Correlation coefficient, (No. of variables >1)
%# xt: (mtxn) data matrix with mt objects and n variables
%#(test set or unknowns)
%#groupt: (mtx1) column vector labelling the mt objects from
%#the test set
%#--> if the new objects are unknown, input [].
%#
%# OUTPUT:ccr:scalar, correct classification rate
%# pgroupt:row vector, predicted class label for the test set
%#0 means that the object is not classified to any
%#class
%#
%# SUBROUTINES: sortlab.m: sorts the group label vector into classes
%#
%# AUTHOR: Wen Wu
%# Copyright(c) 1997 for ChemoAc
%# FABI, Vrije Universiteit Brussel
%# Laarbeeklaan 103 1090 Jette
%#
%# VERSION: 1.1 (28/02/1998)
%#
%# TEST: Andrea Candolfi
%#

function [ccr,pgroupt]=knnt(x,group,K,dist,xt,groupt);

if nargin==5, groupt=[]; end % for unknown objects
distance=dist; clear dist % change variable
if size(group,1)>1,
group=group'; % change column vector into row vector
groupt=groupt'; % change column vector into row vector
end;
[m,n]=size(x); % size of the training set

if distance==2 & n<2, error('Number of variables must > 1'),end% to check the number of variables when using correlation coefficient

[mt,n]=size(xt); % size of the test set
dis=zeros(mt,m);% initial values for the distance (matrix of zeros)

% Calculation of the distance for each test set object
for i=1:mt
for j=1:m % between each training set object and each test set object
if distance==1
dis(i,j)=(xt(i,:)-x(j,:))*(xt(i,:)-x(j,:))';% Euclidian distance
else
r=corrcoef(xt(i,:)',x(j,:)');% Correlation coefficient matrix
r=r(1,2);% Correlation coefficient
dis(i,j)=1-r*r; % 1 - the power of correlation coefficient
end
end
end

% Finding of the nearest neighbours
lab=zeros(1,mt);% initial values of lab
for i=1:mt% for each test object
[a,b]=sort(dis(i,:));% sort distances
b=b(find(a<=a(K)));% to find the nearest neighbours indices
b=group(b);% the nearest neighbours objects
[ng,lgroup]=sortlab(b);% calculate the number of objects from each class in the nearest neighbours
a=find(ng==max(ng));% find the class with the maximum number of objects

if length(a)==1% only one class
lab(i)=lgroup(a);% class label
else
lab(i)=0;% more than one class
end
end

% Calculation of the success rate
if ~isempty(groupt)
dif=groupt-lab;% difference between predicted class label and known class label
ccr=sum(dif==0)/mt;% success rate
end

pgroupt=lab;% the output vector

热心网友 时间:2023-10-22 04:03


好像这些算法在数据缺失的情况下是没法进行的吧,只能说改进之后在数据缺失情况下做了相应处理,你说的这些算法都可以在网上找到代码

热心网友 时间:2023-10-22 04:04

ME5

热心网友 时间:2023-10-22 04:03

function [ccr,pgroupt]=knnt(x,group,K,dist,xt,groupt)
%#
%# AIM: to classify test set objects or unknown objects with the
%#K Nearest Neighbour method
%#
%# PRINCIPLE: KNN is a supervised, deterministic, non-parametric
%#classification method. It uses the majority rule to
%#assign new objects to a class.
%#It is assumed that the number of objects in each class
%#is similar.
%# There are no assumptions about the data distribution and
%#the variance-covariance matrices of each class.
%#There is no limitation of the number of variables when
%#the Euclidean distance is used.
%#However, when the correlation coefficient is used, the
%#number of variables must be larger than 1.
%#Ref: Massart D. L., Vandeginste B. G. M., Deming S. N.,
%#Michotte Y. and Kaufman L., Chemometrics: a textbook,
%#Chapter 23, 395-397, Elsevier Science Publishers B. V.,
%#Amsterdam 1988.
%#
%# INPUT:x: (mxn) data matrix with m objects and n variables,
%# containing samples of several classes (training set)
%#group: (mx1) column vector labelling the m objects from the
%#training set
%# K:integer, number of nearest neighbours
%# dist:integer,
%#= 1, Euclidean distance
%#= 2, Correlation coefficient, (No. of variables >1)
%# xt: (mtxn) data matrix with mt objects and n variables
%#(test set or unknowns)
%#groupt: (mtx1) column vector labelling the mt objects from
%#the test set
%#--> if the new objects are unknown, input [].
%#
%# OUTPUT:ccr:scalar, correct classification rate
%# pgroupt:row vector, predicted class label for the test set
%#0 means that the object is not classified to any
%#class
%#
%# SUBROUTINES: sortlab.m: sorts the group label vector into classes
%#
%# AUTHOR: Wen Wu
%# Copyright(c) 1997 for ChemoAc
%# FABI, Vrije Universiteit Brussel
%# Laarbeeklaan 103 1090 Jette
%#
%# VERSION: 1.1 (28/02/1998)
%#
%# TEST: Andrea Candolfi
%#

function [ccr,pgroupt]=knnt(x,group,K,dist,xt,groupt);

if nargin==5, groupt=[]; end % for unknown objects
distance=dist; clear dist % change variable
if size(group,1)>1,
group=group'; % change column vector into row vector
groupt=groupt'; % change column vector into row vector
end;
[m,n]=size(x); % size of the training set

if distance==2 & n<2, error('Number of variables must > 1'),end% to check the number of variables when using correlation coefficient

[mt,n]=size(xt); % size of the test set
dis=zeros(mt,m);% initial values for the distance (matrix of zeros)

% Calculation of the distance for each test set object
for i=1:mt
for j=1:m % between each training set object and each test set object
if distance==1
dis(i,j)=(xt(i,:)-x(j,:))*(xt(i,:)-x(j,:))';% Euclidian distance
else
r=corrcoef(xt(i,:)',x(j,:)');% Correlation coefficient matrix
r=r(1,2);% Correlation coefficient
dis(i,j)=1-r*r; % 1 - the power of correlation coefficient
end
end
end

% Finding of the nearest neighbours
lab=zeros(1,mt);% initial values of lab
for i=1:mt% for each test object
[a,b]=sort(dis(i,:));% sort distances
b=b(find(a<=a(K)));% to find the nearest neighbours indices
b=group(b);% the nearest neighbours objects
[ng,lgroup]=sortlab(b);% calculate the number of objects from each class in the nearest neighbours
a=find(ng==max(ng));% find the class with the maximum number of objects

if length(a)==1% only one class
lab(i)=lgroup(a);% class label
else
lab(i)=0;% more than one class
end
end

% Calculation of the success rate
if ~isempty(groupt)
dif=groupt-lab;% difference between predicted class label and known class label
ccr=sum(dif==0)/mt;% success rate
end

pgroupt=lab;% the output vector

热心网友 时间:2023-10-22 04:03


好像这些算法在数据缺失的情况下是没法进行的吧,只能说改进之后在数据缺失情况下做了相应处理,你说的这些算法都可以在网上找到代码

热心网友 时间:2023-10-22 04:04

ME5

热心网友 时间:2023-10-22 04:03

function [ccr,pgroupt]=knnt(x,group,K,dist,xt,groupt)
%#
%# AIM: to classify test set objects or unknown objects with the
%#K Nearest Neighbour method
%#
%# PRINCIPLE: KNN is a supervised, deterministic, non-parametric
%#classification method. It uses the majority rule to
%#assign new objects to a class.
%#It is assumed that the number of objects in each class
%#is similar.
%# There are no assumptions about the data distribution and
%#the variance-covariance matrices of each class.
%#There is no limitation of the number of variables when
%#the Euclidean distance is used.
%#However, when the correlation coefficient is used, the
%#number of variables must be larger than 1.
%#Ref: Massart D. L., Vandeginste B. G. M., Deming S. N.,
%#Michotte Y. and Kaufman L., Chemometrics: a textbook,
%#Chapter 23, 395-397, Elsevier Science Publishers B. V.,
%#Amsterdam 1988.
%#
%# INPUT:x: (mxn) data matrix with m objects and n variables,
%# containing samples of several classes (training set)
%#group: (mx1) column vector labelling the m objects from the
%#training set
%# K:integer, number of nearest neighbours
%# dist:integer,
%#= 1, Euclidean distance
%#= 2, Correlation coefficient, (No. of variables >1)
%# xt: (mtxn) data matrix with mt objects and n variables
%#(test set or unknowns)
%#groupt: (mtx1) column vector labelling the mt objects from
%#the test set
%#--> if the new objects are unknown, input [].
%#
%# OUTPUT:ccr:scalar, correct classification rate
%# pgroupt:row vector, predicted class label for the test set
%#0 means that the object is not classified to any
%#class
%#
%# SUBROUTINES: sortlab.m: sorts the group label vector into classes
%#
%# AUTHOR: Wen Wu
%# Copyright(c) 1997 for ChemoAc
%# FABI, Vrije Universiteit Brussel
%# Laarbeeklaan 103 1090 Jette
%#
%# VERSION: 1.1 (28/02/1998)
%#
%# TEST: Andrea Candolfi
%#

function [ccr,pgroupt]=knnt(x,group,K,dist,xt,groupt);

if nargin==5, groupt=[]; end % for unknown objects
distance=dist; clear dist % change variable
if size(group,1)>1,
group=group'; % change column vector into row vector
groupt=groupt'; % change column vector into row vector
end;
[m,n]=size(x); % size of the training set

if distance==2 & n<2, error('Number of variables must > 1'),end% to check the number of variables when using correlation coefficient

[mt,n]=size(xt); % size of the test set
dis=zeros(mt,m);% initial values for the distance (matrix of zeros)

% Calculation of the distance for each test set object
for i=1:mt
for j=1:m % between each training set object and each test set object
if distance==1
dis(i,j)=(xt(i,:)-x(j,:))*(xt(i,:)-x(j,:))';% Euclidian distance
else
r=corrcoef(xt(i,:)',x(j,:)');% Correlation coefficient matrix
r=r(1,2);% Correlation coefficient
dis(i,j)=1-r*r; % 1 - the power of correlation coefficient
end
end
end

% Finding of the nearest neighbours
lab=zeros(1,mt);% initial values of lab
for i=1:mt% for each test object
[a,b]=sort(dis(i,:));% sort distances
b=b(find(a<=a(K)));% to find the nearest neighbours indices
b=group(b);% the nearest neighbours objects
[ng,lgroup]=sortlab(b);% calculate the number of objects from each class in the nearest neighbours
a=find(ng==max(ng));% find the class with the maximum number of objects

if length(a)==1% only one class
lab(i)=lgroup(a);% class label
else
lab(i)=0;% more than one class
end
end

% Calculation of the success rate
if ~isempty(groupt)
dif=groupt-lab;% difference between predicted class label and known class label
ccr=sum(dif==0)/mt;% success rate
end

pgroupt=lab;% the output vector

热心网友 时间:2023-10-22 04:03


好像这些算法在数据缺失的情况下是没法进行的吧,只能说改进之后在数据缺失情况下做了相应处理,你说的这些算法都可以在网上找到代码

热心网友 时间:2023-10-22 04:04

ME5
声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com
罗马帝国包含哪些国家 电脑备忘录怎么设置农历日期提醒如何在电脑桌面上设置日程安排表_百 ... 电脑桌面如何设置日历便签怎样在电脑桌面设置便签 苹果8p卡贴机怎么激活 书籍装帧设计包含哪些要素 铜壶烧水用什么好处 刚买的联想zukz1新手机一点电都没有么 ...显示不变,用了好久,突然间没电自动关机,充满电为100%,用几分钟后... 表达不想结婚的句子对婚姻充满恐惧的说说 我是女生今年26了、非常恐惧婚姻、我根本不想结婚、我自己自由自在过得... 将取消企业自愿测评申请 C-NCAP:谁还说我是“五星批发部”?? 辅警是警察吗?做辅警需要文化吗?考试吗? 淘宝已下单的怎么改地址 宜家枕头哪个好 兆欧表的工作原理是什么样的? 如何保持pmp的资格呢? pmp考试中的pdu,是不是只要交钱就能得到呢? frm二级只看金程的网课能通过吗?有通过的朋友分享点经验 15年护师考试要掌握的重要计算公式 PM认证中,什么是一个CCR周期? 要结婚了,不知道婚庆用品买哪些?有没有专门的婚庆网站? 大家帮忙起个婚庆类网站名字,谢谢 什么是网络婚礼? 有一个专门搞婚庆的网站,有好多婚礼视频,好像是叫什么池网,好像是上海的。清请高人指点。 去哪些婚礼网站上可以看到婚的礼视频或图片? 什么叫一站式婚礼服务网站?为什么说婚礼工场是这样的网站? 在中国比较出名的婚庆网? 最靠谱的最全的最好的婚礼网站有那些啊? 找婚礼素材 有哪些网站? 听说有一个网站叫什么婚庆网的,好像关于婚礼方面的内容挺丰富的,是什么呢? 日产轩逸车电瓶测试值88ccR电压12.79温度14.C要不要更换电瓶,才用一年。 求2012新东方【屠皓民】考研英语四小时精品语法课程视频,一到四的…… sgs检测报告中N20P(不含20种邻笨包括那些) 买车的注意事项有哪些? 买车时应该注意哪些点? 买车的注意事项? 购买汽车时,应该注意什么? 购车需要注意什么事项 华为手机,建议更新吗?我有128内存,现在还有八九十多,建议更新吗? 华为手机系统更新有好处吗?有没有什么注意事项?更新后有没有弊端? 华为手机升级好不好 华为手机系统软件更新好吗 QQ互动标识黑胶唱片怎么获得? 华为手机升级到最新版本好用吗? qq怎么获得神仙眷侣? 车子在外地可以过户吗 车在异地可以办理过户吗 外地车能不能在异地过户 苹果内存满了无法使用怎么办 cpa2022年报名和考试时间
  • 焦点

最新推荐

猜你喜欢

热门推荐