Why concatenate features in machine learning?

Viewed 997

I am learning Microsoft ML framework and confused why features need to be concatenated. In Iris flower example from Microsoft here: https://docs.microsoft.com/en-us/dotnet/machine-learning/tutorials/iris-clustering

... features are concatenated:

string featuresColumnName = "Features";
var pipeline = mlContext.Transforms
    .Concatenate(featuresColumnName, "SepalLength", "SepalWidth", "PetalLength", "PetalWidth")
    ...

Are multiple features treated as a single feature in order to do calculations like linear regression? If so, how is this accurate? What is happening behind the scenes?

1 Answers

According to the official documentation,

concatenation is necessary because trainers take feature vectors as inputs.

It essentially transforms the features in the form of separate columns into a single column of feature vectors. Feature values themselves remain intact; only their format and type is changed. It is more clear through this example:

Before transformation:

        var samples = new List<InputData>()
        {
            new InputData(){ Feature1 = 0.1f, Feature2 = new[]{ 1.1f, 2.1f,
                3.1f }, Feature3 = 1 },

            new InputData(){ Feature1 = 0.2f, Feature2 = new[]{ 1.2f, 2.2f,
                3.2f }, Feature3 = 2 },

            new InputData(){ Feature1 = 0.3f, Feature2 = new[]{ 1.3f, 2.3f,
                3.3f }, Feature3 = 3 },

            new InputData(){ Feature1 = 0.4f, Feature2 = new[]{ 1.4f, 2.4f,
                3.4f }, Feature3 = 4 },

            new InputData(){ Feature1 = 0.5f, Feature2 = new[]{ 1.5f, 2.5f,
                3.5f }, Feature3 = 5 },

            new InputData(){ Feature1 = 0.6f, Feature2 = new[]{ 1.6f, 2.6f,
                3.6f }, Feature3 = 6 },
        };

After:

    //  "Features" column obtained post-transformation.
    //  0.1 1.1 2.1 3.1 1
    //  0.2 1.2 2.2 3.2 2
    //  0.3 1.3 2.3 3.3 3
    //  0.4 1.4 2.4 3.4 4
    //  0.5 1.5 2.5 3.5 5
    //  0.6 1.6 2.6 3.6 6
Related