use of org.knime.base.node.mine.regression.pmmlgreg.PMMLPCovCell in project knime-core by knime.
the class RegressionContent method createGeneralRegressionContent.
/**
* Creates a new PMML General Regression Content from this linear regression model.
*
* @return the PMMLGeneralRegressionContent
*/
public PMMLGeneralRegressionContent createGeneralRegressionContent() {
List<PMMLPredictor> factors = new ArrayList<PMMLPredictor>();
for (String factor : m_factorList) {
PMMLPredictor predictor = new PMMLPredictor(factor);
factors.add(predictor);
}
List<PMMLPredictor> covariates = new ArrayList<PMMLPredictor>();
for (String covariate : m_covariateList) {
PMMLPredictor predictor = new PMMLPredictor(covariate);
covariates.add(predictor);
}
// the ParameterList, the PPMatrix and the ParamMatrix
List<PMMLParameter> parameterList = new ArrayList<PMMLParameter>();
List<PMMLPPCell> ppMatrix = new ArrayList<PMMLPPCell>();
List<PMMLPCell> paramMatrix = new ArrayList<PMMLPCell>();
int p = 0;
if (m_includeConstant) {
// Define the intercept
parameterList.add(new PMMLParameter("p" + p, "Intercept"));
paramMatrix.add(new PMMLPCell("p" + p, m_beta.getEntry(0, 0), 1));
p++;
}
for (String colName : m_outSpec.getLearningFields()) {
if (m_factorList.contains(colName)) {
Iterator<DataCell> designIter = m_factorDomainValues.get(colName).iterator();
if (!designIter.hasNext()) {
continue;
}
// Omit first
designIter.next();
while (designIter.hasNext()) {
DataCell dvValue = designIter.next();
String pName = "p" + p;
parameterList.add(new PMMLParameter(pName, "[" + colName + "=" + dvValue + "]"));
ppMatrix.add(new PMMLPPCell(dvValue.toString(), colName, pName));
paramMatrix.add(new PMMLPCell(pName, m_beta.getEntry(0, p), 1));
p++;
}
} else {
String pName = "p" + p;
parameterList.add(new PMMLParameter("p" + p, colName));
ppMatrix.add(new PMMLPPCell("1", colName, pName));
paramMatrix.add(new PMMLPCell(pName, m_beta.getEntry(0, p), 1));
p++;
}
}
List<PMMLPCovCell> pCovMatrix = new ArrayList<PMMLPCovCell>();
PMMLGeneralRegressionContent content = new PMMLGeneralRegressionContent(ModelType.generalLinear, "KNIME Linear Regression", FunctionName.regression, "LinearRegression", parameterList.toArray(new PMMLParameter[0]), factors.toArray(new PMMLPredictor[0]), covariates.toArray(new PMMLPredictor[0]), ppMatrix.toArray(new PMMLPPCell[0]), pCovMatrix.toArray(new PMMLPCovCell[0]), paramMatrix.toArray(new PMMLPCell[0]));
if (!m_includeConstant) {
content.setOffsetValue(m_offsetValue);
}
return content;
}
use of org.knime.base.node.mine.regression.pmmlgreg.PMMLPCovCell in project knime-core by knime.
the class PolyRegContent method createGeneralRegressionContent.
/**
* Creates a new PMML General Regression Content from this polynomial regression model.
*
* @return the PMMLGeneralRegressionContent
*/
@Override
public PMMLGeneralRegressionContent createGeneralRegressionContent() {
List<PMMLPredictor> factors = new ArrayList<PMMLPredictor>();
for (String factor : m_factorList) {
PMMLPredictor predictor = new PMMLPredictor(factor);
factors.add(predictor);
}
List<PMMLPredictor> covariates = new ArrayList<PMMLPredictor>();
for (String covariate : m_covariateList) {
PMMLPredictor predictor = new PMMLPredictor(covariate);
covariates.add(predictor);
}
// the ParameterList, the PPMatrix and the ParamMatrix
List<PMMLParameter> parameterList = new ArrayList<PMMLParameter>();
List<PMMLPPCell> ppMatrix = new ArrayList<PMMLPPCell>();
List<PMMLPCell> paramMatrix = new ArrayList<PMMLPCell>();
int p = 0;
if (m_includeConstant) {
// Define the intercept
parameterList.add(new PMMLParameter("p" + p, "Intercept"));
paramMatrix.add(new PMMLPCell("p" + p, m_beta.getEntry(0, 0), 1));
p++;
}
for (String colName : m_outSpec.getLearningFields()) {
if (m_factorList.contains(colName)) {
Iterator<DataCell> designIter = m_factorDomainValues.get(colName).iterator();
// Omit first
designIter.next();
while (designIter.hasNext()) {
DataCell dvValue = designIter.next();
String pName = "p" + p;
parameterList.add(new PMMLParameter(pName, "[" + colName + "=" + dvValue + "]"));
ppMatrix.add(new PMMLPPCell(dvValue.toString(), colName, pName));
paramMatrix.add(new PMMLPCell(pName, m_beta.getEntry(0, p), 1));
p++;
}
} else {
String pName = "p" + p;
parameterList.add(new PMMLParameter(pName, colName));
ppMatrix.add(new PMMLPPCell("1", colName, pName));
paramMatrix.add(new PMMLPCell(pName, m_beta.getEntry(0, p), 1));
p++;
}
}
List<PMMLPCovCell> pCovMatrix = new ArrayList<PMMLPCovCell>();
PMMLGeneralRegressionContent content = new PMMLGeneralRegressionContent(ModelType.generalLinear, "KNIME Polynomial Regression", FunctionName.regression, "LinearRegression", parameterList.toArray(new PMMLParameter[0]), factors.toArray(new PMMLPredictor[0]), covariates.toArray(new PMMLPredictor[0]), ppMatrix.toArray(new PMMLPPCell[0]), pCovMatrix.toArray(new PMMLPCovCell[0]), paramMatrix.toArray(new PMMLPCell[0]));
if (!m_includeConstant) {
content.setOffsetValue(m_offsetValue);
}
return content;
}
use of org.knime.base.node.mine.regression.pmmlgreg.PMMLPCovCell in project knime-core by knime.
the class LogisticRegressionContent method createGeneralRegressionContent.
/**
* Creates a new PMML General Regression Content from this logistic
* regression model.
* @return the PMMLGeneralRegressionContent
*/
public PMMLGeneralRegressionContent createGeneralRegressionContent() {
List<PMMLPredictor> factors = new ArrayList<PMMLPredictor>();
for (String factor : m_factorList) {
PMMLPredictor predictor = new PMMLPredictor(factor);
factors.add(predictor);
}
List<PMMLPredictor> covariates = new ArrayList<PMMLPredictor>();
for (String covariate : m_covariateList) {
PMMLPredictor predictor = new PMMLPredictor(covariate);
covariates.add(predictor);
}
// the ParameterList, the PPMatrix and the ParamMatrix
List<PMMLParameter> parameterList = new ArrayList<PMMLParameter>();
List<PMMLPPCell> ppMatrix = new ArrayList<PMMLPPCell>();
List<PMMLPCell> paramMatrix = new ArrayList<PMMLPCell>();
int pCount = m_beta.getColumnDimension() / (m_targetCategories.size() - 1);
int p = 0;
parameterList.add(new PMMLParameter("p" + p, "Intercept"));
for (int k = 0; k < m_targetCategories.size() - 1; k++) {
paramMatrix.add(new PMMLPCell("p" + p, m_beta.getEntry(0, p + (k * pCount)), 1, m_targetCategories.get(k).toString()));
}
p++;
final List<String> learningFields = new ArrayList<>(m_outSpec.getLearningFields());
// learningFields.addAll(m_vectorLengths.keySet());
for (String colName : learningFields) {
if (m_factorList.contains(colName)) {
Iterator<DataCell> designIter = m_factorDomainValues.get(colName).iterator();
// Omit first
designIter.next();
while (designIter.hasNext()) {
DataCell dvValue = designIter.next();
String pName = "p" + p;
parameterList.add(new PMMLParameter(pName, "[" + colName + "=" + dvValue + "]"));
ppMatrix.add(new PMMLPPCell(dvValue.toString(), colName, pName));
for (int k = 0; k < m_targetCategories.size() - 1; k++) {
paramMatrix.add(new PMMLPCell(pName, m_beta.getEntry(0, p + (k * pCount)), 1, m_targetCategories.get(k).toString()));
}
p++;
}
} else {
if (m_vectorLengths.containsKey(colName)) {
final int length = m_vectorLengths.get(colName);
final int pFrozen = p;
for (int idx = 0; idx < length; ++idx) {
final String pName = "p" + pFrozen + "_" + idx;
final String predictorName = VectorHandling.valueAt(colName, idx);
parameterList.add(new PMMLParameter(pName, predictorName));
ppMatrix.add(new PMMLPPCell("1", predictorName, pName));
for (int k = 0; k < m_targetCategories.size() - 1; k++) {
paramMatrix.add(new PMMLPCell(pName, m_beta.getEntry(0, p + (k * pCount)), 1, m_targetCategories.get(k).toString()));
}
p++;
}
} else {
String pName = "p" + p;
parameterList.add(new PMMLParameter("p" + p, colName));
ppMatrix.add(new PMMLPPCell("1", colName, pName));
for (int k = 0; k < m_targetCategories.size() - 1; k++) {
paramMatrix.add(new PMMLPCell(pName, m_beta.getEntry(0, p + (k * pCount)), 1, m_targetCategories.get(k).toString()));
}
p++;
}
}
}
// TODO PCovMatrix
List<PMMLPCovCell> pCovMatrix = new ArrayList<PMMLPCovCell>();
PMMLGeneralRegressionContent content = new PMMLGeneralRegressionContent(ModelType.multinomialLogistic, "KNIME Logistic Regression", FunctionName.classification, "LogisticRegression", parameterList.toArray(new PMMLParameter[0]), factors.toArray(new PMMLPredictor[0]), covariates.toArray(new PMMLPredictor[0]), m_vectorLengths, ppMatrix.toArray(new PMMLPPCell[0]), pCovMatrix.toArray(new PMMLPCovCell[0]), paramMatrix.toArray(new PMMLPCell[0]));
content.setTargetReferenceCategory(m_targetCategories.get(m_targetCategories.size() - 1).toString());
return content;
}
use of org.knime.base.node.mine.regression.pmmlgreg.PMMLPCovCell in project knime-core by knime.
the class LogisticRegressionContent method createGeneralRegressionContent.
/**
* Creates a new PMML General Regression Content from this logistic
* regression model.
* @return the PMMLGeneralRegressionContent
*/
public PMMLGeneralRegressionContent createGeneralRegressionContent() {
List<PMMLPredictor> factors = new ArrayList<PMMLPredictor>();
for (String factor : m_factorList) {
PMMLPredictor predictor = new PMMLPredictor(factor);
factors.add(predictor);
}
List<PMMLPredictor> covariates = new ArrayList<PMMLPredictor>();
for (String covariate : m_covariateList) {
PMMLPredictor predictor = new PMMLPredictor(covariate);
covariates.add(predictor);
}
// the ParameterList, the PPMatrix and the ParamMatrix
List<PMMLParameter> parameterList = new ArrayList<PMMLParameter>();
List<PMMLPPCell> ppMatrix = new ArrayList<PMMLPPCell>();
List<PMMLPCell> paramMatrix = new ArrayList<PMMLPCell>();
int pCount = m_beta.getColumnDimension() / (m_targetCategories.size() - 1);
int p = 0;
parameterList.add(new PMMLParameter("p" + p, "Intercept"));
for (int k = 0; k < m_targetCategories.size() - 1; k++) {
paramMatrix.add(new PMMLPCell("p" + p, m_beta.get(0, p + (k * pCount)), 1, m_targetCategories.get(k).toString()));
}
p++;
for (String colName : m_outSpec.getLearningFields()) {
if (m_factorList.contains(colName)) {
Iterator<DataCell> designIter = m_factorDomainValues.get(colName).iterator();
// Omit first
designIter.next();
while (designIter.hasNext()) {
DataCell dvValue = designIter.next();
String pName = "p" + p;
parameterList.add(new PMMLParameter(pName, "[" + colName + "=" + dvValue + "]"));
ppMatrix.add(new PMMLPPCell(dvValue.toString(), colName, pName));
for (int k = 0; k < m_targetCategories.size() - 1; k++) {
paramMatrix.add(new PMMLPCell(pName, m_beta.get(0, p + (k * pCount)), 1, m_targetCategories.get(k).toString()));
}
p++;
}
} else {
String pName = "p" + p;
parameterList.add(new PMMLParameter("p" + p, colName));
ppMatrix.add(new PMMLPPCell("1", colName, pName));
for (int k = 0; k < m_targetCategories.size() - 1; k++) {
paramMatrix.add(new PMMLPCell(pName, m_beta.get(0, p + (k * pCount)), 1, m_targetCategories.get(k).toString()));
}
p++;
}
}
// TODO PCovMatrix
List<PMMLPCovCell> pCovMatrix = new ArrayList<PMMLPCovCell>();
PMMLGeneralRegressionContent content = new PMMLGeneralRegressionContent(ModelType.multinomialLogistic, "KNIME Logistic Regression", FunctionName.classification, "LogisticRegression", parameterList.toArray(new PMMLParameter[0]), factors.toArray(new PMMLPredictor[0]), covariates.toArray(new PMMLPredictor[0]), ppMatrix.toArray(new PMMLPPCell[0]), pCovMatrix.toArray(new PMMLPCovCell[0]), paramMatrix.toArray(new PMMLPCell[0]));
content.setTargetReferenceCategory(m_targetCategories.get(m_targetCategories.size() - 1).toString());
return content;
}
use of org.knime.base.node.mine.regression.pmmlgreg.PMMLPCovCell in project knime-core by knime.
the class LogisticRegressionContent method createGeneralRegressionContent.
/**
* Creates a new PMML General Regression Content from this logistic
* regression model.
* @return the PMMLGeneralRegressionContent
*/
public PMMLGeneralRegressionContent createGeneralRegressionContent() {
List<PMMLPredictor> factors = new ArrayList<PMMLPredictor>();
for (String factor : m_factorList) {
PMMLPredictor predictor = new PMMLPredictor(factor);
factors.add(predictor);
}
List<PMMLPredictor> covariates = new ArrayList<PMMLPredictor>();
for (String covariate : m_covariateList) {
PMMLPredictor predictor = new PMMLPredictor(covariate);
covariates.add(predictor);
}
// the ParameterList, the PPMatrix and the ParamMatrix
List<PMMLParameter> parameterList = new ArrayList<PMMLParameter>();
List<PMMLPPCell> ppMatrix = new ArrayList<PMMLPPCell>();
List<PMMLPCell> paramMatrix = new ArrayList<PMMLPCell>();
int pCount = m_beta.getColumnDimension() / (m_targetCategories.size() - 1);
int p = 0;
parameterList.add(new PMMLParameter("p" + p, "Intercept"));
for (int k = 0; k < m_targetCategories.size() - 1; k++) {
paramMatrix.add(new PMMLPCell("p" + p, m_beta.getEntry(0, p + (k * pCount)), 1, m_targetCategories.get(k).toString()));
}
p++;
final List<String> learningFields = new ArrayList<>(m_outSpec.getLearningFields());
// learningFields.addAll(m_vectorLengths.keySet());
for (String colName : learningFields) {
if (m_factorList.contains(colName)) {
Iterator<DataCell> designIter = m_factorDomainValues.get(colName).iterator();
// Omit first
designIter.next();
while (designIter.hasNext()) {
DataCell dvValue = designIter.next();
String pName = "p" + p;
parameterList.add(new PMMLParameter(pName, "[" + colName + "=" + dvValue + "]"));
ppMatrix.add(new PMMLPPCell(dvValue.toString(), colName, pName));
for (int k = 0; k < m_targetCategories.size() - 1; k++) {
paramMatrix.add(new PMMLPCell(pName, m_beta.getEntry(0, p + (k * pCount)), 1, m_targetCategories.get(k).toString()));
}
p++;
}
} else {
if (m_vectorLengths.containsKey(colName)) {
final int length = m_vectorLengths.get(colName);
final int pFrozen = p;
for (int idx = 0; idx < length; ++idx) {
final String pName = "p" + pFrozen + "_" + idx;
final String predictorName = VectorHandling.valueAt(colName, idx);
parameterList.add(new PMMLParameter(pName, predictorName));
ppMatrix.add(new PMMLPPCell("1", predictorName, pName));
for (int k = 0; k < m_targetCategories.size() - 1; k++) {
paramMatrix.add(new PMMLPCell(pName, m_beta.getEntry(0, p + (k * pCount)), 1, m_targetCategories.get(k).toString()));
}
p++;
}
} else {
String pName = "p" + p;
parameterList.add(new PMMLParameter("p" + p, colName));
ppMatrix.add(new PMMLPPCell("1", colName, pName));
for (int k = 0; k < m_targetCategories.size() - 1; k++) {
paramMatrix.add(new PMMLPCell(pName, m_beta.getEntry(0, p + (k * pCount)), 1, m_targetCategories.get(k).toString()));
}
p++;
}
}
}
// TODO PCovMatrix
List<PMMLPCovCell> pCovMatrix = new ArrayList<PMMLPCovCell>();
PMMLGeneralRegressionContent content = new PMMLGeneralRegressionContent(ModelType.multinomialLogistic, "KNIME Logistic Regression", FunctionName.classification, "LogisticRegression", parameterList.toArray(new PMMLParameter[0]), factors.toArray(new PMMLPredictor[0]), covariates.toArray(new PMMLPredictor[0]), m_vectorLengths, ppMatrix.toArray(new PMMLPPCell[0]), pCovMatrix.toArray(new PMMLPCovCell[0]), paramMatrix.toArray(new PMMLPCell[0]));
content.setTargetReferenceCategory(m_targetCategories.get(m_targetCategories.size() - 1).toString());
return content;
}
Aggregations