Most of the work associated with building a predictive model is associated with either performance tuning or data prepping.
I’m almost half way through prepping some data. It’s not necessary to script this but a script allows me to adjust the data preparation in the future and more importantly to document the sequence of steps that I have taken.
Hopefully the comments (in green) make the code readable without worrying about the detail of the JSL syntyax:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 |
seed = 2; // allow a fixed seed for reproducible results //**********************************************************************************************// // // // Source Data // // // //**********************************************************************************************// // raw training data dtTrain = Open("train.jmp"); // add validation column Random Reset(seed); proportionTraining = 0.75; proportionValidation = 0.25; dtTrain << New Column( "Validation", Numeric, "Nominal", Format( "Best", 12 ), Formula( Random Category( proportionTraining, 0, proportionValidation, 1, 2 ) ), Value Labels( {0 = "Training", 1 = "Validation", 2 = "Test", 3 = "Blind Test"} ), Use Value Labels( 1 ) ); // raw test data dtTest = Open("test.jmp"); // add validation column dtTest << New Column( "Validation", Numeric, "Nominal", Format( "Best", 12 ), Set Each Value(3), Value Labels( {0 = "Training", 1 = "Validation", 2 = "Test", 3 = "Blind Test"} ), Use Value Labels( 1 ) ); // Data may need to be transformed in various ways or have imputed data appleid to it. // These methods need to be applied equally across all data so combine training and test data dtCombined = dtTrain << Concatenate( dtTest, Output Table( "combined" ) ); // can close test data table but still need training data for functions such // as Collapse Class Variable //Close(dtTrain,NoSave); Close(dtTest,NoSave); //**********************************************************************************************// // // // Target Variable // // // //**********************************************************************************************// targetCol = dtTrain << New Column("Log Sales", Numeric, Continuous, Formula(Log10(SalePrice))); targetCol = dtCombined << New Column("Log Sales", Numeric, Continuous, Formula(Log10(SalePrice))); targetColName = targetCol << Get Name; //**********************************************************************************************// // // // Column Variable Prep // // // //**********************************************************************************************// //----------------------------------------------------------------------------------------------// // ID column // //----------------------------------------------------------------------------------------------// // not required dtCombined << Delete Column("Id"); //----------------------------------------------------------------------------------------------// // MSSubClass: Identifies the type of dwelling involved in the sale. // //----------------------------------------------------------------------------------------------// varName = "MSSubClass"; // Continuous, but should be Nominal Column(dtCombined,varName) << Set Modeling Type("Nominal"); // there are 20 levels. One level occurs 37%, all others <5% // so create an aggregated column col1 = Collapse Class Variable(dtTrain,targetColName,varName,0.05,1,0); // apply this column to the combined data table fml = col1 << Get Formula; col2 = dtCombined << New Column(varName || " GRP", character, Formula( NameExpr(fml) )); // move new column adjacent to source dtCombined << Go To( col2 ); dtCombined << Move Selected Columns( After( Column(varName)) ); dtCombined << Clear Column Selection; // nolonger need the original column Column(dtCombined,varName) << Set Excluded << Set Hidden; //----------------------------------------------------------------------------------------------// // MSZoning: Identifies the classification: residential, commercial etc // //----------------------------------------------------------------------------------------------// varName = "MSZoning"; // there are 5 levels. RL=Low Density Residential accounts for 78% of the data // and RM = medium density accounts for 14%. All levels have distinct average values of sale price // so don't try and aggregate //----------------------------------------------------------------------------------------------// // LotFrontage: Linear feet measurement of property facing street // //----------------------------------------------------------------------------------------------// varName = "LotFrontage"; // 2 outliers (both contained within the training data) - remove these dtCombined << Select Where(:LotFrontage > 300); dtCombined << Delete Rows; // There are over 400 missing data values. JMP provides 2 methods of imputation. // Alternatively a median value could be used. For this particular variable another // option would be to take the SQRT of land area as a substitute for the missing values // To test the alternate methods I can try imputing values where they are already known // and then measure the variance ... // create a column to indicate a row with a missing value col = dtCombined << New Column("IsMissingData", Numeric, Nominal, Formula(IsMissing(:LotFrontage))); // create a subset of the data rows = dtCombined << Get Rows Where(IsMissingData==0); dtSub = dtCombined << Subset(Rows(rows), All Columns); // make a copy of the variable column values = Column(dtSub,varName) << Get Values; dtSub << New Column("Test", Numeric, Continuous, Set Values(values)); // Randomly select 100 (ish) rows and set the test value to empty nr = NRows(dtSub); lst = {}; For (i=1,i<=100,i++, InsertInto(lst,RandomInteger(1,nr)) ); Column(dtSub,"Test")[lst] = .; // missing value platform emv = dtSub << Explore Missing Values( Y( :LotFrontage, :LotArea, :OverallQual, ... :MoSold, :YrSold, :Test ) ); // multivariate normal imputation emv << Multivariate Normal Imputation; vData = Column(dtSub,varName)[lst]; tData = Column(dtSub,"Test")[lst]; diff = vData - tData; ssqMNV = SSQ(diff); // SVD imputation emv << Undo Imputation; emv << Multivariate SVD Imputation(3,10); vData = Column(dtSub,varName)[lst]; tData = Column(dtSub,"Test")[lst]; diff = vData - tData; ssqSVD = SSQ(diff); emv << Undo Imputation; emv << Close Window; // median impute medianValue = Col Quantile( Column(dtSub,"Test"), 0.5 ); Column(dtSub,"Test")[lst] = medianValue; vData = Column(dtSub,varName)[lst]; tData = Column(dtSub,"Test")[lst]; diff = vData - tData; ssqMED = SSQ(diff); // SQRT of land area impute values = Column(dtSub,"LotArea") << Get Values; sqrtValues = Sqrt(values); vData = sqrtValues[lst]; tData = Column(dtSub,"Test")[lst]; diff = vData - Matrix(tData); ssqSQR = SSQ(diff); // impute using a model mdl = Partition( Y( :LotFrontage ), X( :MSSubClass, :MSSubClass GRP, :MSZoning, ... :SaleType, :SaleCondition ), Method( "Boosted Tree" ), Splits per Tree( 3 ), Number of Layers( 50 ), Learning Rate( 0.1 ), Go ); mdl << Save Predicteds; vData = Column(dtSub,varName)[lst]; tData = Column(dtSub,NCols(dtSub))[lst]; diff = vData - tData; ssqMDL = SSQ(diff); mdl << Close Window; show( Round(ssqMNV,0) ); show( Round(ssqSVD,0) ); show( Round(ssqMED,0) ); show( Round(ssqSQR,0) ); show( Round(ssqMDL,0) ); //**************************/ // results //**************************/ // ssqMNV = 123305 // ssqSVD = 28197 // ssqMED = 65368 // ssqSQR = 122906 // ssqMDL = 13758 <<< //**************************/ //----------------------------------------------------------------------------------------------// // LotArea: square footage of the land area // //----------------------------------------------------------------------------------------------// varName = "LotArea"; // 5 outliers (both contained within the training data) - remove these dtCombined << Select Where(:LotArea > 60000); dtCombined << Delete Rows; // the data is slightly skewed, with a regression showing fewer leverage points // with transformed data col = dtCombined << New Column("Log LotArea",Numeric,Continuous,Formula(Log10(:LotArea))); // move new column adjacent to source dtCombined << Go To( col ); dtCombined << Move Selected Columns( After( Column(varName)) ); dtCombined << Clear Column Selection; // nolonger need the original column Column(dtCombined,varName) << Set Excluded << Set Hidden; //----------------------------------------------------------------------------------------------// // Street: indicates whether road access is paved or gravel // //----------------------------------------------------------------------------------------------// varName = "Street"; // 99.6% is paved - only 11 gravel observations, so exclude dtCombined << Delete Column("Street"); //----------------------------------------------------------------------------------------------// // Alley: Type of alley access - paved, gravel or no access // //----------------------------------------------------------------------------------------------// varName = "Alley"; // 93% no access; 120 rows gravel and 78 paved - keep for now //----------------------------------------------------------------------------------------------// // LotShape: Classification indicating level of irregularity of lot shape // //----------------------------------------------------------------------------------------------// varName = "LotShape"; // should be treated as ordinal Column(dtCombined,varName) << Set Modeling Type("Ordinal"); // there are 4 levels: Regular and 3 grades of irregular. 2 of the grades account for only 3% // of the data so collapse all irregular shapes together col = New Column("LotShape RCDE",Numeric,Continuous, Formula( Match( :LotShape, "IR1", "IR", "IR2", "IR", "IR3", "IR", :LotShape ) ) ); // move new column adjacent to source dtCombined << Go To( col ); dtCombined << Move Selected Columns( After( Column(varName)) ); dtCombined << Clear Column Selection; // nolonger need the original column Column(dtCombined,varName) << Set Excluded << Set Hidden; //----------------------------------------------------------------------------------------------// // LandContour: Topology of the land area // //----------------------------------------------------------------------------------------------// varName = "LandContour"; // there are 4 levels, one with 90% of data and no other exceeding 4%, so exclude for now dtCombined << Delete Column(varName); //----------------------------------------------------------------------------------------------// // Utilities: Indicates the type of utilities available // //----------------------------------------------------------------------------------------------// varName = "Utilities"; // 99.9% have all utilities so remove dtCombined << Delete Column(varName); //----------------------------------------------------------------------------------------------// // LotConfig: Indicates position of the lot // //----------------------------------------------------------------------------------------------// varName = "LotConfig"; /* // look to delete this, but first try collapsing the levels col1 = Collapse Class Variable(dtTrain,targetColName,varName,0.05,1,0); // apply this column to the combined data table fml = col1 << Get Formula; col2 = dtCombined << New Column(varName || " GRP", character, Formula( NameExpr(fml) )); // move new column adjacent to source dtCombined << Go To( col2 ); dtCombined << Move Selected Columns( After( Column(varName)) ); dtCombined << Clear Column Selection; // nolonger need the original column Column(dtCombined,varName) << Set Excluded << Set Hidden; */ // Combining leads to 2 levels one with 94% of data the other 6% // since one level is still very small, remove the column from analysis dtCombined << Delete Column(varName); //----------------------------------------------------------------------------------------------// // LandSlope: Degree of slope of the property // //----------------------------------------------------------------------------------------------// varName = "LandSlope"; // 3 level factor that should be ordinal, but 95.3% of data is in one level and 4.2% in another // so need to remove last level; but a oneway shows no significant effect so remove from analysis dtCombined << Delete Column(varName); //----------------------------------------------------------------------------------------------// // Neighborhood: Physical location of the property // //----------------------------------------------------------------------------------------------// varName = "Neighborhood"; // This appears to be one of the most important variables, but it has 25 levels, so created a // grouped variable with less levels // using a p-value threshold of 0.05 yields 3 discrete levels; // a smaller value (0.01) yields 5 levels which might be preferable given the importanance // of the variable but one level has less than 4% of the data, so stick with the default // p-value threshold col1 = Collapse Class Variable(dtTrain,targetColName,varName,0.05,1,0); // apply this column to the combined data table fml = col1 << Get Formula; col2 = dtCombined << New Column(varName || " GRP", character, Formula( NameExpr(fml) )); // move new column adjacent to source dtCombined << Go To( col2 ); dtCombined << Move Selected Columns( After( Column(varName)) ); dtCombined << Clear Column Selection; // nolonger need the original column Column(dtCombined,varName) << Set Excluded << Set Hidden; //----------------------------------------------------------------------------------------------// // Condition1: Proximity to specifc conditions e.g. railroad // //----------------------------------------------------------------------------------------------// varName = "Condition1"; // there are 9 levels with 86% of data in "normal", so collapse into a grouped variable col1 = Collapse Class Variable(dtTrain,targetColName,varName,0.05,1,0); // apply this column to the combined data table fml = col1 << Get Formula; col2 = dtCombined << New Column(varName || " GRP", character, Formula( NameExpr(fml) )); // move new column adjacent to source dtCombined << Go To( col2 ); dtCombined << Move Selected Columns( After( Column(varName)) ); dtCombined << Clear Column Selection; // nolonger need the original column Column(dtCombined,varName) << Set Excluded << Set Hidden; //----------------------------------------------------------------------------------------------// // Condition2: Proximity to conditons (if more than one present) // //----------------------------------------------------------------------------------------------// varName = "Condition2"; // 99% of data in the "normal" level dtCombined << Delete Column(varName); //----------------------------------------------------------------------------------------------// // BldgType: Type of dwelling e.g. townhouse end unit // //----------------------------------------------------------------------------------------------// varName = "BldgType"; // there aer 5 levels some with less than 5% of the data so aggregate into a grouped variable col1 = Collapse Class Variable(dtTrain,targetColName,varName,0.05,1,0); // apply this column to the combined data table fml = col1 << Get Formula; col2 = dtCombined << New Column(varName || " GRP", character, Formula( NameExpr(fml) )); // move new column adjacent to source dtCombined << Go To( col2 ); dtCombined << Move Selected Columns( After( Column(varName)) ); dtCombined << Clear Column Selection; // nolonger need the original column Column(dtCombined,varName) << Set Excluded << Set Hidden; //----------------------------------------------------------------------------------------------// // HouseStyle: Style of swelling e.g. one story, split level etc // //----------------------------------------------------------------------------------------------// varName = "HouseStyle"; // 8 levels but with over 90% of data contained in 3 levels, so group col1 = Collapse Class Variable(dtTrain,targetColName,varName,0.05,1,0); // apply this column to the combined data table fml = col1 << Get Formula; col2 = dtCombined << New Column(varName || " GRP", character, Formula( NameExpr(fml) )); // move new column adjacent to source dtCombined << Go To( col2 ); dtCombined << Move Selected Columns( After( Column(varName)) ); dtCombined << Clear Column Selection; // nolonger need the original column Column(dtCombined,varName) << Set Excluded << Set Hidden; //----------------------------------------------------------------------------------------------// // OverallQual: Rates the overall material and finish of the house // //----------------------------------------------------------------------------------------------// varName = "OverallQual"; // this variable is inherently ordinal, but with 10 levels can be treated as continuous Column(dtCombined,varName) << Set Modeling Type("Continuous"); //----------------------------------------------------------------------------------------------// // OverallCond: Rates the overall condition of the house // //----------------------------------------------------------------------------------------------// varName = "OverallCond"; // this variable is inherently ordinal, but with 10 levels can be treated as continuous Column(dtCombined,varName) << Set Modeling Type("Continuous"); //----------------------------------------------------------------------------------------------// // YearBuilt: Original construction date // //----------------------------------------------------------------------------------------------// varName = "YearBuilt"; // combine with YrSold to determine "AgeAtSale" col = dtCombined << New Column("AgeAtSale",Numeric,Continuous,Formula(:YrSold-YearBuilt)); // move new column adjacent to source dtCombined << Go To( col ); dtCombined << Move Selected Columns( After( Column(varName)) ); dtCombined << Clear Column Selection; // nolonger need the original column Column(dtCombined,varName) << Set Excluded << Set Hidden; //----------------------------------------------------------------------------------------------// // YearRemodAdd: remodel date // //----------------------------------------------------------------------------------------------// varName = "YearRemodAdd"; // if no remodelling has been done then the date is the same as the built date // - so can constuct a flag to indicate whether remodelling has been done col = dtCombined << New Column("hasBeenRemodelled",Numeric,Nominal,Formula(:YearRemodAdd!=:YearBuilt)); // move new column adjacent to source dtCombined << Go To( col ); dtCombined << Move Selected Columns( After( Column(varName)) ); dtCombined << Clear Column Selection; // Calculate age since remodelling (nb using missing if no remodelling) /* col = dtCombined << New Column("AgeSinceRemodel",Numeric,Continuous, Formula( If (:YearRemodAdd==YearBuilt, . , :YrSold-YearRemodAdd ) ) ); */ col = dtCombined << New Column("AgeSinceRemodel",Numeric,Continuous,Formula(:YrSold-YearRemodAdd)); // move new column adjacent to source dtCombined << Go To( col ); dtCombined << Move Selected Columns( After( Column(varName)) ); dtCombined << Clear Column Selection; // nolonger need the original column Column(dtCombined,varName) << Set Excluded << Set Hidden; //----------------------------------------------------------------------------------------------// // RoofStyle: Type of roof // //----------------------------------------------------------------------------------------------// varName = "RoofStyle"; // There are 6 roof types but one type covers 79% of the data and another type covers 19%. // Grouping the other 4 levels together would result in less than 60 rows (~2%) col1 = Collapse Class Variable(dtTrain,targetColName,varName,0.05,1,0); // apply this column to the combined data table fml = col1 << Get Formula; col2 = dtCombined << New Column(varName || " GRP", character, Formula( NameExpr(fml) )); // move new column adjacent to source dtCombined << Go To( col2 ); dtCombined << Move Selected Columns( After( Column(varName)) ); dtCombined << Clear Column Selection; // nolonger need the original column Column(dtCombined,varName) << Set Excluded << Set Hidden; //----------------------------------------------------------------------------------------------// // RoofMatl: Roof material // //----------------------------------------------------------------------------------------------// varName = "RoofMatl"; // ther are 7 levels, but one level accounts for 98.6 nof the data, so remove dtCombined << Delete Column(varName); //----------------------------------------------------------------------------------------------// // Exterior1st: Exteriod material covering the house // //----------------------------------------------------------------------------------------------// varName = "Exterior1st"; // there are 16 levels to this variable so reduce the number into a grouped variable // (note: default p-value threshold results in 4 levels one of which is very sparse, // so have used a higher threshold to create 3 levels) col1 = Collapse Class Variable(dtTrain,targetColName,varName,0.1,1,0); // apply this column to the combined data table fml = col1 << Get Formula; col2 = dtCombined << New Column(varName || " GRP", character, Formula( NameExpr(fml) )); // move new column adjacent to source dtCombined << Go To( col2 ); dtCombined << Move Selected Columns( After( Column(varName)) ); dtCombined << Clear Column Selection; // nolonger need the original column // defer this until post-processing of exterio2nd //Column(dtCombined,varName) << Set Excluded << Set Hidden; //----------------------------------------------------------------------------------------------// // Exterior2nd: Exterior material covering on house (if more than one) // //----------------------------------------------------------------------------------------------// varName = "Exterior2nd"; // one option for handling this is to create a flag to indicate whehter there is moer than one material // the other is to combine both into single values: exterior1/exterior2. Try both ways! // create flag column col = dtCombined << New Column("has2ExteriorMaterials",Numeric,Nominal,Formula(:Exterior2nd!=:Exterior1st)); // move new column adjacent to source dtCombined << Go To( col ); dtCombined << Move Selected Columns( After( Column(varName)) ); dtCombined << Clear Column Selection; // create composite column ... // the composite column has 87 levels but the only dominant levels are those where there is no // 2nd material so replace these to "Other" (which will effectively make the flag redundant) col = dtCombined << New Column("Exterior",Character,Nominal, Formula( If (:Exterior1st==:Exterior2nd, :Exterior1st , "Other" ) ) ); // move new column adjacent to source dtCombined << Go To( col ); dtCombined << Move Selected Columns( After( Column("has2ExteriorMaterials")) ); dtCombined << Clear Column Selection; // now group the composite column (note to do this the composite column has to be put into the // training table) dtTrain << New Column("Exterior",Character,Nominal, Formula( If (:Exterior1st==:Exterior2nd, :Exterior1st , "Other" ) ) ); dtTrain << Run Formulas; col1 = Collapse Class Variable(dtTrain,targetColName,"Exterior",0.05,1,0); // apply this column to the combined data table fml = col1 << Get Formula; col2 = dtCombined << New Column("Exterior" || " GRP", character, Formula( NameExpr(fml) )); // move new column adjacent to source dtCombined << Go To( col2 ); dtCombined << Move Selected Columns( After( Column("Exterior")) ); dtCombined << Clear Column Selection; // nolonger need these Column(dtCombined,"Exterior1st") << Set Excluded << Set Hidden; Column(dtCombined,"Exterior2nd") << Set Excluded << Set Hidden; Column(dtCombined,"Exterior") << Set Excluded << Set Hidden; //----------------------------------------------------------------------------------------------// // MasVnrType: Masonry veneer type // //----------------------------------------------------------------------------------------------// varName = "MasVnrType"; // there are 5 levels, 3 of which contain less than 1% of the data (each), so group // (the level 'none' contains 60%) col1 = Collapse Class Variable(dtTrain,targetColName,varName,0.05,1,0); // apply this column to the combined data table fml = col1 << Get Formula; col2 = dtCombined << New Column(varName || " GRP", character, Formula( NameExpr(fml) )); // move new column adjacent to source dtCombined << Go To( col2 ); dtCombined << Move Selected Columns( After( Column(varName)) ); dtCombined << Clear Column Selection; // nolonger need the original column Column(dtCombined,varName) << Set Excluded << Set Hidden; //----------------------------------------------------------------------------------------------// // MasVnrArea: Masonry veneer area in square feet // //----------------------------------------------------------------------------------------------// varName = "MasVnrArea"; // given that 60% of properties do not have any masonry veneer this is a zero-inflated variable // zero values are not representative of the data so either (i) replace with missing or // (ii) replace with median values // actually, do both - use median values for regression models and missing values for models // that can handle informative missing // with missing values col = dtCombined << New Column("MasVnrArea ZIP",Numeric,Continuous, Formula( If (:MasVnrArea==0, . , :MasVnrArea ) ) ); // move new column adjacent to source dtCombined << Go To( col ); dtCombined << Move Selected Columns( After( Column(varName)) ); dtCombined << Clear Column Selection; // with median values medianValue = Col Quantile( Column(dtCombined,"MasVnrArea ZIP"), 0.5 ); col = dtCombined << New Column("MasVnrArea MED",Numeric,Continuous, Formula( If (:MasVnrArea==0, medianValue , :MasVnrArea ) ) ); // move new column adjacent to source dtCombined << Go To( col ); dtCombined << Move Selected Columns( After( Column(varName)) ); dtCombined << Clear Column Selection; // nolonger need the original column Column(dtCombined,varName) << Set Excluded << Set Hidden; //----------------------------------------------------------------------------------------------// // ExterQual: Evaluates the quality of the material on the exterior // //----------------------------------------------------------------------------------------------// varName = "ExterQual"; // this is a 5 level character ordinal scale |