This article shows how to build a haze prediction model by analyzing a year's worth of real air quality data from Beijing. This model helps identify the pollutants that have the greatest impact on PM 2.5 levels, the primary indicator of haze.
Dataset
This experiment uses hourly air quality data for Beijing from 2016. The following table describes the fields in the dataset.
|
Parameter |
Type |
Description |
|
time |
STRING |
The date, accurate to the day. |
|
hour |
STRING |
The hour the data was recorded. |
|
pm2 |
STRING |
The PM 2.5 index. |
|
pm10 |
STRING |
The PM 10 index. |
|
so2 |
STRING |
The sulfur dioxide (SO2) index. |
|
co |
STRING |
The carbon monoxide (CO) index. |
|
no2 |
STRING |
The nitrogen dioxide (NO2) index. |
Procedure
-
Go to the Machine Learning Designer page.
-
Log on to the PAI console.
-
In the left-side navigation pane, click Workspaces. On the Workspaces page, click the name of the workspace that you want to manage.
-
In the left-side navigation pane, choose .
-
-
Build the pipeline.
On the Designer page, click the Preset Templates tab.
-
In the Haze Prediction section, click Create.
In the Create Pipeline dialog box, configure the parameters. You can use the default settings.
The Data Storage parameter specifies the OSS Bucket path for storing temporary data and models generated during the pipeline run.
Click Confirm.
Creating the pipeline takes about 10 seconds.
-
In the pipeline list, double-click the Haze Prediction pipeline to open it on the canvas.
-
The system automatically builds the pipeline based on the preset template, as shown in the following figure.

Section
Description
①
Data import and preprocessing:
-
The Read Data Table component imports the data source.
-
The Type Transform component converts data from the STRING type to the DOUBLE type.
-
The SQL Script component converts the label column into binary values of 0 and 1. In this experiment, the pm2 column is the label column. A value greater than 200 indicates heavy haze and is set to 1; otherwise, the value is set to 0. The SQL statement is as follows:
select time,hour,(case when pm2>200 then 1 else 0 end),pm10,so2,co,no2 from ${t1}; -
The Normalization component removes the units of measurement to standardize the scale of different pollutant indicators.
②
Statistical analysis:
-
The Histogram component visualizes the distribution of each pollutant.
For example, the most frequent interval for PM 2.5 is 11.74 to 15.61, which occurred 430 times, as shown in the following figure.

-
The Data View component visualizes how different value ranges for each pollutant affect the outcome.
For example, for no2, the interval from 112.33 to 113.9 contains 7 records with a label value of 0 and 9 records with a label value of 1, as shown in the following figure. This indicates that heavy haze is more likely when no2 falls within this range. Entropy and Gini measure the information gain from this feature interval. A larger value indicates a greater impact on the label.

③
Model training and prediction. This pipeline uses the Random Forest and Logistic Regression components to train models.
④
Model evaluation.
-
-
Run the pipeline and view the model performance.
-
Click the Run button
above the canvas. -
When the pipeline finishes, right-click the Evaluation for Binary Classification component downstream of the Random Forest component on the canvas, and then select Visual Analysis.
-
In the Evaluation for Binary Classification dialog box, click the Evaluation Charts tab to view the prediction performance of the model trained by the Random Forest component.
The Area Under the Curve (AUC) value indicates that the haze prediction model trained by the Random Forest component achieves an accuracy of over 99%. -
Right-click the Evaluation for Binary Classification component downstream of the Logistic Regression component on the canvas, and select Visual Analysis.
-
In the Evaluation for Binary Classification dialog box, click the Evaluation Charts tab to view the prediction performance of the model trained by the Logistic Regression component.
The AUC value shows that the haze prediction model trained by the Logistic Regression component has an accuracy of over 98%.
-