Data Analysis - Matlab Code

3 ビュー (過去 30 日間)
Mustafa Furkan SAHIN
Mustafa Furkan SAHIN 2022 年 12 月 11 日
コメント済み: Mustafa Furkan SAHIN 2022 年 12 月 13 日
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
Mustafa Furkan SAHIN 2022 年 12 月 11 日
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
Mustafa Furkan SAHIN 2022 年 12 月 13 日
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