Classification de texte

Introduction à Spark SQL en Python

Mark Plutowski

Data Scientist

Prédiction du dernier mot

Introduction à Spark SQL en Python

Flèche de séquence

Introduction à Spark SQL en Python

Dernier mot

Introduction à Spark SQL en Python

Crochet du dernier mot

Introduction à Spark SQL en Python

Mélange 1

Introduction à Spark SQL en Python

Mélange 2

Introduction à Spark SQL en Python

Chansons

Introduction à Spark SQL en Python

Vidéos

Introduction à Spark SQL en Python

Sélection des données

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))
Introduction à Spark SQL en Python

Combiner les données positives et négatives

df_examples = df_true.union(df_false)
Introduction à Spark SQL en Python

Fractionner en ensembles d'entraînement et d'évaluation

df_train, df_eval = df_examples.randomSplit((0.60, 0.40), 42)
Introduction à Spark SQL en Python

Entraînement

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)
Introduction à Spark SQL en Python

Passons à la pratique !

Introduction à Spark SQL en Python

Preparing Video For Download...