Data Science Engine Step at Query Object Level (R)

Data Science Engine Step at Query Object Level (R)

Intellicus enables the integration of machine learning and predictive modeling during the data transformation phase by adding a Data Science Engine step at the Query Object level. This step allows designers to perform data preparation, cleansing, training, prediction, and script-based computation before report generation.

Prerequisites

  • A valid connection to the data source

  • A configured Data Science Engine connection (e.g., R environment)

  • Access to a shared exchange location (for transmitting data and results)

  • Required libraries installed on the data science engine (for R: lintr, randomForest, dplyr, Rserve)

Why Use a Data Science Step in Query Object?

Adding a Data Science Engine step at the Query Object level is ideal when:

  • Predictions add new variables or fields to the data set (e.g., clustering results in market basket analysis)

  • You need to prepare or cleanse the data before modeling

  • Training and prediction logic must be embedded in the report pipeline

  • You want to perform transformations on predicted data (e.g., join with other tables, calculate fields)

Adding Data for Training and Prediction

You can define input data for both Training and Prediction, depending on your use case:

Scenario

Input Required

Scenario

Input Required

Separate data for training and prediction

Provide both training and prediction datasets

Same data for training and prediction

Add one data source

Pre-trained model used in the script

No training data required

Ensure that your data contains independent variables (inputs used to predict) and dependent variables (outcomes to be predicted). For example, predicting future sales may involve marketing spend, support cost, and headcount as independent variables, while sales is the dependent variable.

Steps to Add a Data Science Engine Step

  1. Navigate to Design > Query Object.

  2. In the transformation area, drag and drop the Data Science Engine step.

  3. Connect the Data Science Engine step to preceding transformation steps or data source steps.

You can place the Data Science Engine step before, in between, or after other steps such as Join, Union, or Formula to shape the prediction flow.

Example placement options:

  • Before transformation steps – use predictions to drive further joins or filters

  • After transformation steps – make predictions on enriched and aggregated data

Writing the Data Science Script

Select the Data Science Engine step to configure its properties.

Properties

Property

Values

Description

Property

Values

Description

Data Source Engine

R Job

Select the data science engine

Script

Custom R script

Add or edit R script using the built-in editor

Edit

Open editor

Launch the script editor to write or modify the code

The built-in script editor allows you to write, validate, and test your R scripts. Use it to modularize training and prediction logic, preview output, and handle errors early.

Guidelines for Script Authoring

Intellicus recommends the following best practices for writing R scripts at the Query Object level:

  • Modularize scripts using placeholders:

    • Training section: #<%TRAINING.SECTION%>

    • Prediction section: #<%PREDICTION.SECTION%>

  • The first line of each section should read the dataset:

    • read.csv('<%Train.Data%>') or read.csv('<%Predict.Data%>')

  • The last line in the Prediction section must write the result:

    • write.csv(...)

  • Refer to prior steps using: StepName.data

  • The model must be saved as myModel (default and mandatory name)

  • If only prediction is needed, the training script can be skipped

  • If training is skipped, a valid pre-trained model must be referenced

Intellicus uses this modular structure to dynamically manage Train Only, Train + Predict, and Predict Only modes during report execution using the Machine Learning Operations Toolbar.

Example Script

#<%TRAINING.SECTION%> trainingDataset = read.csv('<%Train.Data%>') library(randomForest) myModel = randomForest(x = trainingDataset[1:15], y = trainingDataset$TEMP, ntree = 500) #<%PREDICTION.SECTION%> predictionDataset = read.csv('<%Predict.Data%>') y_pred = predict(myModel, data.frame(predictionDataset[1:15])) predictionDataset$ExpectedTemp <- y_pred write.csv(predictionDataset, file='<%Predict.Data%>')

Next Steps

  • Click Verify to validate the script syntax

  • Save or Save As the Query Object for use in reports

  • Use predicted fields in visualizations or further transformation steps

Copyright Intellicus Technologies Pvt. Ltd. All rights reserved.