文字分類

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 入門

一起來練習吧!

Python Spark SQL 入門

Preparing Video For Download...