Data Analysis - Matlab Code

1 次查看(过去 30 天)
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 个评论
Mustafa Furkan SAHIN
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?

请先登录,再进行评论。

采纳的回答

Torsten
Torsten 2022-12-11
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 个评论
Torsten
Torsten 2022-12-13
Yes, it's correct. See above.
Mustafa Furkan SAHIN
That's great. Thanks for taking the time,Torsten

请先登录,再进行评论。

更多回答(1 个)

Steven Lord
Steven Lord 2022-12-12
I would use the normalize function or the Normalize Data task in Live Editor.
  2 个评论
Torsten
Torsten 2022-12-12
It's only asked for mean 0, not standard deviation 1. Is this also possible with "normalize" ?
Steven Lord
Steven Lord 2022-12-12
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.

请先登录,再进行评论。

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by