予測モデルにより過去の動作に基づいて将来の動作を予測できます。モデルを構築した後に、そのモデルを使用して新しいデータのスコアリング、すなわち予測を行います。
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メソッド | オブジェクトのクラス | オブジェクトの説明 |
---|---|---|
|
|
一般化線形モデル |
|
|
k-Meansクラスタリング・モデル |
|
|
線形回帰モデル |
|
|
1000行以下の |
|
|
多項対数線形モデル |
|
|
ニューラル・ネットワーク・モデル |
|
|
Oracle R Enterpriseのモデル |
|
|
マトリクス上の主要コンポーネント分析 |
|
|
数値マトリクス上の主要コンポーネント分析 |
|
|
再帰分割および回帰ツリー・モデル |
ore.predict
メソッドの引数では、メソッドでhelp("ore.predict-glm")
などのhelp
関数を起動します。
例5-1では、iris
data.frame
でlm
関数を使用して線形回帰モデル(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