Leading on from a previous question FCM Clustering numeric data and csv/excel file Im now trying to figure out how to take the outputed information and create a workable .dat file for use with clustering in 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{开发者_JAVA技巧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);
I have several types of data which looks like this:
I tried the below method to create a .dat file but came up with the error:
>> a = load('matlab.mat');
>> save 'matlab.dat' a -ascii
Warning: Attempt to write an unsupported data type
to an ASCII file.
Variable 'a' not written to file.
>> a = load('data.mat');
>> save 'matlab.dat' a -ascii
Warning: Attempt to write an unsupported data type
to an ASCII file.
Variable 'a' not written to file.
>> save 'matlab.dat' a
>> findcluster('matlab.dat')
??? Error using ==> load
Number of columns on line 1 of ASCII file
C:\Users\Garrith\Documents\MATLAB\matlab.dat
must be the same as previous lines.
Error in ==> findcluster>localloadfile at 471
load(filename);
Error in ==> findcluster at 160
localloadfile(filename, param);
Matlabs clustering tool works on multi-dimensional data sets, but only displays on two dimensions. You then use the x and y axis to compare against but im not quite sure if I will be able to create a clustering 2d analysis from the current data?
What I need to do is normalize the m file from my previous post FCM Clustering numeric data and csv/excel file
To normalize the data:
find the minimum and maximum dataset
Normalized scale minimum and maximum
Number in the data set
Normalized value
So first question is how do I find the minimum and maximum numbers in my dataset(m)
Step 1: Find the largest and smallest values in the data set and represent them with the variables capital A and capital B:
Lets say minimum number A = 92000
and max number say B = 64525000
Step 2 normalize Identify the smallest and largest numbers and set the variables to lower case a and b unsure how to do this in matlab (not sure how you normalize the data to start with)
set the minimum = a = 1
set the maximum = b = 10
step 3 calculate the normalized value of any number x using the equation
A = 92000
B = 64525000
a = 1
b = 10
x = 2214000
a + (x - A)(b - a)/(B - A)
1+(2214000 - 92000)(10-1)/(6425000 - 92000)
= 4.01
Looking at the errors in the middle of your question. a = load(matfile)
returns a structure, which is not supported by the ASCII-based MAT-file format. Try reading the documentation.
精彩评论