Last active
August 29, 2015 14:18
-
-
Save Prunus1350/7221f90753e869f74e63 to your computer and use it in GitHub Desktop.
kaggleの手書き文字データのクラス別主成分を描画
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%let home_dir = /folders/myfolders/kaggle/DigitRecognizer/; | |
* trainingデータ読み込み ; | |
data train; | |
infile "&home_dir.train.csv" dsd missover firstobs = 2; | |
input label pixel0 - pixel783; | |
run; | |
* 描画用テンプレート作成 ; | |
proc template; | |
define statgraph prin_digit; | |
begingraph; | |
rangeattrmap name="prange" ; | |
range min - 0 / rangecolormodel=(darkyellow white) ; | |
range 0 - max / rangecolormodel=(white blue) ; | |
endrangeattrmap ; | |
rangeattrvar attrvar=rangevar var=prin attrmap="prange" ; | |
layout overlay / yaxisopts=(reverse=true); | |
heatmapparm x = x y = y colorresponse = rangevar; | |
endlayout; | |
endgraph; | |
end; | |
run; | |
* 枠用データセット作成 ; | |
data waku; | |
do y = 1 to 28; | |
do x = 1 to 28; | |
output; | |
end; | |
end; | |
run; | |
%macro draw_prin(n=); | |
* 主成分分析 ; | |
proc princomp data = train outstat = __m1 noprint; | |
where label eq &n.; | |
var pixel:; | |
run; | |
* 第1主成分データを取得 ; | |
data prin1(keep=pixel:); | |
set __m1; | |
if (_type_ eq "SCORE") and (_name_ eq "Prin1"); | |
run; | |
* 転置 ; | |
proc transpose data = prin1 out = tprin1; | |
run; | |
* 枠用データセットをマージ ; | |
data temp2; | |
merge waku tprin1(keep=col1 rename=(col1=prin)); | |
run; | |
* 描画範囲を正方形にリサイズ ; | |
ods graphics / width = 500 height = 500; | |
* 描画 ; | |
proc sgrender data = temp2 template = prin_digit; | |
run; | |
ods graphics / reset = width reset = height; | |
%mend draw_prin; | |
%draw_prin(n=0); | |
%draw_prin(n=1); | |
%draw_prin(n=2); | |
%draw_prin(n=3); | |
%draw_prin(n=4); | |
%draw_prin(n=5); | |
%draw_prin(n=6); | |
%draw_prin(n=7); | |
%draw_prin(n=8); | |
%draw_prin(n=9); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment