FCM群集数值数据和csv/excel文件 [英] FCM Clustering numeric data and csv/excel file

查看:111
本文介绍了FCM群集数值数据和csv/excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问了一个可以给出合理答案的先前问题,我以为我回到了正轨,解决方案

这里是一个示例,说明了如何将数据读入MATLAB.您需要两件事:以逗号分隔格式的数据本身,以及功能列表及其类型(数字,标称).

%# read the list of features
fid = fopen('kddcup.names','rt');
C = textscan(fid, '%s %s', 'Delimiter',':', 'HeaderLines',1);
fclose(fid);

%# determine type of features
C{2} = regexprep(C{2}, '.$','');              %# remove "." at the end
attribNom = [ismember(C{2},'symbolic');true]; %# nominal features

%# build format string used to read/parse the actual data
frmt = cell(1,numel(C{1}));
frmt( ismember(C{2},'continuous') ) = {'%f'}; %# numeric features: read as number
frmt( ismember(C{2},'symbolic') ) = {'%s'};   %# nominal features: read as string
frmt = [frmt{:}];
frmt = [frmt '%s'];                           %# add the class attribute

%# read dataset
fid = fopen('kddcup.data','rt');
C = textscan(fid, frmt, 'Delimiter',',');
fclose(fid);

%# convert nominal attributes to numeric
ind = find(attribNom);
G = cell(numel(ind),1);
for i=1:numel(ind)
    [C{ind(i)},G{i}] = grp2idx( C{ind(i)} );
end

%# all numeric dataset
M = cell2mat(C);

您还可以从统计信息工具箱中查看 DATASET

Hi I asked a previous question that gave a reasonable answer and I thought I was back on track, Fuzzy c-means tcp dump clustering in matlab the problem is the preprocessing stage of the below tcp/udp data that I would like to run through matlabs fcm clustering algorithm.My question:

1) how do i or what would be the best method to convert the text data in the cells to a numeric value? what should the numeric value be?

Edit: My data in excel looks like this now:

0,tcp,http,SF,239,486,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,8,8,0.00,0.00,0.00,0.00,1.00,0.00,0.00,19,19,1.00,0.00,0.05,0.00,0.00,0.00,0.00,0.00,normal.

解决方案

Here is an example how I would read the data into MATLAB. You need two things: the data itself which is in comma-separated format, as well as the list of features along with their types (numeric,nominal).

%# read the list of features
fid = fopen('kddcup.names','rt');
C = textscan(fid, '%s %s', 'Delimiter',':', 'HeaderLines',1);
fclose(fid);

%# determine type of features
C{2} = regexprep(C{2}, '.$','');              %# remove "." at the end
attribNom = [ismember(C{2},'symbolic');true]; %# nominal features

%# build format string used to read/parse the actual data
frmt = cell(1,numel(C{1}));
frmt( ismember(C{2},'continuous') ) = {'%f'}; %# numeric features: read as number
frmt( ismember(C{2},'symbolic') ) = {'%s'};   %# nominal features: read as string
frmt = [frmt{:}];
frmt = [frmt '%s'];                           %# add the class attribute

%# read dataset
fid = fopen('kddcup.data','rt');
C = textscan(fid, frmt, 'Delimiter',',');
fclose(fid);

%# convert nominal attributes to numeric
ind = find(attribNom);
G = cell(numel(ind),1);
for i=1:numel(ind)
    [C{ind(i)},G{i}] = grp2idx( C{ind(i)} );
end

%# all numeric dataset
M = cell2mat(C);

You could also look into the DATASET class from the Statistics Toolbox.

这篇关于FCM群集数值数据和csv/excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆