Skip to content

[SPARK-4081] [mllib] VectorIndexer #3000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mllib/src/main/scala/org/apache/spark/ml/Pipeline.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ abstract class PipelineStage extends Serializable with Logging {

/**
* Derives the output schema from the input schema and parameters, optionally with logging.
*
* This should be optimistic. If it is unclear whether the schema will be valid, then it should
* be assumed valid until proven otherwise.
*/
protected def transformSchema(
schema: StructType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class AttributeGroup private (
def getAttr(attrIndex: Int): Attribute = this(attrIndex)

/** Converts to metadata without name. */
private[attribute] def toMetadata: Metadata = {
private[attribute] def toMetadataImpl: Metadata = {
import AttributeKeys._
val bldr = new MetadataBuilder()
if (attributes.isDefined) {
Expand Down Expand Up @@ -142,17 +142,24 @@ class AttributeGroup private (
bldr.build()
}

/** Converts to a StructField with some existing metadata. */
def toStructField(existingMetadata: Metadata): StructField = {
val newMetadata = new MetadataBuilder()
/** Converts to ML metadata with some existing metadata. */
def toMetadata(existingMetadata: Metadata): Metadata = {
new MetadataBuilder()
.withMetadata(existingMetadata)
.putMetadata(AttributeKeys.ML_ATTR, toMetadata)
.putMetadata(AttributeKeys.ML_ATTR, toMetadataImpl)
.build()
StructField(name, new VectorUDT, nullable = false, newMetadata)
}

/** Converts to ML metadata */
def toMetadata: Metadata = toMetadata(Metadata.empty)

/** Converts to a StructField with some existing metadata. */
def toStructField(existingMetadata: Metadata): StructField = {
StructField(name, new VectorUDT, nullable = false, toMetadata(existingMetadata))
}

/** Converts to a StructField. */
def toStructField(): StructField = toStructField(Metadata.empty)
def toStructField: StructField = toStructField(Metadata.empty)

override def equals(other: Any): Boolean = {
other match {
Expand Down
Loading