Columns to vector

Updated at:

The Columns to vector component combines multiple numeric columns into a single vector column, making tabular data ready for ML models such as logistic regression and decision trees that expect feature vectors as input.

Limits

Supported compute engines: MaxCompute and Realtime Compute for Apache Flink.

How it works

The component reads the columns you specify in selectedCols, concatenates their values in order, and writes the result as a single vector to the column named by vectorCol. All other columns are dropped unless listed in reservedCols.

Configure the component in Machine Learning Designer

Input ports

Input portData typeRecommended upstream componentRequired
dataIntegerRead Table, Read CSV FileYes

Component parameters

Field Setting tab

ParameterDescriptionDefault
reservedColsNames of the columns to keep in the output alongside the vector column.All columns
selectedColsNames of the numeric columns to combine into a vector.

Parameter Setting tab

ParameterDescriptionDefaultValid values
vectorColName of the output column that contains the vector.
handleInvalidPolicy for rows that contain invalid values. ERROR stops the job immediately, making it easy to catch data quality issues early. SKIP drops those rows and returns NULL, which is useful when running on noisy data where some missing values are expected.ERRORERROR, SKIP
vectorSizeNumber of elements in the vector.-1

Execution Tuning tab

ParameterDescriptionValid values
Number of WorkersNumber of parallel workers. Must be set together with Memory per worker, unit MB.Positive integer; 1–9999
Memory per worker, unit MBMemory allocated to each worker.1024–65536

Output ports

Output portStorage locationRecommended downstream componentModel type
Output resultN/ANoneNone

Example

The following example uses the PyAlink Script component to replicate this component's behavior in code. Copy the code into the PyAlink Script code editor.

All calls use ColumnsToVectorBatchOp to select input columns, reserve additional columns, and write the output vector.

from pyalink.alink import *

def main(sources, sinks, parameter):
    data = sources[0]
    op = ColumnsToVectorBatchOp()\
        .setSelectedCols(["f0", "f1"])\
        .setReservedCols(["row"])\
        .setVectorCol("vec")\
        .linkFrom(data)
    result = op.linkFrom(data)
    result.link(sinks[0])
    BatchOperator.execute()

Replace ["f0", "f1"], ["row"], and "vec" with your own column names.