Columns to vector
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 port | Data type | Recommended upstream component | Required |
|---|---|---|---|
| data | Integer | Read Table, Read CSV File | Yes |
Component parameters
Field Setting tab
| Parameter | Description | Default |
|---|---|---|
| reservedCols | Names of the columns to keep in the output alongside the vector column. | All columns |
| selectedCols | Names of the numeric columns to combine into a vector. | — |
Parameter Setting tab
| Parameter | Description | Default | Valid values |
|---|---|---|---|
| vectorCol | Name of the output column that contains the vector. | — | — |
| handleInvalid | Policy 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. | ERROR | ERROR, SKIP |
| vectorSize | Number of elements in the vector. | -1 | — |
Execution Tuning tab
| Parameter | Description | Valid values |
|---|---|---|
| Number of Workers | Number of parallel workers. Must be set together with Memory per worker, unit MB. | Positive integer; 1–9999 |
| Memory per worker, unit MB | Memory allocated to each worker. | 1024–65536 |
Output ports
| Output port | Storage location | Recommended downstream component | Model type |
|---|---|---|---|
| Output result | N/A | None | None |
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.