Loading...

verticapy.machine_learning.vertica.decomposition.PCA

class verticapy.machine_learning.vertica.decomposition.PCA(name: str = None, overwrite_model: bool = False, n_components: int = 0, scale: bool = False, method: Literal['lapack'] = 'lapack')

Creates a PCA (Principal Component Analysis) object using the Vertica PCA algorithm.

Parameters

name: str, optional

Name of the model. The model is stored in the database.

overwrite_model: bool, optional

If set to True, training a model with the same name as an existing model overwrites the existing model.

n_components: int, optional

The number of components to keep in the model. If this value is not provided, all components are kept. The maximum number of components is the number of non-zero singular values returned by the internal call to SVD. This number is less than or equal to SVD (number of columns, number of rows).

scale: bool, optional

A Boolean value that specifies whether to standardize the columns during the preparation step.

method: str, optional

The method used to calculate PCA.

  • lapack:

    Lapack definition.

Attributes

Many attributes are created during the fitting phase.

principal_components_: numpy.array

Matrix of the principal components.

mean_: numpy.array

List of the averages of each input feature.

cos2_: numpy.array

Quality of representation of each observation in the principal component space. A high cos2 value indicates that the observation is well-represented in the reduced-dimensional space defined by the principal components, while a low value suggests poor representation.

explained_variance_: numpy.array

Represents the proportion of the total variance in the original dataset that is captured by a specific principal component or a combination of principal components.

Note

All attributes can be accessed using the get_attributes() method.

Note

Several other attributes can be accessed by using the get_vertica_attributes() method.

Examples

The following examples provide a basic understanding of usage. For more detailed examples, please refer to the Machine Learning or the Examples section on the website.

Load data for machine learning

We import verticapy:

import verticapy as vp

Hint

By assigning an alias to verticapy, we mitigate the risk of code collisions with other libraries. This precaution is necessary because verticapy uses commonly known function names like “average” and “median”, which can potentially lead to naming conflicts. The use of an alias ensures that the functions from verticapy are used as intended without interfering with functions from other libraries.

For this example, we will use the winequality dataset.

import verticapy.datasets as vpd

data = vpd.load_winequality()
123
fixed_acidity
Numeric(8)
123
volatile_acidity
Numeric(9)
123
citric_acid
Numeric(8)
123
residual_sugar
Numeric(9)
123
chlorides
Float(22)
123
free_sulfur_dioxide
Numeric(9)
123
total_sulfur_dioxide
Numeric(9)
123
density
Float(22)
123
pH
Numeric(8)
123
sulphates
Numeric(8)
123
alcohol
Float(22)
123
quality
Integer
123
good
Integer
Abc
color
Varchar(20)
13.90.2250.44.20.0329.0118.00.9893.570.3612.881white
24.70.3350.141.30.03669.0168.00.992123.470.4610.550white
34.70.4550.181.90.03633.0106.00.987463.210.8314.071white
44.70.7850.03.40.03623.0134.00.989813.530.9213.860white
54.90.3450.341.00.06832.0143.00.991383.240.410.150white
64.90.3450.341.00.06832.0143.00.991383.240.410.150white
74.90.420.02.10.04816.042.00.991543.710.7414.071red
85.00.270.41.20.07642.0124.00.992043.320.4710.160white
95.00.310.06.40.04643.0166.00.9943.30.639.960white
105.00.40.54.30.04629.080.00.99023.490.6613.660red
115.00.440.0418.60.03938.0128.00.99853.370.5710.260white
125.10.110.321.60.02812.090.00.990083.570.5212.260white
135.10.140.250.70.03915.089.00.99193.220.439.260white
145.10.1650.225.70.04742.0146.00.99343.180.559.960white
155.10.330.221.60.02718.089.00.98933.510.3812.571white
165.10.330.221.60.02718.089.00.98933.510.3812.571white
175.10.330.221.60.02718.089.00.98933.510.3812.571white
185.10.390.211.70.02715.072.00.98943.50.4512.560white
195.20.20.273.20.04716.093.00.992353.440.5310.171white
205.20.210.311.70.04817.061.00.989533.240.3712.071white
215.20.220.466.20.06641.0187.00.993623.190.429.7333333333333350white
225.20.310.22.40.02727.0117.00.988863.560.4513.071white
235.20.320.251.80.10313.050.00.99573.380.559.250red
245.20.340.376.20.03142.0133.00.990763.250.4112.560white
255.20.360.021.60.03124.0104.00.98963.440.3512.260white
265.20.3650.0813.50.04137.0142.00.9973.460.399.960white
275.20.480.041.60.05419.0106.00.99273.540.6212.271red
285.20.50.182.00.03623.0129.00.989493.360.7713.471white
295.30.160.391.00.02840.0101.00.991563.570.5910.660white
305.30.160.391.00.02840.0101.00.991563.570.5910.660white
315.30.1650.241.10.05125.0105.00.99253.320.479.150white
325.30.230.560.90.04146.0141.00.991193.160.629.750white
335.30.30.31.20.02925.093.00.987423.310.413.671white
345.30.330.31.20.04825.0119.00.990453.320.6211.360white
355.30.360.276.30.02840.0132.00.991863.370.411.660white
365.30.360.276.30.02840.0132.00.991863.370.411.660white
375.30.40.253.90.03145.0130.00.990723.310.5811.7571white
385.30.470.112.20.04816.089.00.991823.540.8813.671red
395.30.470.112.20.04816.089.00.991823.540.8813.566666666666771red
405.30.7150.191.50.1617.062.00.993953.620.6111.050red
415.40.220.291.20.04569.0152.00.991783.760.6311.071white
425.40.5950.12.80.04226.080.00.99323.360.389.350white
435.40.740.091.70.08916.026.00.994023.670.5611.660red
445.50.120.331.00.03823.0131.00.991643.250.459.850white
455.50.120.331.00.03823.0131.00.991643.250.459.850white
465.50.140.274.60.02922.0104.00.99493.340.449.050white
475.50.140.274.60.02922.0104.00.99493.340.449.050white
485.50.160.311.20.02631.068.00.98983.330.4411.6560white
495.50.160.311.20.02631.068.00.98983.330.4411.633333333333360white
505.50.180.225.50.03710.086.00.991563.460.4412.250white
515.50.240.451.70.04622.0113.00.992243.220.4810.050white
525.50.290.31.10.02220.0110.00.988693.340.3812.871white
535.50.310.293.00.02716.0102.00.990673.230.5611.260white
545.50.320.454.90.02825.0191.00.99223.510.4911.571white
555.50.350.351.10.04514.0167.00.9923.340.689.960white
565.50.3750.381.70.03617.098.00.991423.290.3910.560white
575.60.150.265.550.05151.0139.00.993363.470.511.060white
585.60.150.315.30.0388.079.00.99233.30.3910.560white
595.60.160.271.40.04453.0168.00.99183.280.3710.160white
605.60.1750.290.80.04320.067.00.991123.280.489.960white
615.60.1850.197.10.04836.0110.00.994383.260.419.560white
625.60.1850.197.10.04836.0110.00.994383.260.419.560white
635.60.220.321.20.02429.097.00.988233.20.4613.0571white
645.60.260.181.40.03418.0135.00.991743.320.3510.260white
655.60.260.265.70.03112.080.00.99233.250.3810.850white
665.60.260.511.40.02925.093.00.994283.230.4910.560white
675.60.280.284.20.04452.0158.00.9923.350.4410.771white
685.60.30.16.40.04334.0142.00.993823.140.489.850white
695.60.350.145.00.04648.0198.00.99373.30.7110.350white
705.60.490.134.50.03917.0116.00.99073.420.913.771white
715.60.490.134.50.03917.0116.00.99073.420.913.771white
725.60.660.02.20.0873.011.00.993783.710.6312.871red
735.60.660.02.20.0873.011.00.993783.710.6312.871red
745.70.150.4711.40.03549.0128.00.994563.030.3410.581white
755.70.180.262.20.02321.095.00.98933.070.5412.360white
765.70.180.361.20.0469.071.00.991993.70.6810.971white
775.70.20.32.50.04638.0125.00.992763.340.59.960white
785.70.210.320.90.03838.0121.00.990743.240.4610.660white
795.70.210.374.50.0458.0140.00.993323.290.6210.660white
805.70.220.216.00.04441.0113.00.998623.220.468.960white
815.70.220.216.00.04441.0113.00.998623.220.468.960white
825.70.220.216.00.04441.0113.00.998623.220.468.960white
835.70.220.216.00.04441.0113.00.998623.220.468.960white
845.70.220.216.00.04441.0113.00.998623.220.468.960white
855.70.220.293.50.0427.0146.00.989993.170.3612.160white
865.70.230.289.650.02526.0121.00.99253.280.3811.360white
875.70.250.2612.50.04952.5106.00.996913.080.459.460white
885.70.250.2612.50.04952.5120.00.996913.080.459.460white
895.70.250.2711.50.0424.0120.00.994113.330.3110.860white
905.70.260.2417.80.05923.0124.00.997733.30.510.150white
915.70.260.2417.80.05923.0124.00.997733.30.510.150white
925.70.260.2417.80.05923.0124.00.997733.30.510.150white
935.70.270.321.20.04620.0155.00.99343.80.4110.260white
945.70.280.2417.50.04460.0167.00.99893.310.449.450white
955.70.320.181.40.02926.0104.00.99063.440.3711.060white
965.70.320.384.750.03323.094.00.9913.420.4211.871white
975.70.360.344.20.02621.077.00.99073.410.4511.960white
985.80.140.156.10.04227.0123.00.993623.060.69.960white
995.80.150.321.20.03714.0119.00.991373.190.510.260white
1005.80.170.341.80.04596.0170.00.990353.380.911.881white
Rows: 1-100 | Columns: 14

Note

VerticaPy offers a wide range of sample datasets that are ideal for training and testing purposes. You can explore the full list of available datasets in the Datasets, which provides detailed information on each dataset and how to use them effectively. These datasets are invaluable resources for honing your data analysis and machine learning skills within the VerticaPy environment.

We can drop the “color” column as it is varchar type.

data.drop("color")

Model Initialization

First we import the PCA model:

from verticapy.machine_learning.vertica import PCA

Then we can create the model:

model = PCA(
    n_components = 3,
)

You can select the number of components by the n_component parameter. If it is not provided, then all are considered.

Hint

In verticapy 1.0.x and higher, you do not need to specify the model name, as the name is automatically assigned. If you need to re-use the model, you can fetch the model name from the model’s attributes.

Important

The model name is crucial for the model management system and versioning. It’s highly recommended to provide a name if you plan to reuse the model later.

Model Training

We can now fit the model:

model.fit(data)


=======
columns
=======
index|        name        |  mean   |   sd   
-----+--------------------+---------+--------
  1  |   fixed_acidity    | 7.21531 | 1.29643
  2  |  volatile_acidity  | 0.33967 | 0.16464
  3  |    citric_acid     | 0.31863 | 0.14532
  4  |   residual_sugar   | 5.44324 | 4.75780
  5  |     chlorides      | 0.05603 | 0.03503
  6  |free_sulfur_dioxide |30.52532 |17.74940
  7  |total_sulfur_dioxide|115.74457|56.52185
  8  |      density       | 0.99470 | 0.00300
  9  |         ph         | 3.21850 | 0.16079
 10  |     sulphates      | 0.53127 | 0.14881
 11  |      alcohol       |10.49180 | 1.19271
 12  |      quality       | 5.81838 | 0.87326
 13  |        good        | 0.19655 | 0.39742


===============
singular_values
===============
index| value  |explained_variance|accumulated_explained_variance
-----+--------+------------------+------------------------------
  1  |58.06985|      0.95351     |            0.95351           
  2  |11.98567|      0.04062     |            0.99413           
  3  | 4.13105|      0.00483     |            0.99896           


====================
principal_components
====================
index|  PC1   |  PC2   |  PC3   
-----+--------+--------+--------
  1  |-0.00741|-0.00537| 0.02386
  2  |-0.00118|-0.00079| 0.00091
  3  | 0.00049|-0.00025| 0.00192
  4  | 0.04102| 0.01863| 0.99519
  5  |-0.00017| 0.00007| 0.00018
  6  | 0.23048| 0.97262|-0.02711
  7  | 0.97217|-0.23139|-0.03586
  8  | 0.00000| 0.00000| 0.00046
  9  |-0.00066| 0.00065|-0.00691
 10  |-0.00070| 0.00035|-0.00194
 11  |-0.00545| 0.00288|-0.08266
 12  |-0.00053| 0.00916|-0.00889
 13  |-0.00033| 0.00257|-0.00593


========
counters
========
   counter_name   |counter_value
------------------+-------------
accepted_row_count|    6497     
rejected_row_count|      0      
 iteration_count  |      1      


===========
call_string
===========
SELECT PCA('"public"."_verticapy_tmp_pca_v_mldb_6a3e7c2e979711efa8720242ac120002_"', '"public"."_verticapy_tmp_view_v_mldb_6a7b3c04979711efa8720242ac120002_"', '"fixed_acidity", "volatile_acidity", "citric_acid", "residual_sugar", "chlorides", "free_sulfur_dioxide", "total_sulfur_dioxide", "density", "pH", "sulphates", "alcohol", "quality", "good"'
USING PARAMETERS scale=false, num_components=3);

Important

To train a model, you can directly use the vDataFrame or the name of the relation stored in the database.

Scores

The decomposition score on the dataset for each transformed column can be calculated by:

model.score()
Out[4]: 
None                                   Score  
fixed_acidity               3.26018188659356  
volatile_acidity           0.255704870531141  
citric_acid                0.232055113862187  
residual_sugar             0.784335096491506  
chlorides                 0.0412739282041458  
free_sulfur_dioxide        0.743079726641214  
total_sulfur_dioxide        1.03787465340887  
density                   0.0561515090418319  
pH                         0.801959298244123  
sulphates                  0.303876275255451  
alcohol                     4.02272456571807  
quality                     2.54477536599627  
good                       0.348243267430713  
Rows: 1-13 | Columns: 2

For more details on the function, check out score()

You can also fetch the explained variance by:

model.explained_variance_
Out[5]: array([0.95351037, 0.04062083, 0.00482552])

Principal Components

To get the transformed dataset in the form of principal components:

model.transform(data)
Out[6]: 
None                col1                  col2                   col3  
1       58.2585435866956      50.2581718382341      -7.15770033829499  
2       47.8458923519163      22.9883205947403      -2.56964241029969  
3       55.3788310502415      46.7802985538193      -7.45917494667214  
4       55.8773719495785     -33.4658268951551       -5.7612979172938  
5      -15.2310907537325      13.2721178525629      -4.02619559516123  
6      -6.66895840225282     -7.21300376171408      -2.27046351728112  
7      -6.55502655331496     -12.1686938056515       5.01741673181464  
8       17.5008031764373      12.6595659366785      -5.22319739599441  
9       64.0218965257457      -7.6609298570904      -7.00387756953786  
10      3.27549637771102      2.98554661691686       6.13681673815753  
11      35.0776851714977     0.281798297982037      -6.05124271309634  
12      59.5163276885018      25.2569270184036      -7.08677590412429  
13      59.5163276885018      25.2569270184036      -7.08677590412429  
14      39.6841016220826      6.39508394279764      -4.60997393999157  
15      61.0027620426437      9.58292669483431      -4.70032804310602  
16      39.6146400834972     -16.9614288466675       4.85177815550989  
17     -9.05233764951464      4.63067668949458      -3.60265729333252  
18     -71.3209829620149      1.95095263269743      -1.55326105628056  
19     -44.8177038153328     -3.32408322957085      -1.97193555518783  
20      34.4954873429935     -10.9184000917509      -5.77391014958169  
21      16.0557078794116      10.0876558355333      0.301566854171824  
22     -14.7925554427983     -2.23755020006416      -3.49815587620536  
23     -35.9331209476593      7.94028679930402      -1.34254106589017  
24     -38.8823966562382      4.48833970280952      -3.12535345595975  
25     -40.2475149621483     -1.34154829779239      -2.46499047023164  
26     -22.2439190727728     -7.64669388773425      -3.15856230273649  
27     -43.8486203630266     -3.54797443411161      -2.06066615700047  
28     -37.9825447838218     -9.06930587461121      -2.65098373716963  
29     -14.7176386387758     -7.22915685663195       2.79821670371247  
30      5.87868202428021      11.3419902859004      -4.68490339600052  
31      5.87868202428021      11.3419902859004      -4.68490339600052  
32     -53.0361658378291     -7.56802962653592      -2.38792515916192  
33     -2.18645483941726     -2.00295741680722       1.98891773276953  
34     -45.2419386762454     -9.41311081776226      -2.18616368987377  
35     -60.7026869530663     -13.9295260643832      -1.53198510227278  
36     -12.0977825304334     0.221015212890943      -2.27030993497004  
37     -4.23590901086943      6.69306391189276       1.74416419472203  
38     -28.9423854285489      2.29809920192316       1.98015091955561  
39      14.9711139961645      41.0221634644192      -5.48379105461812  
40     -8.89199083888603     0.544774112136061     -0.802536442046489  
41     -23.5633723605189    -0.158474443586148      -3.57342555010811  
42       30.951920634207      8.46775316590347      -3.85908075190824  
43     -8.39746657541938     -1.63604022426093      -1.26320600579139  
44     -60.9274109944813      6.70068383920975      -1.25659879942325  
45     -71.3239461395363      1.94880379853522      -1.54371564900316  
46     -26.3271101035469     -11.8316349249606      -3.20114227347833  
47     -42.6631180778819     -2.82046371621985      -2.53137244580647  
48      3.13858172797976    -0.313314340722323      -3.63199332923701  
49     -17.7257199740003      -19.042961915661      -2.81789228127042  
50     -28.6845498098243      4.16886554183883      -2.88451102497602  
51     -21.1368994490638     -7.86904708071976    -0.0505301707979124  
52     -43.8567232892656     0.616666828063992      -1.00122049575341  
53     -43.8567232892656     0.616666828063992      -1.00122049575341  
54     -13.3898146125559     -5.57989179416356     0.0789195527929948  
55     -50.6701591427734     -1.94729914664207      -2.23100117676321  
56      36.7343745322282     -14.5349150809514      -5.37438544593779  
57      5.54392122869397     -16.3153376375122      -2.86742379241561  
58     -45.4995344865387     -6.22144753680841      -1.59002136120339  
59      51.3890491383617    -0.515319080832429       -5.1735252192907  
60      -8.4552801596779     -15.8433463863653       5.18028150863589  
61     -11.3452508986281      12.3250923024257       -4.1362072202068  
62     -24.4591677987751     -1.65753683516123       9.43165664047288  
63     -21.3517440617296    -0.525811760264606       2.75160644879837  
64     -21.3517440617296    -0.525811760264606       2.75160644879837  
65     -27.6662555296056     -1.09200730619686       2.52334048417307  
66      54.9395589948006     -20.7582582225397      -1.17977372548587  
67     -17.5483170110743      7.68829760512098      -2.69484923618189  
68     -105.914733294145     -1.11813575030598      0.541918795710582  
69     -105.914733294145     -1.11813575030598      0.541918795710582  
70     -58.6556742195508     -1.06977984719543      -1.38022635757763  
71     -105.684929342291    -0.162232221938359      0.432516347466094  
72      -103.48483223194     0.383321377182943       1.08956518419427  
73     -18.4568875105065     -5.38113396956644      0.927947984624256  
74      40.3122897522569      17.5707761764461      -3.81164089238009  
75      40.3122897522569      17.5707761764461      -3.81164089238009  
76      -3.2004038488878      -1.7974698694657       1.03254923632082  
77     -31.5872109925239     -16.7698728126436      -2.69617343137619  
78      77.8939482830483      11.6668429317711      -6.56181482485684  
79      77.8939482830483      11.6668429317711      -6.56181482485684  
80      6.49764491315117     0.901393112002678      -4.27003463262866  
81      72.7569547959708      50.8734792819764      -8.33797192598707  
82     -4.23685380698288      7.57556593326435      -3.69053012357174  
83      -18.694106678149     -1.31855012765248      -3.54737619016085  
84     -62.3171405117399     -9.19510699563876       7.63941681809391  
85     -10.7167283879474      1.93446727781806      -3.44551093652981  
86      36.9370652532915      7.17362872293809     -0.275934599737356  
87      36.9370652532915      7.17362872293809     -0.275934599737356  
88     -4.11501330759734      2.60757174492509       3.63976956684187  
89     -4.11501330759734      2.60757174492509       3.63976956684187  
90     -23.4522869302903      13.1845512500111       -3.0741906393028  
91     -30.9328980436483     -1.40965296609462     -0.190808411699063  
92     -22.8580984418803      2.74602275333044      -3.32639842349154  
93     -5.79893309122244     -12.5114932944398    -0.0707707043574328  
94     -5.79893309122244     -12.5114932944398    -0.0707707043574328  
95      55.1436384119657     -15.6605619821546     -0.638954470669958  
96      51.7376826854555     -11.9415002244243      -5.83312383826673  
97      5.97630943862789        3.070478923037      -4.54308193034896  
98      64.1812667449478     -21.7614310143679       4.85207523153766  
99      64.1812667449478     -21.7614310143679       4.85207523153766  
100    -19.6058608927542     -5.24345400802905      -3.34594564413817  
Rows: 1-100 | Columns: 3

Please refer to transform() for more details on transforming a vDataFrame.

Similarly, you can perform the inverse tranform to get the original features using:

model.inverse_transform(data_transformed)

The variable data_transformed includes the PCA components.

Plots - PCA

You can plot the first two components conveniently using:

model.plot()

Plots - Scree

You can also plot the Scree plot:

model.plot_scree()
Loading....

Parameter Modification

In order to see the parameters:

model.get_params()
Out[7]: {'n_components': 3, 'scale': False, 'method': 'lapack'}

And to manually change some of the parameters:

model.set_params({'n_components': 3})

Model Register

In order to register the model for tracking and versioning:

model.register("model_v1")

Please refer to /notebooks/ml/model_tracking_versioning/index.ipynb for more details on model tracking and versioning.

Model Exporting

To Memmodel

model.to_memmodel()

Note

MemModel objects serve as in-memory representations of machine learning models. They can be used for both in-database and in-memory prediction tasks. These objects can be pickled in the same way that you would pickle a scikit-learn model.

The preceding methods for exporting the model use MemModel, and it is recommended to use MemModel directly.

SQL

To get the SQL query use below:

model.to_sql()
Out[9]: 
['("fixed_acidity" - 7.21530706479914) * -0.0074079438036857 + ("volatile_acidity" - 0.339665999692166) * -0.00118432129646062 + ("citric_acid" - 0.318633215330152) * 0.000486867004519226 + ("residual_sugar" - 5.44323533938741) * 0.0410197294279797 + ("chlorides" - 0.0560338617823611) * -0.000168197431343703 + ("free_sulfur_dioxide" - 30.5253193781746) * 0.230481489722234 + ("total_sulfur_dioxide" - 115.744574418963) * 0.972166693841427 + ("density" - 0.994696633830999) * 1.77249642312968e-06 + ("pH" - 3.21850084654456) * -0.000655520779893174 + ("sulphates" - 0.531268277666616) * -0.000704339207760155 + ("alcohol" - 10.4918008311528) * -0.0054518247482017 + ("quality" - 5.81837771279052) * -0.000532705277259336 + ("good" - 0.196552254886871) * -0.000326386219750347',
 '("fixed_acidity" - 7.21530706479914) * -0.00537208540551765 + ("volatile_acidity" - 0.339665999692166) * -0.000787179265927931 + ("citric_acid" - 0.318633215330152) * -0.000247100931315455 + ("residual_sugar" - 5.44323533938741) * 0.0186262696200209 + ("chlorides" - 0.0560338617823611) * 6.67995503853843e-05 + ("free_sulfur_dioxide" - 30.5253193781746) * 0.972615829133943 + ("total_sulfur_dioxide" - 115.744574418963) * -0.231392918488152 + ("density" - 0.994696633830999) * 1.27197739295354e-06 + ("pH" - 3.21850084654456) * 0.000648027441471814 + ("sulphates" - 0.531268277666616) * 0.00034656412640182 + ("alcohol" - 10.4918008311528) * 0.00288222663864494 + ("quality" - 5.81837771279052) * 0.00915670157688833 + ("good" - 0.196552254886871) * 0.00256735969031285',
 '("fixed_acidity" - 7.21530706479914) * 0.023863518193516 + ("volatile_acidity" - 0.339665999692166) * 0.000908752011458777 + ("citric_acid" - 0.318633215330152) * 0.00192084403361971 + ("residual_sugar" - 5.44323533938741) * 0.995191758737064 + ("chlorides" - 0.0560338617823611) * 0.000177543760783034 + ("free_sulfur_dioxide" - 30.5253193781746) * -0.0271071934686966 + ("total_sulfur_dioxide" - 115.744574418963) * -0.0358591349601494 + ("density" - 0.994696633830999) * 0.000460901781338664 + ("pH" - 3.21850084654456) * -0.00691133676962069 + ("sulphates" - 0.531268277666616) * -0.00193655721535334 + ("alcohol" - 10.4918008311528) * -0.0826607385648236 + ("quality" - 5.81837771279052) * -0.0088875638392344 + ("good" - 0.196552254886871) * -0.00592921565549885']

To Python

To obtain the prediction function in Python syntax, use the following code:

X = [[3.8, 0.3, 0.02, 11, 0.03, 20, 113, 0.99, 3, 0.4, 12, 6, 0]]

model.to_python()(X)
Out[11]: array([[-4.84895114, -9.47474643,  5.70830533]])

Hint

The to_python() method is used to retrieve the Principal Component values. For specific details on how to use this method for different model types, refer to the relevant documentation for each model.

__init__(name: str = None, overwrite_model: bool = False, n_components: int = 0, scale: bool = False, method: Literal['lapack'] = 'lapack') → None

Must be overridden in the child class

Methods

__init__([name, overwrite_model, ...])

Must be overridden in the child class

contour([nbins, chart])

Draws the model's contour plot.

deployInverseSQL([key_columns, ...])

Returns the SQL code needed to deploy the inverse model.

deploySQL([X, n_components, cutoff, ...])

Returns the SQL code needed to deploy the model.

does_model_exists(name[, raise_error, ...])

Checks whether the model is stored in the Vertica database.

drop()

Drops the model from the Vertica database.

export_models(name, path[, kind])

Exports machine learning models.

fit(input_relation[, X, return_report])

Trains the model.

get_attributes([attr_name])

Returns the model attributes.

get_match_index(x, col_list[, str_check])

Returns the matching index.

get_params()

Returns the parameters of the model.

get_plotting_lib([class_name, chart, ...])

Returns the first available library (Plotly, Matplotlib, or Highcharts) to draw a specific graphic.

get_vertica_attributes([attr_name])

Returns the model Vertica attributes.

import_models(path[, schema, kind])

Imports machine learning models.

inverse_transform(vdf[, X])

Applies the Inverse Model on a vDataFrame.

plot([dimensions, chart])

Draws a decomposition scatter plot.

plot_circle([dimensions, chart])

Draws a decomposition circle.

plot_scree([chart])

Draws a decomposition scree plot.

register(registered_name[, raise_error])

Registers the model and adds it to in-DB Model versioning environment with a status of 'under_review'.

score([X, input_relation, metric, p])

Returns the decomposition score on a dataset for each transformed column.

set_params([parameters])

Sets the parameters of the model.

summarize()

Summarizes the model.

to_binary(path)

Exports the model to the Vertica Binary format.

to_memmodel()

Converts the model to an InMemory object that can be used for different types of predictions.

to_pmml(path)

Exports the model to PMML.

to_python([return_proba, ...])

Returns the Python function needed for in-memory scoring without using built-in Vertica functions.

to_sql([X, return_proba, ...])

Returns the SQL code needed to deploy the model without using built-in Vertica functions.

to_tf(path)

Exports the model to the Frozen Graph format (TensorFlow).

transform([vdf, X, n_components, cutoff])

Applies the model on a vDataFrame.

Attributes