Textklassificering

Introduktion till Spark SQL i Python

Mark Plutowski

Data Scientist

Förutsägelse av slutord

Introduktion till Spark SQL i Python

Sekvens med pil

Introduktion till Spark SQL i Python

Slutord

Introduktion till Spark SQL i Python

Slutord med hakparentes

Introduktion till Spark SQL i Python

Blandning 1

Introduktion till Spark SQL i Python

Blandning 2

Introduktion till Spark SQL i Python

Låtar

Introduktion till Spark SQL i Python

Videor

Introduktion till Spark SQL i Python

Välja ut data

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))
Introduktion till Spark SQL i Python

Kombinera positiv och negativ data

df_examples = df_true.union(df_false)
Introduktion till Spark SQL i Python

Dela upp data i tränings- och utvärderingsmängd

df_train, df_eval = df_examples.randomSplit((0.60, 0.40), 42)
Introduktion till Spark SQL i Python

Träning

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)
Introduktion till Spark SQL i Python

Nu kör vi en övning!

Introduktion till Spark SQL i Python

Preparing Video For Download...