
prerna.reactor.frame.r.analytics.RunNumericalModelReactor Maven / Gradle / Ivy
The newest version!
package prerna.reactor.frame.r.analytics;
import java.util.List;
import org.apache.logging.log4j.Logger;
import prerna.ds.OwlTemporalEngineMeta;
import prerna.ds.r.RDataTable;
import prerna.reactor.frame.r.AbstractRFrameReactor;
import prerna.reactor.task.constant.ConstantTaskCreationHelper;
import prerna.sablecc2.om.PixelDataType;
import prerna.sablecc2.om.PixelOperationType;
import prerna.sablecc2.om.ReactorKeysEnum;
import prerna.sablecc2.om.nounmeta.NounMetadata;
import prerna.sablecc2.om.task.ITask;
import prerna.util.Utility;
public class RunNumericalModelReactor extends AbstractRFrameReactor {
private static final String CLASS_NAME = RunNumericalModelReactor.class.getName();
/**
* RunNumericalSimilarity(column = ["age"], panel=["0"]);
*/
public RunNumericalModelReactor() {
this.keysToGet = new String[] { ReactorKeysEnum.COLUMN.getKey(), ReactorKeysEnum.PANEL.getKey() };
}
@Override
public NounMetadata execute() {
init();
organizeKeys();
String[] packages = new String[] { "data.table", "nueralnet" };
this.rJavaTranslator.checkPackages(packages);
Logger logger = this.getLogger(CLASS_NAME);
RDataTable dataFrame = (RDataTable) getFrame();
String frameName = dataFrame.getName();
dataFrame.setLogger(logger);
OwlTemporalEngineMeta meta = this.getFrame().getMetaData();
// get inputs
String instanceColumn = this.keyValue.get(this.keysToGet[0]);
String panelId = this.keyValue.get(this.keysToGet[1]);
// ensure that datatype of column is numeric
if (!dataFrame.isNumeric(instanceColumn)) {
// now return this object
NounMetadata noun = new NounMetadata("Numerical Similarity can only be run on a numerical column",
PixelDataType.CONST_STRING, PixelOperationType.ERROR);
return noun;
}
// determine the name for the new similarity column to avoid adding
// columns with same name
String newColName = instanceColumn + "_Predicted";
// clean the column name to ensure that it is valid
newColName = getCleanNewColName(dataFrame, newColName);
// get the data from the numerical similarity algorithm
logger.info("Start iterating through data to determine model");
boolean success = runAlgorithm(frameName, instanceColumn, newColName);
logger.info("Done iterating through data to determine model");
if (success) {
// create the new frame meta
meta.addProperty(frameName, frameName + "__" + newColName);
meta.setAliasToProperty(frameName + "__" + newColName, newColName);
meta.setDataTypeToProperty(frameName + "__" + newColName, "DOUBLE");
// now lets visualize the difference between actual and predicted
// lets do a scatter
// we need to add a unique row id
String[] dataTableHeaders = new String[] { "ROW_ID", instanceColumn, newColName };
// query for retrieving the second item of the list - the Actuals vs
// Predicted
String queryDataPoints = frameName;
this.rJavaTranslator.executeEmptyR(queryDataPoints + "$ROW_ID <- seq.int(nrow(" + queryDataPoints + "))");
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy