Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Challenge: Customer Segmentation | Section
Machine Learning with PySpark
Sectie 1. Hoofdstuk 9
single

single

Challenge: Customer Segmentation

Veeg om het menu te tonen

Taak

Veeg om te beginnen met coderen

You are given a flights dataset as a list of rows. Load it into a DataFrame using createDataFrame and segment airlines by their operational profile using K-Means clustering. Complete all steps and store results in the specified variables:

  1. Fill nulls in Delay and Length with 0;
  2. Aggregate by Airline to compute:
    • AVG_DELAY – average Delay;
    • AVG_LENGTH – average Length;
    • TOTAL_FLIGHTS – count of flights. Store the result in airline_df;
  3. Build a Pipeline with VectorAssembler on ["AVG_DELAY", "AVG_LENGTH", "TOTAL_FLIGHTS"] and KMeans with k=3, seed=42, maxIter=5 – no scaling needed;
  4. Fit the pipeline and transform airline_df – store the result in clustered_df;
  5. Store the number of rows per cluster as a list of tuples [(cluster_id, count), ...] sorted by cluster_id in cluster_counts.

Print cluster_counts and show clustered_df sorted by prediction.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 9
single

single

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

some-alt