Phân loại văn bản

Nhập môn Spark SQL bằng Python

Mark Plutowski

Data Scientist

Dự đoán từ cuối

Nhập môn Spark SQL bằng Python

Mũi tên chuỗi

Nhập môn Spark SQL bằng Python

Từ cuối

Nhập môn Spark SQL bằng Python

Ngoặc từ cuối

Nhập môn Spark SQL bằng Python

Xáo trộn 1

Nhập môn Spark SQL bằng Python

Xáo trộn 2

Nhập môn Spark SQL bằng Python

Bài hát

Nhập môn Spark SQL bằng Python

Video

Nhập môn Spark SQL bằng Python

Chọn dữ liệu

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))
Nhập môn Spark SQL bằng Python

Kết hợp dữ liệu dương và âm

df_examples = df_true.union(df_false)
Nhập môn Spark SQL bằng Python

Chia dữ liệu thành tập huấn luyện và đánh giá

df_train, df_eval = df_examples.randomSplit((0.60, 0.40), 42)
Nhập môn Spark SQL bằng Python

Huấn luyện

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)
Nhập môn Spark SQL bằng Python

Hãy thực hành!

Nhập môn Spark SQL bằng Python

Preparing Video For Download...