PCA transformation

Example A.13. PCA transformation

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#                                                                       #
#                   AdvancedMiner Example Script                        #
#            Copyright Algolytics sp. z o. o. 2004-2015                 #
#                                                                       #
#                                                                       #
# Description:                                                          #
#     The script contains an example of PCA transformation.             #
#                                                                       #
# Input data:                                                           #
#            Dataset from Smoothing Methods in Statistics               #
#            (ftp stat.cmu.edu/datasets)                                #
#                                                                       #
#            Simonoff, J.S. (1996). Smoothing Methods in Statistics.    #
#            New York: Springer-Verlag.                                 #
#                                                                       #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
table 'baskball' :
    assists_per_minute height time_played age points_per_minute
    0.0888 201.0 36.02 28.0 0.5885
    0.1399 198.0 39.32 30.0 0.8291
    0.0747 198.0 38.8 26.0 0.4974
    0.0983 191.0 40.71 30.0 0.5772
    0.1276 196.0 38.4 28.0 0.5703
    0.1671 201.0 34.1 31.0 0.5835
    0.1906 193.0 36.2 30.0 0.5276
    0.1061 191.0 36.75 27.0 0.5523
    0.2446 185.0 38.43 29.0 0.4007
    0.167 203.0 33.54 24.0 0.477
    0.2485 188.0 35.01 27.0 0.4313
    0.1227 198.0 36.67 29.0 0.4909
    0.124 185.0 33.88 24.0 0.5668
    0.1461 191.0 35.59 30.0 0.5113
    0.2315 191.0 38.01 28.0 0.3788
    0.0494 193.0 32.38 32.0 0.559
    0.1107 196.0 35.22 25.0 0.4799
    0.2521 183.0 31.73 29.0 0.5735
    0.1007 193.0 28.81 34.0 0.6318
    0.1067 196.0 35.6 23.0 0.4326
    0.1956 188.0 35.28 32.0 0.428
    0.1828 191.0 29.54 28.0 0.4401
    0.1627 196.0 31.35 28.0 0.5581
    0.1403 198.0 33.5 23.0 0.4866
    0.1563 193.0 34.56 32.0 0.5267
    0.2681 183.0 39.53 27.0 0.5439
    0.1236 196.0 26.7 34.0 0.4419
    0.13 188.0 30.77 26.0 0.3998
    0.0896 198.0 25.67 30.0 0.4325
    0.2071 178.0 36.22 30.0 0.4086
    0.2244 185.0 36.55 23.0 0.4624
    0.3437 185.0 34.91 31.0 0.4325
    0.1058 191.0 28.35 28.0 0.4903
    0.2326 185.0 33.53 27.0 0.4802
    0.1577 193.0 31.07 25.0 0.4345
    0.2327 185.0 36.52 32.0 0.4819
    0.1256 196.0 27.87 29.0 0.6244
    0.107 198.0 24.31 34.0 0.3991
    0.1343 193.0 31.26 28.0 0.4414
    0.0586 196.0 22.18 23.0 0.4013
    0.2383 185.0 35.25 26.0 0.3801
    0.1006 198.0 22.87 30.0 0.3498
    0.2164 193.0 24.49 32.0 0.3185
    0.1485 198.0 23.57 27.0 0.3097
    0.227 191.0 31.72 27.0 0.4319
    0.1649 188.0 27.9 25.0 0.3799
    0.1188 191.0 22.74 24.0 0.4091
    0.194 193.0 20.62 27.0 0.3588
    0.2495 185.0 30.46 25.0 0.4727
    0.2378 185.0 32.38 27.0 0.3212
    0.1592 191.0 25.75 31.0 0.3418
    0.2069 170.0 33.84 30.0 0.4285
    0.2084 185.0 27.83 25.0 0.3917
    0.0877 193.0 21.67 26.0 0.5769
    0.101 193.0 21.79 24.0 0.4773
    0.0942 201.0 20.17 26.0 0.4512
    0.055 193.0 29.07 31.0 0.3096
    0.1071 196.0 24.28 24.0 0.3089
    0.0728 193.0 19.24 27.0 0.4573
    0.2771 180.0 27.07 28.0 0.3214
    0.0528 196.0 18.95 22.0 0.5437
    0.213 188.0 21.59 30.0 0.4121
    0.1356 193.0 13.27 31.0 0.2185
    0.1043 196.0 16.3 23.0 0.3313
    0.113 191.0 23.01 25.0 0.3302
    0.1477 196.0 20.31 31.0 0.4677
    0.1317 188.0 17.46 33.0 0.2406
    0.2187 191.0 21.95 28.0 0.3007
    0.2127 188.0 14.57 37.0 0.2471
    0.2547 160.0 34.55 28.0 0.2894
    0.1591 191.0 22.0 24.0 0.3682
    0.0898 196.0 13.37 34.0 0.389
    0.2146 188.0 20.51 24.0 0.512
    0.1871 183.0 19.78 28.0 0.4449
    0.1528 191.0 16.36 33.0 0.4035
    0.156 191.0 16.03 23.0 0.2683
    0.2348 188.0 24.27 26.0 0.2719
    0.1623 180.0 18.49 28.0 0.3408
    0.1239 180.0 17.76 26.0 0.4393
    0.2178 185.0 13.31 25.0 0.3004
    0.1608 185.0 17.41 26.0 0.3503
    0.0805 193.0 13.67 25.0 0.4388
    0.1776 193.0 17.46 27.0 0.2578
    0.1668 185.0 14.38 35.0 0.2989
    0.1072 188.0 12.12 31.0 0.4455
    0.1821 185.0 12.63 25.0 0.3087
    0.188 180.0 12.24 30.0 0.3678
    0.1167 196.0 12.0 24.0 0.3667
    0.2617 185.0 24.46 27.0 0.3189
    0.1994 188.0 20.06 27.0 0.4187
    0.1706 170.0 17.0 25.0 0.5059
    0.1554 183.0 11.58 24.0 0.3195
    0.2282 185.0 10.08 24.0 0.2381
    0.1778 185.0 18.56 23.0 0.2802
    0.1863 185.0 11.81 23.0 0.381
    0.1014 193.0 13.81 32.0 0.1593
        
pd = PhysicalData('baskball')
save('pd', pd)

ld = LogicalData(pd)
save('ld', ld)

pCASettings = PCASettings();
pCASettings.logicalData=ld
pCASettings.setCriterion(PCACriterion.KAISER)
pCASettings.setStandardize(TRUE)

save('PCA_ps', pCASettings)

bt = TransformationBuildTask()
bt.transformationName='PCA_tr'
bt.physicalDataName= 'pd'
bt.transformationSettingsName='PCA_ps'
save('PCA_bt', bt)

execute('PCA_bt')

tat=TransformationApplyTask()



save('pd_out',PhysicalData('PCA_out'))
tat.setTargetDataName('pd_out')
tat.setTransformationName('PCA_tr')

tat.setSourceDataName('pd')

save('PCA_at', tat)

execute('PCA_at')

print 'See result in PCA_out table...'

# print first 5 rows of result table
print "Printing first 5 rows:"
print "component_1  component_2"
trans None<-'PCA_out':
    if __rowNumber__<5: 
        print "%8.4f     %8.4f"%(component_1,component_2)

Output:

See result in PCA_out table...
Printing first 5 rows:
component_1  component_2
  2.7778      -0.1732
  3.5347      -1.9591
  2.2514      -0.0083
  2.0564      -1.1573
  2.0581      -0.8847