Version: 9.16.0
Methods dedicated to linear regression

Functions

PMMLLIB_EXPORT void PMMLlib::PMMLlib::AddRegressionModel (std::string modelName, PMMLMiningFunction functionName, std::string targetFieldName)
 Specific to RegressionModel. More...
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::AddRegressionTable ()
 No property "intercept" will be set. More...
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::AddRegressionTable (double intercept)
 Specific to RegressionModel. More...
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::AddNumericPredictor (std::string neuronName, int exponent, double coefficient)
 Specific to RegressionModel. More...
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::AddPredictorTerm (double coefficient, std::vector< std::string > fieldRef)
 Specific to RegressionModel
More...
 
PMMLLIB_EXPORT bool PMMLlib::PMMLlib::HasIntercept ()
 Specific to RegressionModel
More...
 
PMMLLIB_EXPORT double PMMLlib::PMMLlib::GetRegressionTableIntercept ()
 Specific to RegressionModel
More...
 
PMMLLIB_EXPORT int PMMLlib::PMMLlib::GetNumericPredictorNb ()
 Specific to RegressionModel
More...
 
PMMLLIB_EXPORT int PMMLlib::PMMLlib::GetPredictorTermNb ()
 Specific to RegressionModel
More...
 
PMMLLIB_EXPORT std::string PMMLlib::PMMLlib::GetNumericPredictorName (int num_pred_index)
 Specific to RegressionModel
More...
 
PMMLLIB_EXPORT std::string PMMLlib::PMMLlib::GetPredictorTermName (int num_pred_index)
 Specific to RegressionModel
More...
 
PMMLLIB_EXPORT double PMMLlib::PMMLlib::GetNumericPredictorCoefficient (int num_pred_index)
 (The coefficient is the value of property "coefficient") More...
 
PMMLLIB_EXPORT double PMMLlib::PMMLlib::GetPredictorTermCoefficient (int pred_term_index)
 (The coefficient is the value of property "coefficient") More...
 
PMMLLIB_EXPORT int PMMLlib::PMMLlib::GetPredictorTermFieldRefNb (int pred_term_index)
 Specific to RegressionModel
More...
 
PMMLLIB_EXPORT std::string PMMLlib::PMMLlib::GetPredictorTermFieldRefName (int pred_term_index, int field_index)
 (The name is the value of property "field") More...
 
PMMLLIB_EXPORT std::string PMMLlib::PMMLlib::ReadRegressionStructure ()
 Specific to RegressionModel. More...
 
xmlNodePtr PMMLlib::PMMLlib::GetRegressionPtr (int reg_index)
 
xmlNodePtr PMMLlib::PMMLlib::GetRegressionPtr (std::string reg_name)
 
void PMMLlib::PMMLlib::CheckRegression ()
 Called in all methods specific to the RegressionModel model. More...
 

Detailed Description

Methods dedicated to linear regression

Function Documentation

◆ AddNumericPredictor()

void PMMLlib::PMMLlib::AddNumericPredictor ( std::string  neuronName,
int  exponent,
double  coefficient 
)

Specific to RegressionModel.

Add a numeric predictor to the Regression model.

Parameters
neuronNameValue of property "name"
exponentValue of property "exponent"
coefficientValue of property "coefficient"

Definition at line 2309 of file PMMLlib.cxx.

2312{
2313 CheckRegression();
2314 stringstream ss;
2315 xmlNodePtr numPrecNode = xmlNewChild(_currentNode, 0, (const xmlChar*)"NumericPredictor", 0);
2316 xmlNewProp(numPrecNode, (const xmlChar*)"name", (const xmlChar*)(neuronName.c_str()) );
2317 ss.str(""); ss << exponent;
2318 xmlNewProp(numPrecNode, (const xmlChar*)"exponent", (const xmlChar*)(ss.str().c_str()) );
2319 ss.str(""); ss << scientific << coefficient;
2320 xmlNewProp(numPrecNode, (const xmlChar*)"coefficient", (const xmlChar*)(ss.str().c_str()) );
2321}
xmlNodePtr _currentNode
Pointer to the current node
Definition: PMMLlib.hxx:80
void CheckRegression()
Called in all methods specific to the RegressionModel model.
Definition: PMMLlib.cxx:2225

◆ AddPredictorTerm()

void PMMLlib::PMMLlib::AddPredictorTerm ( double  coefficient,
std::vector< std::string >  fieldRef 
)

Specific to RegressionModel

Add a predictor term to the Regression model.

Parameters
coefficientValue of property "coefficient"
fieldRefList of values for property "field", one per FieldRef to add to the PredictorTerm

Definition at line 2329 of file PMMLlib.cxx.

2331{
2333 stringstream ss;
2334 xmlNodePtr predTermNode = xmlNewChild(_currentNode, 0, (const xmlChar*)"PredictorTerm", 0);
2335 ss.str(""); ss << scientific << coefficient;
2336 xmlNewProp(predTermNode, (const xmlChar*)"coefficient", (const xmlChar*)(ss.str().c_str()) );
2337 vector<string>::iterator it;
2338 for(it=fieldRef.begin() ; it!=fieldRef.end() ; it++)
2339 {
2340 xmlNodePtr fieldRefNode = xmlNewChild(predTermNode, 0, (const xmlChar*)"FieldRef", 0);
2341 ss.str(""); ss << (*it);
2342 xmlNewProp(fieldRefNode, (const xmlChar*)"field", (const xmlChar*)(ss.str().c_str()) );
2343 }
2344}

◆ AddRegressionModel()

void PMMLlib::PMMLlib::AddRegressionModel ( std::string  modelName,
PMMLMiningFunction  functionName,
std::string  targetFieldName 
)

Specific to RegressionModel.

Add a RegressionModel to the root node

Parameters
modelNameName of the model (Value of property "modelName")
functionNameValue of property "functionName"
targetFieldNameValue of Property "targetFieldName"

Definition at line 2248 of file PMMLlib.cxx.

2251{
2253 _currentModelName = modelName;
2254 // Check regression after setting model type!
2256
2257 string function;
2258 switch(functionName)
2259 {
2260 case kREGRESSION:
2261 function = "regression";
2262 break;
2263 }
2264 xmlNodePtr netNode = xmlNewChild(_rootNode, 0, (const xmlChar*)"RegressionModel", 0);
2265 xmlNewProp(netNode, (const xmlChar*)"functionName", (const xmlChar*)(function.c_str()) );
2266 xmlNewProp(netNode, (const xmlChar*)"modelName", (const xmlChar*)(_currentModelName.c_str()) );
2267 xmlNewProp(netNode, (const xmlChar*)"targetFieldName", (const xmlChar*)(targetFieldName.c_str()) );
2268 _currentModelNode = netNode ;
2269}
xmlNodePtr _currentModelNode
Pointer to the current model node
Definition: PMMLlib.hxx:84
std::string _currentModelName
Name of the current model
Definition: PMMLlib.hxx:82
PMMLType _currentModelType
Type of the current model.
Definition: PMMLlib.hxx:83
xmlNodePtr _rootNode
Root node of the document.
Definition: PMMLlib.hxx:79
@ kREGRESSION
Definition: PMMLlib.hxx:66

References PMMLlib::kLR, and PMMLlib::kREGRESSION.

◆ AddRegressionTable() [1/2]

void PMMLlib::PMMLlib::AddRegressionTable ( )

No property "intercept" will be set.

Add a RegressionTable to the Regression model.

Specific to RegressionModel

Definition at line 2276 of file PMMLlib.cxx.

2277{
2278 CheckRegression();
2279 xmlNodePtr tableNode = xmlNewChild(_currentModelNode, 0, (const xmlChar*)"RegressionModel", 0);
2280 _currentNode = tableNode;
2281}

◆ AddRegressionTable() [2/2]

void PMMLlib::PMMLlib::AddRegressionTable ( double  intercept)

Specific to RegressionModel.

Add a RegressionTable to the Regression model with a given value of property "intercept".

Parameters
interceptValue of property "intercept"

Definition at line 2288 of file PMMLlib.cxx.

2289{
2291
2292 stringstream ss;
2293 xmlNodePtr tableNode = xmlNewChild(_currentModelNode, 0, (const xmlChar*)"RegressionTable", 0);
2294 if(intercept!=0.0)
2295 {
2296 ss << scientific << intercept;
2297 xmlNewProp(tableNode, (const xmlChar*)"intercept", (const xmlChar*)(ss.str().c_str()) );
2298 }
2299 _currentNode = tableNode;
2300}

◆ CheckRegression()

void PMMLlib::PMMLlib::CheckRegression ( )
private

Called in all methods specific to the RegressionModel model.

Check if the current model type is kLR.

Throw an exception if the model type is not kLR.

Definition at line 2225 of file PMMLlib.cxx.

2226{
2227 if ( _currentModelType != kLR )
2228 throw string("Use this method with Regression models.");
2229}

References PMMLlib::kLR.

◆ GetNumericPredictorCoefficient()

double PMMLlib::PMMLlib::GetNumericPredictorCoefficient ( int  num_pred_index)

(The coefficient is the value of property "coefficient")

Get the coefficient of the numeric predictor given by its index.

Specific to RegressionModel

Parameters
num_pred_indexIndex of the numeric predictor
Returns
Coefficient of the numeric predictor

Definition at line 2503 of file PMMLlib.cxx.

2504{
2506
2507 double coef = 0.;
2508 xmlNodePtr numPredNodes = GetChildByName(_currentModelNode,"RegressionTable");
2509 if ( numPredNodes == NULL )
2510 return coef;
2511 numPredNodes = GetChildByName(numPredNodes,"NumericPredictor");
2512 if ( numPredNodes == NULL )
2513 return coef;
2514 // Positionnement sur la bonne sortie
2515 for(int i=0;i<num_pred_index;i++)
2516 {
2517 numPredNodes = numPredNodes->next;
2518 if ( numPredNodes == NULL ||
2519 string((const char*)(numPredNodes->name)) != "NumericPredictor" )
2520 return coef;
2521 }
2522 string strValue = _getProp(numPredNodes, string("coefficient"));
2523 coef = atof(strValue.c_str());
2524 return coef;
2525}
std::string _getProp(const xmlNodePtr node, std::string const &prop) const
Definition: PMMLlib.cxx:694
xmlNodePtr GetChildByName(xmlNodePtr node, std::string nodename)
Definition: PMMLlib.cxx:310

References yacsorb.CORBAEngineTest::i.

◆ GetNumericPredictorName()

std::string PMMLlib::PMMLlib::GetNumericPredictorName ( int  num_pred_index)

Specific to RegressionModel

Get the name of the numeric predictor given by its index.

Parameters
num_pred_indexIndex of the numeric predictor
Returns
Name of the numeric predictor

Definition at line 2438 of file PMMLlib.cxx.

2439{
2441 string strName("");
2442 xmlNodePtr numPredNodes = GetChildByName(_currentModelNode,"RegressionTable");
2443 if ( numPredNodes == NULL )
2444 return strName;
2445
2446 numPredNodes = GetChildByName(numPredNodes,"NumericPredictor");
2447 if ( numPredNodes == NULL )
2448 return strName;
2449 // Positionnement sur la bonne sortie PredictorTerm
2450 for(int i=0;i<num_pred_index;i++)
2451 {
2452 numPredNodes = numPredNodes->next;
2453 if ( numPredNodes == NULL ||
2454 string((const char*)(numPredNodes->name)) != "NumericPredictor" )
2455 return strName;
2456 }
2457 strName = _getProp(numPredNodes, string("name"));
2458 return strName;
2459}

References yacsorb.CORBAEngineTest::i.

◆ GetNumericPredictorNb()

int PMMLlib::PMMLlib::GetNumericPredictorNb ( )

Specific to RegressionModel

Get the number of numeric predictors.

Returns
Number of numeric predictors

Definition at line 2392 of file PMMLlib.cxx.

2393{
2395
2396 int nb=0;
2397 xmlNodePtr tableNode = GetChildByName(_currentModelNode,"RegressionTable");
2398 if ( tableNode == NULL )
2399 return nb;
2400 xmlNodePtr numPredNodes = tableNode->children;
2401 while (numPredNodes != NULL )
2402 {
2403 if ( string((const char*)(numPredNodes->name)) == "NumericPredictor" )
2404 nb++;
2405 numPredNodes = numPredNodes->next;
2406 }
2407 return nb;
2408}

◆ GetPredictorTermCoefficient()

double PMMLlib::PMMLlib::GetPredictorTermCoefficient ( int  pred_term_index)

(The coefficient is the value of property "coefficient")

Get the coefficient of the predictor term given by its index.

Specific to RegressionModel

Parameters
pred_term_indexIndex of the predictor term
Returns
Coefficient of the predictor term

Definition at line 2534 of file PMMLlib.cxx.

2535{
2537
2538 double coef = 0.;
2539 xmlNodePtr predTermNodes = GetChildByName(_currentModelNode,"RegressionTable");
2540 if ( predTermNodes == NULL )
2541 return coef;
2542 predTermNodes = GetChildByName(predTermNodes,"PredictorTerm");
2543 if ( predTermNodes == NULL )
2544 return coef;
2545 // Positionnement sur la bonne sortie
2546 for(int i=0;i<pred_term_index;i++)
2547 {
2548 predTermNodes = predTermNodes->next;
2549 if ( predTermNodes == NULL ||
2550 string((const char*)(predTermNodes->name)) != "PredictorTerm" )
2551 return coef;
2552 }
2553 string strValue = _getProp(predTermNodes, string("coefficient"));
2554 coef = atof(strValue.c_str());
2555 return coef;
2556}

References yacsorb.CORBAEngineTest::i.

◆ GetPredictorTermFieldRefName()

std::string PMMLlib::PMMLlib::GetPredictorTermFieldRefName ( int  pred_term_index,
int  field_index 
)

(The name is the value of property "field")

Get the name of the field_index-th FieldRef for the pred_term_index-th predictor term.

Specific to RegressionModel

Parameters
pred_term_indexIndex of the predictor term
field_indexIndex of the FieldRef
Returns
Name of the FieldRef

Definition at line 2600 of file PMMLlib.cxx.

2601{
2603
2604 string strName("");
2605 xmlNodePtr fieldRefNodes = GetChildByName(_currentModelNode,"RegressionTable");
2606 if ( fieldRefNodes == NULL )
2607 return strName;
2608 fieldRefNodes = GetChildByName(fieldRefNodes,"PredictorTerm");
2609 if ( fieldRefNodes == NULL )
2610 return strName;
2611 // Positionnement sur la bonne sortie PredictorTerm
2612 for(int i=0;i<pred_term_index;i++)
2613 {
2614 fieldRefNodes = fieldRefNodes->next;
2615 if ( fieldRefNodes == NULL ||
2616 string((const char*)(fieldRefNodes->name)) != "PredictorTerm" )
2617 return strName;
2618 }
2619 fieldRefNodes = fieldRefNodes->children;
2620 if ( fieldRefNodes == NULL )
2621 return strName;
2622 // Positionnement sur la bonne sortie FieldRef
2623 for(int i=0;i<field_index;i++)
2624 {
2625 fieldRefNodes = fieldRefNodes->next;
2626 if ( fieldRefNodes == NULL )
2627 return strName;
2628 }
2629 strName = _getProp(fieldRefNodes, string("field"));
2630 return strName;
2631}

References yacsorb.CORBAEngineTest::i.

◆ GetPredictorTermFieldRefNb()

int PMMLlib::PMMLlib::GetPredictorTermFieldRefNb ( int  index)

Specific to RegressionModel

Get the number of FieldRef for the predictor term given by its index.

Parameters
indsexIndex of the predictor term
Returns
Number of FieldRef

Definition at line 2564 of file PMMLlib.cxx.

2565{
2567
2568 int nb=0;
2569 xmlNodePtr fieldRefNodes = GetChildByName(_currentModelNode,"RegressionTable");
2570 if ( fieldRefNodes == NULL )
2571 return nb;
2572 fieldRefNodes = GetChildByName(fieldRefNodes,"PredictorTerm");
2573 if ( fieldRefNodes == NULL )
2574 return nb;
2575 // Positionnement sur la bonne sortie
2576 for(int i=0;i<index;i++)
2577 {
2578 fieldRefNodes = fieldRefNodes->next;
2579 if ( fieldRefNodes == NULL ||
2580 string((const char*)(fieldRefNodes->name)) != "PredictorTerm" )
2581 return nb;
2582 }
2583 fieldRefNodes = fieldRefNodes->children;
2584 while (fieldRefNodes != NULL)
2585 {
2586 nb++;
2587 fieldRefNodes = fieldRefNodes->next;
2588 }
2589 return nb;
2590}

References yacsorb.CORBAEngineTest::i.

◆ GetPredictorTermName()

std::string PMMLlib::PMMLlib::GetPredictorTermName ( int  pred_term_index)

Specific to RegressionModel

Get the name of the predictor term given by its index.

Parameters
pred_term_indexIndex of the predictor term
Returns
Name of the predictor term

Definition at line 2467 of file PMMLlib.cxx.

2468{
2470 string strName("");
2471 xmlNodePtr fieldRefNodes = GetChildByName(_currentModelNode,"RegressionTable");
2472 if ( fieldRefNodes == NULL )
2473 return strName;
2474
2475 fieldRefNodes = GetChildByName(fieldRefNodes,"PredictorTerm");
2476 if ( fieldRefNodes == NULL )
2477 return strName;
2478 // Positionnement sur la bonne sortie
2479 for(int i=0;i<pred_term_index;i++)
2480 {
2481 fieldRefNodes = fieldRefNodes->next;
2482 if ( fieldRefNodes == NULL ||
2483 string((const char*)(fieldRefNodes->name)) != "PredictorTerm" )
2484 return strName;
2485 }
2486
2487 fieldRefNodes = fieldRefNodes->children;
2488 while (fieldRefNodes != NULL)
2489 {
2490 strName += _getProp(fieldRefNodes, string("field"));
2491 fieldRefNodes = fieldRefNodes->next;
2492 }
2493 return strName;
2494}

References yacsorb.CORBAEngineTest::i.

◆ GetPredictorTermNb()

int PMMLlib::PMMLlib::GetPredictorTermNb ( )

Specific to RegressionModel

Get the number of predictor terms.

Returns
Number of predictor terms

Definition at line 2415 of file PMMLlib.cxx.

2416{
2418 int nb=0;
2419 xmlNodePtr tableNode = GetChildByName(_currentModelNode,"RegressionTable");
2420 if ( tableNode == NULL )
2421 return nb;
2422 xmlNodePtr numPredNodes = tableNode->children;
2423 while ( numPredNodes != NULL )
2424 {
2425 if ( string((const char*)(numPredNodes->name)) == "PredictorTerm" )
2426 nb++;
2427 numPredNodes = numPredNodes->next;
2428 }
2429 return nb;
2430}

◆ GetRegressionPtr() [1/2]

xmlNodePtr PMMLlib::PMMLlib::GetRegressionPtr ( int  reg_index)
private

◆ GetRegressionPtr() [2/2]

xmlNodePtr PMMLlib::PMMLlib::GetRegressionPtr ( std::string  name)
private

Get the pointeur to the regression model node.

Parameters
nameName of the regression model
Returns
Pointer to the XML node

Definition at line 2236 of file PMMLlib.cxx.

2237{
2238 return GetPtr(name, GetTypeString() );
2239}
std::string GetTypeString()
Definition: PMMLlib.cxx:473
xmlNodePtr GetPtr(int ann_index, std::string name)
Definition: PMMLlib.cxx:419

◆ GetRegressionTableIntercept()

double PMMLlib::PMMLlib::GetRegressionTableIntercept ( )

Specific to RegressionModel

Get the value of property "intercept" in the RegressionTable.

Returns
Value of property "intercept"

Definition at line 2376 of file PMMLlib.cxx.

2377{
2379 double reg = 0.;
2380 xmlNodePtr tableNode = GetChildByName(_currentModelNode,"RegressionTable");
2381 if ( tableNode == NULL )
2382 return reg;
2383 string strValue = _getProp(tableNode, string("intercept") );
2384 return atof(strValue.c_str());
2385}

◆ HasIntercept()

bool PMMLlib::PMMLlib::HasIntercept ( )

Specific to RegressionModel

Check if the RegressionTable has a property called "intercept".

Returns
true if it has, false otherwise

Definition at line 2351 of file PMMLlib.cxx.

2352{
2354 bool b = false;
2355 xmlNodePtr tableNode = GetChildByName(_currentModelNode,"RegressionTable");
2356 if ( tableNode == NULL )
2357 return b;
2358 xmlChar *xp = _stringToXmlChar("intercept");
2359 xmlChar * attr ;
2360 attr = xmlGetProp(tableNode, xp);
2361 if ( attr )
2362 {
2363 xmlFree(attr);
2364 xmlFree(xp);
2365 return true;
2366 }
2367 xmlFree(xp);
2368 return false;
2369}
xmlChar * _stringToXmlChar(const std::string &s) const
Definition: PMMLlib.cxx:683

References gui.CONNECTOR::b.

◆ ReadRegressionStructure()

std::string PMMLlib::PMMLlib::ReadRegressionStructure ( )

Specific to RegressionModel.

Read the structure of the regression model

Returns
Structure read

Definition at line 2873 of file PMMLlib.cxx.

2874{
2875 CheckRegression();
2876
2877 string structure("");
2878 string structureActive("");
2879 string structurePredicted("@");
2880 int nPred = 0;
2881 xmlNodePtr mNode = GetChildByName(_currentModelNode,"MiningSchema");
2882 if ( mNode != NULL )
2883 {
2884 xmlNodePtr dNode = GetChildByName(mNode,"MiningField");
2885 while (dNode != NULL)
2886 {
2887 string name = _getProp(dNode, string("name"));
2888 string usage = _getProp(dNode, string("usageType"));
2889 if ( usage == "active" )
2890 {
2891 structureActive += name;
2892 structureActive += ":";
2893 }
2894 else if ( usage == "predicted" )
2895 {
2896 structurePredicted += name;
2897 structurePredicted += ":";
2898 nPred++;
2899 }
2900 dNode = dNode->next;
2901 }
2902 // Delete the last ":"
2903 if ( structureActive.length() > 0 )
2904 structureActive.erase(structureActive.size()-1);
2905 structurePredicted.erase(structurePredicted.size()-1);
2906 }
2907 std::ostringstream oss;
2908 oss << nPred;
2909 structure = structureActive + "," + oss.str() + "," + structurePredicted;
2910 return structure;
2911}