Help us understand the problem. What is going on with this article?

SAS Viyaでグルーピングした結果を別テーブルに保存する

SAS ViyaはAIプラットフォームです。大量のデータを素早く分析したり、機械学習を用いて新しいデータの分類や判別をすることができます。開発者であればJupyter Notebookを使ってデモ環境で試すことができます。

今回はデータの簡易的な分類分けを行い、その結果をテーブルに保存する方法を紹介します。

元データについて

元データはGitHubにて公開しているcars.csvです。

まずデータをグルーピングします。

cars = conn.CASTable('cars')
cars.groupby=['Origin']
cars.where = 'MSRP < 100000 and MPG_City < 40'
nomList = ['Type','DriveTrain']
contList = ['MPG_City','Weight','Length']

そして、そのデータの一般線形化モデル(GLM)を取得します。

linear4 = cars.glm

出力先の定義と設定

そして、この線形モデルの出力先を設定します。

linear4.output.casout = conn.CASTable('MSRPPredictionGroupBy')

後はデータを設定し、最後にlinear4を実行して終了です。

linear4.target = 'MSRP'
linear4.inputs = nomList + contList
linear4.nominals = nomList
linear4.display.names = ['FitStatistics','ParameterEstimates']
linear4.output.copyVars = 'ALL';
linear4.output.pred = 'Predicted_MSRP'
linear4.output.resid = 'Residual_MSRP'
linear4.output.lcl = 'LCL_MSRP'
linear4.output.ucl = 'UCL_MSRP'
linear4()

出力

結果は以下のように出てきます。

§ ByGroupInfo
BY Groups
Origin Origin_f _key_
0 Asia Asia Asia
1 Europe Europe Europe
2 USA USA USA



§ ByGroup1.FitStatistics



Fit Statistics


























































RowId Description Value
Origin
Asia RMSE Root MSE 7.023321e+03
Asia RSQUARE R-Square 6.432711e-01
Asia ADJRSQ Adj R-Sq 6.211293e-01
Asia AIC AIC 2.912330e+03
Asia AICC AICC 2.914176e+03
Asia SBC SBC 2.785764e+03
Asia TRAIN_ASE ASE 4.614465e+07




§ ByGroup1.ParameterEstimates



Parameter Estimates












































































































































































Effect Type DriveTrain Parameter DF Estimate StdErr tValue Probt
Origin
Asia Intercept Intercept 1 -7800.227372 19135.597840 -0.407629 6.841472e-01
Asia Type SUV Type SUV 1 -968.795973 2805.772482 -0.345287 7.303792e-01
Asia Type Sedan Type Sedan 1 3766.422921 2436.960318 1.545541 1.243951e-01
Asia Type Sports Type Sports 1 9154.062848 2929.463572 3.124826 2.149295e-03
Asia Type Truck Type Truck 1 -11550.233853 3982.945107 -2.899923 4.313916e-03
Asia Type Wagon Type Wagon 0 0.000000 NaN NaN NaN
Asia DriveTrain All DriveTrain All 1 -8003.325899 2150.711618 -3.721245 2.828697e-04
Asia DriveTrain Front DriveTrain Front 1 -12340.999993 1974.140868 -6.251327 4.295785e-09
Asia DriveTrain Rear DriveTrain Rear 0 0.000000 NaN NaN NaN
Asia MPG_City MPG_City 1 17.219012 250.187094 0.068825 9.452241e-01
Asia Weight Weight 1 10.934945 2.354866 4.643552 7.607689e-06
Asia Length Length 1 14.517900 114.818053 0.126443 8.995567e-01




§ ByGroup2.FitStatistics



Fit Statistics


























































RowId Description Value
Origin
Europe RMSE Root MSE 8.984900e+03
Europe RSQUARE R-Square 7.682232e-01
Europe ADJRSQ Adj R-Sq 7.513667e-01
Europe AIC AIC 2.296227e+03
Europe AICC AICC 2.298264e+03
Europe SBC SBC 2.200239e+03
Europe TRAIN_ASE ASE 7.462291e+07




§ ByGroup2.ParameterEstimates



Parameter Estimates
































































































































































Effect Type DriveTrain Parameter DF Estimate StdErr tValue Probt
Origin
Europe Intercept Intercept 1 -97268.426796 23984.147398 -4.055530 9.371452e-05
Europe Type SUV Type SUV 1 -8680.048584 4832.887423 -1.796038 7.523358e-02
Europe Type Sedan Type Sedan 1 3983.432570 2826.381315 1.409375 1.615450e-01
Europe Type Sports Type Sports 1 28690.137970 3766.149186 7.617897 9.639114e-12
Europe Type Wagon Type Wagon 0 0.000000 NaN NaN NaN
Europe DriveTrain All DriveTrain All 1 -5872.661455 2354.280432 -2.494461 1.410149e-02
Europe DriveTrain Front DriveTrain Front 1 -5977.536993 2282.743859 -2.618575 1.007440e-02
Europe DriveTrain Rear DriveTrain Rear 0 0.000000 NaN NaN NaN
Europe MPG_City MPG_City 1 -572.454386 438.201671 -1.306372 1.941510e-01
Europe Weight Weight 1 15.461755 3.107484 4.975652 2.418969e-06
Europe Length Length 1 514.342947 125.888841 4.085691 8.374752e-05




§ ByGroup3.FitStatistics



Fit Statistics


























































RowId Description Value
Origin
USA RMSE Root MSE 7.336632e+03
USA RSQUARE R-Square 6.317860e-01
USA ADJRSQ Adj R-Sq 6.075967e-01
USA AIC AIC 2.775430e+03
USA AICC AICC 2.777386e+03
USA SBC SBC 2.656335e+03
USA TRAIN_ASE ASE 5.016452e+07




§ ByGroup3.ParameterEstimates



Parameter Estimates












































































































































































Effect Type DriveTrain Parameter DF Estimate StdErr tValue Probt
Origin
USA Intercept Intercept 1 27189.194732 17038.936722 1.595710 0.112858
USA Type SUV Type SUV 1 -2642.099747 3692.428467 -0.715545 0.475490
USA Type Sedan Type Sedan 1 1143.294987 2930.398473 0.390150 0.697032
USA Type Sports Type Sports 1 16249.501038 4286.648839 3.790724 0.000224
USA Type Truck Type Truck 1 -8503.479255 3650.165897 -2.329614 0.021288
USA Type Wagon Type Wagon 0 0.000000 NaN NaN NaN
USA DriveTrain All DriveTrain All 1 -2882.556364 2448.067975 -1.177482 0.241045
USA DriveTrain Front DriveTrain Front 1 -660.205840 1827.536082 -0.361255 0.718466
USA DriveTrain Rear DriveTrain Rear 0 0.000000 NaN NaN NaN
USA MPG_City MPG_City 1 -1069.867684 340.679897 -3.140390 0.002067
USA Weight Weight 1 6.966966 1.889464 3.687271 0.000326
USA Length Length 1 -21.416004 71.698994 -0.298693 0.765627




elapsed 0.00926s · user 0.008s · sys 0.006s · mem 24.9MB

まとめ

出力先を指定しておくことで、重たい分析処理であってもすぐに結果を何度も確認できます。SQLで書くこともできますが、大抵行わないでしょう。Pythonでのプログラミングであれば出力先のテーブル名を指定するだけなので簡単です。ぜひお試しください。

SAS for Developers | SAS

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away