knitr::opts_chunk$set(echo = TRUE)
library(workflows)
library(here)
library(tibble)
library(magrittr)
library(dplyr)

Prediction from saved xgboost model

#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")


datadavidz/concrete documentation built on March 9, 2021, 11:37 p.m.