文本分类

Python 中的 Spark SQL 入门

Mark Plutowski

Data Scientist

结尾词预测

Python 中的 Spark SQL 入门

序列箭头

Python 中的 Spark SQL 入门

结尾词

Python 中的 Spark SQL 入门

结尾词括号

Python 中的 Spark SQL 入门

洗牌 1

Python 中的 Spark SQL 入门

随机洗牌 2

Python 中的 Spark SQL 入门

歌曲

Python 中的 Spark SQL 入门

视频

Python 中的 Spark SQL 入门

选择数据

df_true = df.where("endword in ('she', 'he', 'hers', 'his', 'her', 'him')")\
            .withColumn('label', lit(1))

df_false = df.where("endword not in ('she', 'he', 'hers', 'his', 'her', 'him')")\
           .withColumn('label', lit(0))
Python 中的 Spark SQL 入门

合并正负样本

df_examples = df_true.union(df_false)
Python 中的 Spark SQL 入门

划分训练集与评估集

df_train, df_eval = df_examples.randomSplit((0.60, 0.40), 42)
Python 中的 Spark SQL 入门

训练

from pyspark.ml.classification import LogisticRegression

logistic = LogisticRegression(maxIter=50, regParam=0.6, elasticNetParam=0.3)
model = logistic.fit(df_train)
print("Training iterations: ", model.summary.totalIterations)
Python 中的 Spark SQL 入门

Vamos praticar!

Python 中的 Spark SQL 入门

Preparing Video For Download...