knitr::opts_chunk$set(echo = TRUE)
library(workflows) library(here) library(tibble) library(magrittr) library(dplyr)
#saved xgboost model in "model" load(here::here("data/model.rda")) load(here::here("data/spec_vol.rda"))
Starting formulation
start_form <- tibble::tribble(~ingredient, ~amount, "cement", 275, "blast_furnace_slag", 20, "fly_ash", 0, "water", 185, "superplasticizer", 5, "coarse_aggregate", 975, "fine_aggregate", 775 )
Starting formulation
formulation <- tibble::tibble("cement" = 275, "blast_furnace_slag" = 20, "fly_ash" = 0, "water" = 185, "superplasticizer" = 5, "coarse_aggregate" = 975, "fine_aggregate"= 775, "age" = 28 )
Predict compressive strength using saved model (xgboost)
prediction <- predict( model, formulation ) paste("Predicted compressive strength:", round(prediction$.pred, 1), "MPa")
Calculate the volume of the ingredients
volume <- start_form %>% left_join(spec_vol, by = "ingredient") %>% mutate(ingred_vol = amount * specific_volume) %>% pull(ingred_vol) %>% sum paste("Volume of ingredients:", round(volume, 1), "m^3")
Approach just multiplying the two vectors
volume <- t(spec_vol$specific_volume) %*% as.numeric(as.vector(formulation[1,1:7])) #volume <- t(spec_vol$specific_volume) %*% as.vector(formulation[1,1:7]) #doesn't work paste("Volume of ingredients:", round(volume, 1), "m^3")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.