publications/LatinR2019/Presentation/Scripts/03_fit_model_emos.R

et.seed(8818)

## load data

`๐Ÿทs` <- readRDS("labels.rds")
`โ„นโ“‚๏ธgs_๐Ÿ…ฐ๏ธrr` <- readRDS("imgs_arr.rds")

`t๐Ÿ‡ช๐Ÿ‡ธt_๐Ÿ†”โœ–s` <- sample(seq_len(nrow(`๐Ÿทs`)), round(nrow(`โ„นโ“‚๏ธgs_๐Ÿ…ฐ๏ธrr`) * .2))
`โœ–_๐Ÿš‚` <- `โ„นโ“‚๏ธgs_๐Ÿ…ฐ๏ธrr`[-`t๐Ÿ‡ช๐Ÿ‡ธt_๐Ÿ†”โœ–s`, , , ]
`y_๐Ÿš‚` <- `๐Ÿทs`[-`t๐Ÿ‡ช๐Ÿ‡ธt_๐Ÿ†”โœ–s`, "Category"]
`โœ–_t๐Ÿ‡ช๐Ÿ‡ธt` <- `โ„นโ“‚๏ธgs_๐Ÿ…ฐ๏ธrr`[`t๐Ÿ‡ช๐Ÿ‡ธt_๐Ÿ†”โœ–s`, , , ]
`y_t๐Ÿ‡ช๐Ÿ‡ธt` <- `๐Ÿทs`[`t๐Ÿ‡ช๐Ÿ‡ธt_๐Ÿ†”โœ–s`, "Category"]
dim(`โœ–_๐Ÿš‚`)
head(`y_๐Ÿš‚`)

## fit autokeras model

# Create an image classifier, and train for one hour
`๐Ÿ†‘f` <- model_image_classifier(verbose = TRUE, augment = FALSE) %>%
  fit(`โœ–_๐Ÿš‚`, `y_๐Ÿš‚`, time_limit = 1 * 60 * 60)

# Evaluate
`๐Ÿ†‘f` %>% evaluate(`โœ–_t๐Ÿ‡ช๐Ÿ‡ธt`, `y_t๐Ÿ‡ช๐Ÿ‡ธt`)

# Re-train the best trained model with all the available data
`๐Ÿ†‘f` %>%
  final_fit(
    `โœ–_๐Ÿš‚`, `y_๐Ÿš‚`, `โœ–_t๐Ÿ‡ช๐Ÿ‡ธt`, `y_t๐Ÿ‡ช๐Ÿ‡ธt`,
    retrain = TRUE, time_limit = 20 * 60
  )
jcrodriguez1989/autokeras documentation built on Jan. 23, 2021, 10:51 p.m.