本文整理匯總了Python中pyspark.ml.feature.StringIndexer.labels方法的典型用法代碼示例。如果您正苦於以下問題:Python StringIndexer.labels方法的具體用法?Python StringIndexer.labels怎麽用?Python StringIndexer.labels使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyspark.ml.feature.StringIndexer
的用法示例。
在下文中一共展示了StringIndexer.labels方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: VectorAssembler
# 需要導入模塊: from pyspark.ml.feature import StringIndexer [as 別名]
# 或者: from pyspark.ml.feature.StringIndexer import labels [as 別名]
train_feature_df = train_feature_df.drop('time')
test_feature_df = test_feature_df.drop('time')
assembler = VectorAssembler(
inputCols=list(set(train_feature_df.columns) - set(['result', 'home_name', 'away_name'])),
outputCol="features")
train_df = assembler.transform(train_feature_df)
test_df = assembler.transform(test_feature_df)
labelIndexer = StringIndexer(inputCol="result", outputCol="indexedResult").fit(feature_df)
train_df = labelIndexer.transform(train_df)
test_df = labelIndexer.transform(test_df)
label_mapping = dict(enumerate(labelIndexer.labels()))
reverse_mapping = {}
for key in label_mapping:
reverse_mapping[label_mapping[key]] = key
# ## Dimensionality reduction
#
# Feature selection is not really supported yet in mllib, therefore, we just applied dim reduction using PCA
# In[509]:
pca = PCA(inputCol="features", outputCol="pca", k=15).fit(train_df)
train_df = pca.transform(train_df)
test_df = pca.transform(test_df)