Loading...

verticapy.machine_learning.vertica.decomposition.MCA

class verticapy.machine_learning.vertica.decomposition.MCA(name: str = None, overwrite_model: bool = False)

Creates a MCA (multiple correspondence analysis) object using the Vertica PCA algorithm. MCA is a PCA applied to a complete disjunctive table. The input relation is transformed to a TCDT (transformed complete disjunctive table) before applying the PCA.

Important

This algorithm is not Vertica Native and relies solely on SQL for attribute computation. While this model does not take advantage of the benefits provided by a model management system, including versioning and tracking, the SQL code it generates can still be used to create a pipeline.

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.

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 Titanic dataset.

import verticapy.datasets as vpd

data = vpd.load_titanic()
123
pclass
Integer
123
survived
Integer
Abc
Varchar(164)
Abc
sex
Varchar(20)
123
age
Numeric(8)
123
sibsp
Integer
123
parch
Integer
Abc
ticket
Varchar(36)
123
fare
Numeric(12)
Abc
cabin
Varchar(30)
Abc
embarked
Varchar(20)
Abc
boat
Varchar(100)
123
body
Integer
Abc
Varchar(100)
110male71.000PC 1760949.5042[null]C[null]22
210male45.00011378435.5TS[null][null]
310male[null]0011379831.0[null]S[null][null]
410male17.00011305947.1[null]S[null][null]
510male27.01013508136.7792C89C[null][null]
610male37.011PC 1775683.1583E52C[null][null]
710male31.010F.C. 1275052.0B71S[null][null]
810male50.010PC 17761106.425C86C[null]62
910female36.000PC 1753131.6792A29C[null][null]
1010male37.01011380353.1C123S[null][null]
1110male24.000PC 1759379.2B86C[null][null]
1210male45.0103697383.475C83S[null][null]
1310male40.0001120590.0B94S[null]110
1410male42.00011303842.5B11S[null][null]
1510male[null]001746351.8625E46S[null][null]
1610male42.01011378952.0[null]S[null]38
1710male[null]00PC 1760030.6958[null]C14[null]
1810male29.00011350130.0D6S[null]126
1910male46.0001305075.2417C6C[null]292
2010male54.0001746351.8625E46S[null]175
2110male47.00011379642.4[null]S[null][null]
2210male58.00235273113.275D48C[null]122
2310male45.50011304328.5C124S[null]166
2410male29.01011377666.6C2S[null][null]
2510male47.00011046552.0C110S[null]207
2610male38.000199720.0[null]S[null][null]
2710male22.000PC 17760135.6333[null]C[null]232
2810male31.000PC 1759050.4958A24S[null][null]
2910male50.0101350755.9E44S[null][null]
3010male56.0001776430.6958A7C[null][null]
3110male57.010PC 17569146.5208B78C[null][null]
3210female63.010PC 17483221.7792C55 C57S[null][null]
3310male61.0003696332.3208D50S[null]46
3410male21.0013528177.2875D26S[null]169
3510male51.001PC 1759761.3792[null]C[null][null]
3611female63.0101350277.9583D7S10[null]
3711female32.0001181376.2917D15C8[null]
3811female58.00011378326.55C103S8[null]
3911female44.000PC 1761027.7208B4C6[null]
4011female41.00016966134.5E40C3[null]
4111female53.000PC 1760627.4458[null]C6[null]
4211male36.001PC 17755512.3292B51 B53 B55C3[null]
4311female58.001PC 17755512.3292B51 B53 B55C3[null]
4411male11.012113760120.0B96 B98S4[null]
4511female76.0101987778.85C46S6[null]
4611female[null]0111350555.0E33S6[null]
4711female39.011PC 1775683.1583E49C14[null]
4811female27.012F.C. 1275052.0B71S3[null]
4911female[null]0017421110.8833[null]C4[null]
5011female35.000113503211.5C130C4[null]
5111female22.00111237859.4[null]C7[null]
5211female25.0101176555.4417E50C5[null]
5311male48.010PC 1757276.7292D33C3[null]
5411female35.0103697383.475C83SD[null]
5511male27.000PC 1757276.7292D49C3[null]
5611female24.0001176783.1583C54C7[null]
5711female52.0111274993.5B69S3[null]
5811female44.00111136157.9792B18C4[null]
5911female15.00124160211.3375B5S2[null]
6011male30.0101323657.75C78C11[null]
6111female31.01035273113.275D36C6[null]
6211female39.000PC 17758108.9C105C8[null]
6311female22.00111350961.9792B36C5[null]
6411male52.00011378630.5C104S6[null]
6511female43.00124160211.3375B3S2[null]
6611female33.00011015286.5B77S8[null]
6711male45.01116966134.5E34C3[null]
6811female40.01116966134.5E34C3[null]
6911male48.0101999652.0C126S5 7[null]
7011female[null]00PC 1758579.2[null]CD[null]
7111female35.000PC 17755512.3292[null]C3[null]
7211female60.01011081375.25D37C5[null]
7311male21.001PC 1759761.3792[null]CA[null]
7420male23.000C.A. 3103010.5[null]S[null][null]
7520male28.00024435826.0[null]S[null][null]
7620male60.0112975039.0[null]S[null][null]
7720female44.01024425226.0[null]S[null][null]
7820male29.010200326.0[null]S[null][null]
7920male18.000S.O.C. 1487973.5[null]S[null][null]
8020male18.000S.O.C. 1487973.5[null]S[null][null]
8120male54.0002840326.0[null]S[null][null]
8220male18.00023617113.0[null]S[null][null]
8320male36.00022923613.0[null]S[null]236
8420male34.0102866421.0[null]S[null][null]
8520male21.0102813311.5[null]S[null][null]
8620male21.0102813411.5[null]S[null][null]
8720male24.00023386613.0[null]S[null]155
8820male34.0001223313.0[null]S[null][null]
8920male30.00025065313.0[null]S[null]75
9020male44.00024874613.0[null]S[null]35
9120male49.01222084565.0[null]S[null][null]
9220male21.020S.O.C. 1487973.5[null]S[null][null]
9320male21.000S.O.C. 1487973.5[null]S[null][null]
9420female60.0102406526.0[null]S[null][null]
9520male24.020C.A. 3102931.5[null]S[null][null]
9620male22.020C.A. 3102931.5[null]S[null][null]
9720male35.00023373412.35[null]Q[null][null]
9820male31.000C.A. 1872310.5[null]S[null]165
9920male36.000SC/Paris 216312.875DC[null][null]
10020male[null]00SC/A.3 286115.5792[null]C[null][null]
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.

Model Initialization

First we import the MCA model:

from verticapy.machine_learning.vertica import MCA

Then we can create the model:

model = MCA()

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

Important

As this model is not native, it solely relies on SQL statements to compute various attributes, storing them within the object. No data is saved in the database.

Model Training

Before fitting the model, we need to calculate the Transformed Completely Disjontive Table before fitting the model:

tcdt = data[["survived", "pclass", "sex"]].cdt()

We can now fit the model:

model.fit(tcdt)

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[6]: 
None            Score  
survived_0        0.0  
survived_1        0.0  
pclass_1          0.0  
pclass_2          0.0  
pclass_3          0.0  
sex_female        0.0  
sex_male          0.0  
Rows: 1-7 | Columns: 2

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

You can also fetch the explained variance by:

model.explained_variance_
Out[7]: 
array([3.71602747e-01, 3.42234698e-01, 2.01530443e-01, 8.46321118e-02,
       4.58523775e-17, 3.71471553e-18, 4.48009740e-16])

Principal Components

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

model.transform(tcdt)
Out[8]: 
None                   col1                     col2                    col3                     col4                     col5                    col6   \\
1       0.00229204335572604      0.00032174051601337    0.000797337308334705     -0.00224766909385811    -1.78934016041576e-16    2.14129929065887e-16   \\
2       0.00229204335572604      0.00032174051601337    0.000797337308334705     -0.00224766909385811    -1.78934016041576e-16    2.14129929065887e-16   \\
3       0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
4       0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
5       0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
6       0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
7       0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
8       0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
9       0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
10      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
11      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
12      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
13      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
14      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
15      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
16      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
17      0.00229204335572604      0.00032174051601337    0.000797337308334705     -0.00224766909385811    -1.78934016041576e-16    2.14129929065887e-16   \\
18      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
19      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
20      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
21      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
22      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
23      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
24      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
25      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
26      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
27      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
28      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
29      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
30      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
31      0.00146911605526444    -0.000826178800615592     0.00235861847839742    -0.000590677084987079    -1.78642636707721e-16    2.13642038088269e-16   \\
32       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
33       0.0024040087227709     0.000370460404419619     0.00166740181096483      0.00135391740166905     -1.7609476160238e-16     2.1391308863139e-16   \\
34       0.0024040087227709     0.000370460404419619     0.00166740181096483      0.00135391740166905     -1.7609476160238e-16     2.1391308863139e-16   \\
35       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
36       0.0024040087227709     0.000370460404419619     0.00166740181096483      0.00135391740166905     -1.7609476160238e-16     2.1391308863139e-16   \\
37       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
38       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
39       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
40       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
41       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
42       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
43       0.0024040087227709     0.000370460404419619     0.00166740181096483      0.00135391740166905     -1.7609476160238e-16     2.1391308863139e-16   \\
44       0.0024040087227709     0.000370460404419619     0.00166740181096483      0.00135391740166905     -1.7609476160238e-16     2.1391308863139e-16   \\
45       0.0024040087227709     0.000370460404419619     0.00166740181096483      0.00135391740166905     -1.7609476160238e-16     2.1391308863139e-16   \\
46       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
47       0.0024040087227709     0.000370460404419619     0.00166740181096483      0.00135391740166905     -1.7609476160238e-16     2.1391308863139e-16   \\
48       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
49       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
50       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
51       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
52       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
53       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
54       0.0024040087227709     0.000370460404419619     0.00166740181096483      0.00135391740166905     -1.7609476160238e-16     2.1391308863139e-16   \\
55       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
56       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
57       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
58       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
59       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
60       0.0024040087227709     0.000370460404419619     0.00166740181096483      0.00135391740166905     -1.7609476160238e-16     2.1391308863139e-16   \\
61       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
62       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
63       0.0024040087227709     0.000370460404419619     0.00166740181096483      0.00135391740166905     -1.7609476160238e-16     2.1391308863139e-16   \\
64       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
65       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
66       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
67       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
68       0.0024040087227709     0.000370460404419619     0.00166740181096483      0.00135391740166905     -1.7609476160238e-16     2.1391308863139e-16   \\
69       0.0024040087227709     0.000370460404419619     0.00166740181096483      0.00135391740166905     -1.7609476160238e-16     2.1391308863139e-16   \\
70       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
71       0.0024040087227709     0.000370460404419619     0.00166740181096483      0.00135391740166905     -1.7609476160238e-16     2.1391308863139e-16   \\
72       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
73       0.0024040087227709     0.000370460404419619     0.00166740181096483      0.00135391740166905     -1.7609476160238e-16     2.1391308863139e-16   \\
74       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
75       0.0024040087227709     0.000370460404419619     0.00166740181096483      0.00135391740166905     -1.7609476160238e-16     2.1391308863139e-16   \\
76       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
77       0.0024040087227709     0.000370460404419619     0.00166740181096483      0.00135391740166905     -1.7609476160238e-16     2.1391308863139e-16   \\
78       0.0024040087227709     0.000370460404419619     0.00166740181096483      0.00135391740166905     -1.7609476160238e-16     2.1391308863139e-16   \\
79       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
80       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
81       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
82       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
83       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
84       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
85       0.0032269360232325      0.00151837972104858     0.00010612064090212    -0.000303074607201982    -1.76386140936236e-16    2.14455189717633e-16   \\
86     -0.00288205990078061      0.00144320031180486     0.00136902297293012    -0.000247042678679404    -1.78588426599097e-16     2.1391308863139e-16   \\
87     -0.00288205990078061      0.00144320031180486     0.00136902297293012    -0.000247042678679404    -1.78588426599097e-16     2.1391308863139e-16   \\
88     -0.00288205990078061      0.00144320031180486     0.00136902297293012    -0.000247042678679404    -1.78588426599097e-16     2.1391308863139e-16   \\
89     -0.00288205990078061      0.00144320031180486     0.00136902297293012    -0.000247042678679404    -1.78588426599097e-16     2.1391308863139e-16   \\
90     -0.00288205990078061      0.00144320031180486     0.00136902297293012    -0.000247042678679404    -1.78588426599097e-16     2.1391308863139e-16   \\
91     -0.00288205990078061      0.00144320031180486     0.00136902297293012    -0.000247042678679404    -1.78588426599097e-16     2.1391308863139e-16   \\
92     -0.00288205990078061      0.00144320031180486     0.00136902297293012    -0.000247042678679404    -1.78588426599097e-16     2.1391308863139e-16   \\
93     -0.00288205990078061      0.00144320031180486     0.00136902297293012    -0.000247042678679404    -1.78588426599097e-16     2.1391308863139e-16   \\
94     -0.00288205990078061      0.00144320031180486     0.00136902297293012    -0.000247042678679404    -1.78588426599097e-16     2.1391308863139e-16   \\
95     -0.00288205990078061      0.00144320031180486     0.00136902297293012    -0.000247042678679404    -1.78588426599097e-16     2.1391308863139e-16   \\
96     -0.00288205990078061      0.00144320031180486     0.00136902297293012    -0.000247042678679404    -1.78588426599097e-16     2.1391308863139e-16   \\
97     -0.00288205990078061      0.00144320031180486     0.00136902297293012    -0.000247042678679404    -1.78588426599097e-16     2.1391308863139e-16   \\
98     -0.00288205990078061      0.00144320031180486     0.00136902297293012    -0.000247042678679404    -1.78588426599097e-16     2.1391308863139e-16   \\
99     -0.00288205990078061      0.00144320031180486     0.00136902297293012    -0.000247042678679404    -1.78588426599097e-16     2.1391308863139e-16   \\
100    -0.00288205990078061      0.00144320031180486     0.00136902297293012    -0.000247042678679404    -1.78588426599097e-16     2.1391308863139e-16   \\
None                    col7  
1      -1.31025832544873e-16  
2      -1.31025832544873e-16  
3      -1.31649248794052e-16  
4      -1.31649248794052e-16  
5      -1.31649248794052e-16  
6      -1.31649248794052e-16  
7      -1.31649248794052e-16  
8      -1.31649248794052e-16  
9      -1.31649248794052e-16  
10     -1.31649248794052e-16  
11     -1.31649248794052e-16  
12     -1.31649248794052e-16  
13     -1.31649248794052e-16  
14     -1.31649248794052e-16  
15     -1.31649248794052e-16  
16     -1.31649248794052e-16  
17     -1.31025832544873e-16  
18     -1.31649248794052e-16  
19     -1.31649248794052e-16  
20     -1.31649248794052e-16  
21     -1.31649248794052e-16  
22     -1.31649248794052e-16  
23     -1.31649248794052e-16  
24     -1.31649248794052e-16  
25     -1.31649248794052e-16  
26     -1.31649248794052e-16  
27     -1.31649248794052e-16  
28     -1.31649248794052e-16  
29     -1.31649248794052e-16  
30     -1.31649248794052e-16  
31     -1.31649248794052e-16  
32     -1.33844758193336e-16  
33     -1.34468174442515e-16  
34     -1.34468174442515e-16  
35     -1.33844758193336e-16  
36     -1.34468174442515e-16  
37     -1.33844758193336e-16  
38     -1.33844758193336e-16  
39     -1.33844758193336e-16  
40     -1.33844758193336e-16  
41     -1.33844758193336e-16  
42     -1.33844758193336e-16  
43     -1.34468174442515e-16  
44     -1.34468174442515e-16  
45     -1.34468174442515e-16  
46     -1.33844758193336e-16  
47     -1.34468174442515e-16  
48     -1.33844758193336e-16  
49     -1.33844758193336e-16  
50     -1.33844758193336e-16  
51     -1.33844758193336e-16  
52     -1.33844758193336e-16  
53     -1.33844758193336e-16  
54     -1.34468174442515e-16  
55     -1.33844758193336e-16  
56     -1.33844758193336e-16  
57     -1.33844758193336e-16  
58     -1.33844758193336e-16  
59     -1.33844758193336e-16  
60     -1.34468174442515e-16  
61     -1.33844758193336e-16  
62     -1.33844758193336e-16  
63     -1.34468174442515e-16  
64     -1.33844758193336e-16  
65     -1.33844758193336e-16  
66     -1.33844758193336e-16  
67     -1.33844758193336e-16  
68     -1.34468174442515e-16  
69     -1.34468174442515e-16  
70     -1.33844758193336e-16  
71     -1.34468174442515e-16  
72     -1.33844758193336e-16  
73     -1.34468174442515e-16  
74     -1.33844758193336e-16  
75     -1.34468174442515e-16  
76     -1.33844758193336e-16  
77     -1.34468174442515e-16  
78     -1.34468174442515e-16  
79     -1.33844758193336e-16  
80     -1.33844758193336e-16  
81     -1.33844758193336e-16  
82     -1.33844758193336e-16  
83     -1.33844758193336e-16  
84     -1.33844758193336e-16  
85     -1.33844758193336e-16  
86      -1.3403449357352e-16  
87      -1.3403449357352e-16  
88      -1.3403449357352e-16  
89      -1.3403449357352e-16  
90      -1.3403449357352e-16  
91      -1.3403449357352e-16  
92      -1.3403449357352e-16  
93      -1.3403449357352e-16  
94      -1.3403449357352e-16  
95      -1.3403449357352e-16  
96      -1.3403449357352e-16  
97      -1.3403449357352e-16  
98      -1.3403449357352e-16  
99      -1.3403449357352e-16  
100     -1.3403449357352e-16  
Rows: 1-100 | Columns: 7

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 MCA components.

Plots - MCA

You can plot the first two dimensions conveniently using:

model.plot()

Plots - Scree

You can also plot the Scree plot:

model.plot_scree()
Loading....

Plots - Decomposition Circle

You can also plot the Decomposition Circles:

model.plot_circle()

Model Register

As this model is not native, it does not support model management and versioning. However, it is possible to use the SQL code it generates for deployment.

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]: 
['("survived_0" - -0.999189627228525) * -0.181634302254857 + ("survived_1" - -0.999189627228525) * 0.316447317706116 + ("pclass_1" - -0.999189627228525) * 0.648146903282895 + ("pclass_2" - -0.999189627228525) * -0.588909547134058 + ("pclass_3" - -0.999189627228525) * -0.0749536366765797 + ("sex_female" - -0.999189627228525) * 0.272960421482614 + ("sex_male" - -0.999189627228525) * -0.140839529511913',
 '("survived_0" - -0.999189627228525) * -0.232487358829214 + ("survived_1" - -0.999189627228525) * 0.405044642937851 + ("pclass_1" - -0.999189627228525) * 0.12304188125764 + ("pclass_2" - -0.999189627228525) * 0.689909726160875 + ("pclass_3" - -0.999189627228525) * -0.327414307734686 + ("sex_female" - -0.999189627228525) * 0.38075847078997 + ("sex_male" - -0.999189627228525) * -0.196460144633645',
 '("survived_0" - -0.999189627228525) * 0.134292054542375 + ("survived_1" - -0.999189627228525) * -0.233966601691513 + ("pclass_1" - -0.999189627228525) * 0.612207252170771 + ("pclass_2" - -0.999189627228525) * 0.25190527149492 + ("pclass_3" - -0.999189627228525) * -0.386503963792662 + ("sex_female" - -0.999189627228525) * -0.517868305005971 + ("sex_male" - -0.999189627228525) * 0.267204776538706',
 '("survived_0" - -0.999189627228525) * -0.377802794939543 + ("survived_1" - -0.999189627228525) * 0.658216424961079 + ("pclass_1" - -0.999189627228525) * -0.169709763121012 + ("pclass_2" - -0.999189627228525) * -0.0518795498186792 + ("pclass_3" - -0.999189627228525) * 0.100130089738782 + ("sex_female" - -0.999189627228525) * -0.549615059411761 + ("sex_male" - -0.999189627228525) * 0.283585165789851',
 '("survived_0" - -0.999189627228525) * 0.831334231648148 + ("survived_1" - -0.999189627228525) * 0.477168882961496 + ("pclass_1" - -0.999189627228525) * 0.105081084294435 + ("pclass_2" - -0.999189627228525) * 0.0872307718982565 + ("pclass_3" - -0.999189627228525) * 0.223297304125609 + ("sex_female" - -0.999189627228525) * 0.0516338525183842 + ("sex_male" - -0.999189627228525) * 0.100071323690393',
 '("survived_0" - -0.999189627228525) * 0.0 + ("survived_1" - -0.999189627228525) * 1.24263724796271e-16 + ("pclass_1" - -0.999189627228525) * -0.158651249622961 + ("pclass_2" - -0.999189627228525) * -0.131700877090842 + ("pclass_3" - -0.999189627228525) * -0.337133905448692 + ("sex_female" - -0.999189627228525) * 0.421207057725456 + ("sex_male" - -0.999189627228525) * 0.816339392829816',
 '("survived_0" - -0.999189627228525) * -0.247128905111581 + ("survived_1" - -0.999189627228525) * -0.141846948087061 + ("pclass_1" - -0.999189627228525) * 0.353489618841737 + ("pclass_2" - -0.999189627228525) * 0.293441702820515 + ("pclass_3" - -0.999189627228525) * 0.751165440038467 + ("sex_female" - -0.999189627228525) * 0.173694732678169 + ("sex_male" - -0.999189627228525) * 0.336636934285787']

To Python

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

X = [[0, 1, 0, 1, 1, 0, 1]]

model.to_python()(X)
Out[11]: 
array([[-0.23724135,  1.41279017,  0.02580683,  0.88306341,  2.76206562,
         0.95707065,  2.75761838]])

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) → 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_contrib([dimension, chart])

Draws a decomposition contribution plot of the input dimension.

plot_cos2([dimensions, chart])

Draws a MCA (multiple correspondence analysis) cos2 plot of the two input dimensions.

plot_scree([chart])

Draws a decomposition scree plot.

plot_var([dimensions, method, chart])

Draws the MCA (multiple correspondence analysis) graph.

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