Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package prerna.reactor.frame.r.analytics;
import java.util.List;
import java.util.Random;
import java.util.Vector;
import org.apache.logging.log4j.Logger;
import prerna.algorithm.api.ITableDataFrame;
import prerna.ds.r.RSyntaxHelper;
import prerna.reactor.frame.r.AbstractRFrameReactor;
import prerna.reactor.task.constant.ConstantTaskCreationHelper;
import prerna.sablecc2.om.GenRowStruct;
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;
import prerna.util.usertracking.AnalyticsTrackerHelper;
import prerna.util.usertracking.UserTrackerFactory;
public class RunMatrixRegressionReactor extends AbstractRFrameReactor {
private static Random rand = new Random();
private static final String CLASS_NAME = RunMatrixRegressionReactor.class.getName();
private static final String Y_COLUMN = "yColumn";
private static final String X_COLUMNS = "xColumns";
public RunMatrixRegressionReactor() {
this.keysToGet = new String[]{Y_COLUMN, X_COLUMNS, ReactorKeysEnum.PANEL.getKey()};
}
@Override
public NounMetadata execute() {
init();
Logger logger = this.getLogger(CLASS_NAME);
ITableDataFrame dataFrame = getFrame();
String frameName = dataFrame.getName();
dataFrame.setLogger(logger);
// figure out inputs
List panelIds = getPanelId();
if(panelIds == null || panelIds.isEmpty()) {
panelIds = new Vector();
String panelId = rand.nextInt(5000) + "";
panelIds.add(panelId);
panelId = rand.nextInt(5000) + "";
panelIds.add(panelId);
} else if(panelIds.size() < 2) {
String panelId = rand.nextInt(5000) + "";
panelIds.add(panelId);
}
String predictionCol = getPrediction(logger);
List numericalCols = getColumns();
if (numericalCols.contains(predictionCol)) {
numericalCols.remove(predictionCol);
}
int numCols = numericalCols.size();
if (numCols == 0) {
String errorString = "Could not find input x variables";
logger.info(errorString);
throw new IllegalArgumentException(errorString);
}
// need the headers as a list of strings
String[] retHeaders = new String[numCols];
for(int i = 0; i < numCols; i++) {
String header = numericalCols.get(i);
if(header.contains("__")) {
String[] split = header.split("__");
retHeaders[i] = split[1];
} else {
retHeaders[i] = header;
}
}
// get the correlation data from the run r regression algorithm
logger.info("Start iterating through data to determine regression");
String resultsList = runRLinearRegression(frameName, predictionCol, retHeaders, logger);
logger.info("Done iterating through data to determine regression");
// track GA data
// UserTrackerFactory.getInstance().trackAnalyticsPixel(this.insight, "MatrixRegression");
// NEW TRACKING
UserTrackerFactory.getInstance().trackAnalyticsWidget(
this.insight,
dataFrame,
"MatrixRegression",
AnalyticsTrackerHelper.getHashInputs(this.store, this.keysToGet));
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
////////////////////////Coefficient Table Object/////////////////////////////
////////////////////////////////////////////////////////////////////////////
// THIS DOES NOT GET USED:
// the length of the object will be numCols + 1 (because of the intercept)
// there will always be 2 rows (column header and coefficient)
Object[][] retCoefficientOutput = new Object[numCols][2];
// need to fill in the object with the data values
// retrieve data using getBulkDataRow
String[] coefficientTableHeaders = new String[]{"ColumnName", "Coefficient"};
// query for retrieving the first item of the list - the coefficient table
String queryCoefficients = resultsList + "[[1]]";
List