Error adding VectorAssembler to Spark ML Pipeline

Trying to add VectorAssembler to the GBT pipeline example and get an error the pipeline cannot find the features field. I'm bringing in a sample file instead of a libsvm so I needed to transform the feature set set.

Error:
Exception in thread "main" java.lang.IllegalArgumentException: Field "features" does not exist.

If you call fit(sampleDF), VectorIndexer will search for features column in sampleDF, but this dataset doesn't have such column.

You should not call fit () manually, it will be done when calling fit() on pipeline - then pipeline will call all transformator and estimators, so call fit on assembler, then pass the result to fit of labelIndexer and pass previous step result to fit of featureIndexer.

DataFrame that will be used in featureIndexer.fit() called inside Pipeline will have all columns generated by previous transformers.

Remember that if you are using standalone VectorIndexer you must fit model on one data and then use this model to transform new data. If you are using VectorIndexer inside pipeline, then don't use fit() on VectorIndexer - it will be called when calling Pipeline.fit().

In your code sampleDF doesn't have features column, however, during Pipeline fit() this column will be added by assembler stage