Data Analysis - Matlab Code

2 views (last 30 days)
I have a dataset(145 rows, 32 columns without id and attributes https://archive.ics.uci.edu/ml/datasets/Higher+Education+Students+Performance+Evaluation+Dataset ). I can read it in matlab with code. But I can't find the centered data matrix. I can find centered data matrix in another example.
D = randi([-5, 5] , 4,2] generate 8 numbers from -5 to 5 and I use size() ones() etc.
onesd = ones(size(D,1)1)
meand= mean(D)
D=onesd*meand then i find the centered data matrix
how can i write this dataset i have with centered data matrix
  1 Comment
Mustafa Furkan SAHIN
Mustafa Furkan SAHIN on 11 Dec 2022
clc
clear
dataset = xlsread('DATA.csv','DATA');
[m,n] = size(dataset)
Mean = mean(dataset)
Size = size(dataset, 1)
dataset2 = repmat(Mean,Size,1)
CenterMatrix = dataset - dataset2
Is this my code correct? Is such use acceptable?

Sign in to comment.

Accepted Answer

Torsten
Torsten on 11 Dec 2022
D = randi([-5, 5],4,2)
D = 4×2
4 -1 -2 -5 -4 -1 -2 -3
Cn = eye(size(D,1))-1/size(D,1)*ones(size(D,1))
Cn = 4×4
0.7500 -0.2500 -0.2500 -0.2500 -0.2500 0.7500 -0.2500 -0.2500 -0.2500 -0.2500 0.7500 -0.2500 -0.2500 -0.2500 -0.2500 0.7500
D_centered = Cn*D
D_centered = 4×2
5.0000 1.5000 -1.0000 -2.5000 -3.0000 1.5000 -1.0000 -0.5000
mean(D_centered,1)
ans = 1×2
0 0
  10 Comments
Torsten
Torsten on 13 Dec 2022
Yes, it's correct. See above.
Mustafa Furkan SAHIN
Mustafa Furkan SAHIN on 13 Dec 2022
That's great. Thanks for taking the time,Torsten

Sign in to comment.

More Answers (1)

Steven Lord
Steven Lord on 12 Dec 2022
I would use the normalize function or the Normalize Data task in Live Editor.
  2 Comments
Torsten
Torsten on 12 Dec 2022
It's only asked for mean 0, not standard deviation 1. Is this also possible with "normalize" ?
Steven Lord
Steven Lord on 12 Dec 2022
The normalize function can center without scaling:
format longg
x = rand(1, 10);
n = normalize(x, 'center');
[mean(n), std(n)]
ans = 1×2
-1.11022302462516e-17 0.266647564148699
scale without centering:
s = normalize(x, 'scale');
[mean(s), std(s)]
ans = 1×2
2.19316158923735 1
or both center and scale.
z = normalize(x); % 'zscore' is the default
[mean(z), std(z)]
ans = 1×2
-5.55111512312578e-18 1
There are other normalization options as well.

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!