ヘッダーをスキップ
Oracle® R Enterpriseユーザーズ・ガイド
リリース1.4
E52975-01
  目次へ移動
目次
索引へ移動
索引

前
 
次
 

5 Rモデルでの予測

予測モデルにより過去の動作に基づいて将来の動作を予測できます。モデルを構築した後に、そのモデルを使用して新しいデータのスコアリング、すなわち予測を行います。

Rにより様々なモデルを構築できます。Rモデルを使用して新しい結果を予測するためにデータのスコアリングをするときは、スコアリングするデータはR data.frameにある必要があります。ore.predict関数を使用すると、Rモデルを使用してore.frameオブジェクトにあるデータベース常駐データをスコアリングできます。

ore.predict関数を使用すると、ore.frameオブジェクトを使用した予測のみが可能であるため、モデルの再構築はできません。スケーラビリティおよびパフォーマンスを向上するには、第4章「Oracle R Enterpriseでのモデルの構築」に記載されているアルゴリズムおよび関数を使用してデータベース表にモデルを構築します。これらには、Oracle R Enterpriseに固有のアルゴリズムおよびRで公開されているOracle Data Miningのアルゴリズムの両方が含まれます。

ore.predict関数は汎用関数です。次のように使用します。

ore.predict(object, newdata, ...)

object引数の値は、Rモデルまたは表5-1にリストされているオブジェクトのいずれかです。newdata引数の値は、スコアリングするデータが含まれているore.frameオブジェクトです。OREpredictパッケージには、固有のRモデル・クラスで使用するためのメソッドがあります。...引数は、各種のメソッドで受け入れられる様々な追加の引数を表します。

表5-1に、汎用のore.predict関数で使用されるメソッド、メソッドがobject引数として受け入れるオブジェクトのクラスおよびモデルまたはオブジェクトのタイプの説明をリストします。

表5-1 汎用のore.predict関数のメソッド

OREpredictメソッド オブジェクトのクラス オブジェクトの説明

ore.predict-glm

glm

一般化線形モデル

ore.predict-kmeans

kmeans

k-Meansクラスタリング・モデル

ore.predict-lm

lm

線形回帰モデル

ore.predict-matrix

matrix

1000行以下のmatrix

ore.predict-multinom

multinom

多項対数線形モデル

ore.predict-nnet

nnet

ニューラル・ネットワーク・モデル

ore.predict-ore.model

ore.model

Oracle R Enterpriseのモデル

ore.predict-prcomp

prcomp

マトリクス上の主要コンポーネント分析

ore.predict-princomp

princomp

数値マトリクス上の主要コンポーネント分析

ore.predict-rpart

rpart

再帰分割および回帰ツリー・モデル


ore.predictメソッドの引数では、メソッドでhelp("ore.predict-glm")などのhelp関数を起動します。

例5-1では、iris data.framelm関数を使用して線形回帰モデル(irisModel)を構築します。ここでは、データセットをore.frameオブジェクトであるiris_ofとしてデータベースにプッシュします。次に、ore.predictをそこで起動してモデルをスコアリングします。

例5-1 LMモデルでのore.predict関数の使用方法

irisModel <- lm(Sepal.Length ~ ., data = iris)
iris_of <- ore.push(iris)
iris_of_pred <- ore.predict(irisModel, iris_of, se.fit = TRUE, 
                            interval = "prediction")
iris_of <- cbind(iris_of, iris_of_pred)
head(iris_of)

例5-1のリスト

R> irisModel <- lm(Sepal.Length ~ ., data = iris)
R> iris_of <- ore.push(iris)
R> iris_of_pred <- ore.predict(irisModel, iris_of, se.fit = TRUE, 
+                              interval = "prediction")
R> iris_of <- cbind(iris_of, iris_of_pred)
R> head(iris_of)
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species     PRED    SE.PRED
1          5.1         3.5          1.4         0.2  setosa 5.004788 0.04479188
2          4.9         3.0          1.4         0.2  setosa 4.756844 0.05514933
3          4.7         3.2          1.3         0.2  setosa 4.773097 0.04690495
4          4.6         3.1          1.5         0.2  setosa 4.889357 0.05135928
5          5.0         3.6          1.4         0.2  setosa 5.054377 0.04736842
6          5.4         3.9          1.7         0.4  setosa 5.388886 0.05592364
  LOWER.PRED UPPER.PRED
1   4.391895   5.617681
2   4.140660   5.373027
3   4.159587   5.386607
4   4.274454   5.504259
5   4.440727   5.668026
6   4.772430   6.005342

R> head(iris_of)
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species     PRED    SE.PRED LOWER.PRED UPPER.PRED
1          5.1         3.5          1.4         0.2  setosa 5.004788 0.04479188   4.391895   5.617681
2          4.9         3.0          1.4         0.2  setosa 4.756844 0.05514933   4.140660   5.373027
3          4.7         3.2          1.3         0.2  setosa 4.773097 0.04690495   4.159587   5.386607
4          4.6         3.1          1.5         0.2  setosa 4.889357 0.05135928   4.274454   5.504259
5          5.0         3.6          1.4         0.2  setosa 5.054377 0.04736842   4.440727   5.668026
6          5.4         3.9          1.7         0.4  setosa 5.388886 0.05592364   4.772430   6.005342

例5-2では、infertデータセットを使用して一般化線形モデルを生成した後に、そのモデルでore.predict関数を起動します。

例5-2 GLMモデルでのore.predict関数の使用方法

infertModel <-
  glm(case ~ age + parity + education + spontaneous + induced,
  data = infert, family = binomial())
INFERT <- ore.push(infert)
INFERTpred <- ore.predict(infertModel, INFERT, type = "response",
                          se.fit = TRUE)
INFERT <- cbind(INFERT, INFERTpred)
head(INFERT)

例5-2のリスト

R> infertModel <-
+   glm(case ~ age + parity + education + spontaneous + induced,
+   data = infert, family = binomial())
R> INFERT <- ore.push(infert)
R> INFERTpred <- ore.predict(infertModel, INFERT, type = "response",
+                           se.fit = TRUE)
R> INFERT <- cbind(INFERT, INFERTpred)
R> head(INFERT)
  education age parity induced case spontaneous stratum pooled.stratum
1    0-5yrs  26      6       1    1           2       1              3
2    0-5yrs  42      1       1    1           0       2              1
3    0-5yrs  39      6       2    1           0       3              4
4    0-5yrs  34      4       2    1           0       4              2
5   6-11yrs  35      3       1    1           1       5             32
6   6-11yrs  36      4       2    1           1       6             36
       PRED    SE.PRED
1 0.5721916 0.20630954
2 0.7258539 0.17196245
3 0.1194459 0.08617462
4 0.3684102 0.17295285
5 0.5104285 0.06944005
6 0.6322269 0.10117919