Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Customer Segmentation | Section
Machine Learning with PySpark
Seksjon 1. Kapittel 9
single

single

Challenge: Customer Segmentation

Sveip for å vise menyen

Oppgave

Sveip for å begynne å kode

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.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 9
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

some-alt