The TRANSFORMER
function requires Python with TensorFlow
and Keras installed. Without these, the function returns mock results
for demonstration. We recommend users install the latest version of
Python on their system. Then, create a Conda environment and install
TensorFlow, Keras, and Pandas. If unfamiliar with these steps, follow
the guide below.
After installing Python, run the R script below. It creates a conda environment and installs TensorFlow. If already installed, it skips the step.
Example system path for python.exe
:
After TensorFlow installation, install Keras in the virtual environment:
install_r_keras(tensorflow_python_path = "virtual_environment_path_of_python.exe", env_name = "r-tensorflow")
Example path:
Once setup is complete, run the R package using example or custom data.
result <- TRANSFORMER(
df = df,
study_variable = "Price",
tensorflow_python_path = "C:/Users/kabil/Documents/.virtualenvs/r-tensorflow/Scripts/python.exe",
env_name = "r-tensorflow",
sequence_size = 10,
head_size = 128,
num_heads = 8,
ff_dim = 256,
num_transformer_blocks = 4,
mlp_units = c(128),
mlp_dropout = 0.3,
dropout = 0.2,
epochs = 100,
batch_size = 32,
patience = 15
)
Root Mean Squared Error (RMSE) – Measures the average prediction error.
Mean Absolute Error (MAE) – Shows the average absolute difference between actual and predicted values.
Mean Absolute Percentage Error (MAPE) – Represents prediction accuracy as a percentage.
Symmetric Mean Absolute Percentage Error (sMAPE) – A variant of MAPE considering both over- and under-predictions.
Relative Root Mean Squared Error (RRMSE) – RMSE scaled by the mean of the actual values.
Quantile Loss – Used for probabilistic forecasting.