0
0

More than 3 years have passed since last update.

CASTableでデータの概要を確認する

Posted at

SAS ViyaはAIプラットフォームです。PythonやJava、Rなどの言語を通して利用できます。そのSAS Viyaの中で使われているのがCASTableというテーブルオブジェクトです(CASはCloud Analytic Servicesの略です)。今回はCASTableでデータの状態を見る際に、その抽出条件を変更する方法を紹介します。

データベースからテーブルを取得する

まずはSAS Viyaに接続します。

import swat
conn = swat.CAS('server-name.mycompany.com', 5570, 'username', 'password')

次にCASTableを取得します。今回はIRISデータのCSVを利用します。

tbl = conn.loadtable('data/iris.csv', caslib='casuser').casTable

情報を確認する

どういったデータがあるのかを確認する際には describe メソッドを使います。

tbl.describe()

以下のように結果が返ってきます。行数、標準偏差、最小値、最大値、さらに25%/50%/75%に値するデータが確認できます。

sepal_length sepal_width petal_length petal_width
count 150.000000 150.000000 150.000000
mean 5.843333 3.054000 3.758667
std 0.828066 0.433594 1.764420
min 4.300000 2.000000 1.000000
25% 5.100000 2.800000 1.600000
50% 5.800000 3.000000 4.350000
75% 6.400000 3.300000 5.100000
max 7.900000 4.400000 6.900000

パーセントを変更する

percentiles を変更すると、取得されるデータが変わります。以下は30%と80%のデータに変更する例です。

tbl.describe(percentiles=[0.3, 0.8])
sepal_length sepal_width petal_length petal_width
count 150.000000 150.000000 150.000000
mean 5.843333 3.054000 3.758667
std 0.828066 0.433594 1.764420
min 4.300000 2.000000 1.000000
30% 5.250000 2.800000 1.700000
50% 5.800000 3.000000 4.350000
80% 6.550000 3.400000 5.350000
max 7.900000 4.400000 6.900000

全体を見る

全データを確認する際には include='all' を指定します。

tbl.describe(include='all')
sepal_length sepal_width petal_length petal_width species
count 150 150 150 150
unique 35 23 43 22
top 5 3 1.5 0.2
freq 10 26 14 28
mean 5.84333 3.054 3.75867 1.19867
std 0.828066 0.433594 1.76442 0.763161
min 4.3 2 1 0.1
25% 5.1 2.8 1.6 0.3
50% 5.8 3 4.35 1.3
75% 6.4 3.3 5.1 1.8
max 7.9 4.4 6.9 2.5

数値を浮動小数点数にもできます。

tbl.describe(stats='all')
sepal_length sepal_width petal_length petal_width
count 1.500000e+02 1.500000e+02 1.500000e+02
unique 3.500000e+01 2.300000e+01 4.300000e+01
mean 5.843333e+00 3.054000e+00 3.758667e+00
std 8.280661e-01 4.335943e-01 1.764420e+00
min 4.300000e+00 2.000000e+00 1.000000e+00
25% 5.100000e+00 2.800000e+00 1.600000e+00
50% 5.800000e+00 3.000000e+00 4.350000e+00
75% 6.400000e+00 3.300000e+00 5.100000e+00
max 7.900000e+00 4.400000e+00 6.900000e+00
nmiss 0.000000e+00 0.000000e+00 0.000000e+00
sum 8.765000e+02 4.581000e+02 5.638000e+02
stderr 6.761132e-02 3.540283e-02 1.440643e-01
var 6.856935e-01 1.880040e-01 3.113179e+00
uss 5.223850e+03 1.427050e+03 2.583000e+03
cv 1.417113e+01 1.419759e+01 4.694272e+01
tvalue 8.642537e+01 8.626430e+01 2.609020e+01
probt 3.331256e-129 4.374977e-129 1.994305e-57

まとめ

describeメソッドを使うことでCASTable内のデータについて概要を把握できるようになります。データ分析を行う際のベースとしてご利用ください。

SAS for Developers | SAS

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0