Classificazione del testo

Introduzione a Spark SQL in Python

Mark Plutowski

Data Scientist

Predizione dell'ultima parola

Introduzione a Spark SQL in Python

Freccia di sequenza

Introduzione a Spark SQL in Python

Ultima parola

Introduzione a Spark SQL in Python

Parentesi ultima parola

Introduzione a Spark SQL in Python

Mescola 1

Introduzione a Spark SQL in Python

Mescola 2

Introduzione a Spark SQL in Python

Canzoni

Introduzione a Spark SQL in Python

Video

Introduzione a Spark SQL in Python

Selezionare i dati

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))
Introduzione a Spark SQL in Python

Unire dati positivi e negativi

df_examples = df_true.union(df_false)
Introduzione a Spark SQL in Python

Suddividere in training ed evaluation

df_train, df_eval = df_examples.randomSplit((0.60, 0.40), 42)
Introduzione a Spark SQL in Python

Training

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)
Introduzione a Spark SQL in Python

Ayo berlatih!

Introduzione a Spark SQL in Python

Preparing Video For Download...