でトレーニングされた年次モデルのリサンプルの精度スコアの箱ひげ図をプロットしていcaret
ます。モデルには、参照する年によって名前が付けられます:2000、2001、2002、...、2010。モデルを箱ひげ図に表示し、年、つまりモデルの名前に基づいて昇順で表示します。
以下のコードに基づくリサンプルの要約
fit.year.res <- resamples(fit.year)
summary(fit.year.res)
このように見えます:
ただし、箱ひげ図のさまざまな年次モデルは並べ替えられません。
scales <- list(x=list(relation="free"), y=list(relation="free"))
bwplot(fit.year.res, scales=scales)
リサンプルのmodels要素をfit.year.res$models
文字からの因数分解に変換しようとしましたが、まったく違いはありませんでした。
bwplot
キャレットパッケージの方法を使った簡単な解決策を知りません。おそらく1つありますが、私の格子スキルが不足しています。ggplot2を使用して箱ひげ図を手動でプロットすることをお勧めします。このようにして、最終的なプロットをより適切に制御できるようになります。
データ付きの例を投稿しなかったので、次の例の1つを使用します ?caret:::bwplot.resamples
library(caret)
library(party)
library(RWeka)
load(url("http://topepo.github.io/caret/exampleModels.RData"))
resamps <- resamples(list(CART = rpartFit,
CondInfTree = ctreeFit,
MARS = earthFit))
bwplot(resamps,
metric = "RMSE")
生成:
ggplotを使用して手動でプロットを作成するには、いくつかのデータ操作が必要になります。
library(tidyverse)
resamps$values %>% #extract the values
select(1, ends_with("RMSE")) %>% #select the first column and all columns with a name ending with "RMSE"
gather(model, RMSE, -1) %>% #convert to long table
mutate(model = sub("~RMSE", "", model)) %>% #leave just the model names
ggplot()+ #call ggplot
geom_boxplot(aes(x = RMSE, y = model)) -> p1 #and plot the box plot
p1
y軸に特定の順序を設定するには:
p1 +
scale_y_discrete(limits = c("MARS", "CART", "CondInfTree"))
あなたが格子を好むなら
library(lattice)
resamps$values %>%
select(1, ends_with("RMSE")) %>%
gather(model, RMSE, -1) %>%
mutate(model = sub("~RMSE", "", model)) %>%
{bwplot(model ~ RMSE, data = .)}
順序を変更するには、モデルのレベルを変更します(このアプローチはggplot2でも機能します)。
resamps$values %>%
select(1, ends_with("RMSE")) %>%
gather(model, RMSE, -1) %>%
mutate(model = sub("~RMSE", "", model),
model = factor(model, levels = c("MARS", "CART", "CondInfTree"))) %>%
{bwplot(model ~ RMSE, data = .)}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加