Implement Classification and Time Series Analysis in Tensorflow (2)
Implement Classification and Time Series Analysis in Tensorflow (2)
analysis in TensorFlow
OBJECTIVE
• To classify air quality levels based on sensor data using machine learning
models.
LET’S EXPLORE
• Time series forecasting is used to predict future values based on past data
trends.
Page | 1
5. Scikit-learn - Machine learning library in Python for classification,
regression, clustering, and model evaluation.
Datasets:
This command reads the CSV file named city_day.csv from the specified path
(/content/) and loads its contents into a Pandas DataFrame (df). This allows for
structured data analysis, manipulation, and processing using Pandas functions.
Page | 2
Step 2: Preprocess Data
The following code converts categorical labels in the 'AQI_Bucket' column into
numerical values using LabelEncoder, which is useful for machine learning models
that require numeric inputs.
The dataset is split into training and testing sets for model evaluation.
Splits the dataset into training (70%) and testing (30%) sets for both features (X) and
target (Y) using train_test_split().
Page | 3
Step 5: Train Model
A Support Vector Machine (SVM) classifier is trained using the processed dataset.
Imports the Support Vector Classifier (SVC), initializes the model, trains it on X_train
and Y_train, and evaluates its accuracy on X_test and Y_test.
The trained model is tested, and accuracy and classification metrics are displayed.
Predicts air quality using the trained SVM model and converts the encoded result back
to its original category using label_encoder.inverse_transform().
Page | 4
• matplotlib.pyplot is used for visualization.
• Groups the dataset by date and calculates the average temperature per day.
• Renames columns:
• 'ds' → Date column (required by Prophet).
• 'y' → Temperature values for prediction.
Page | 5
Step 6: Create Future Dates for Forecasting
Page | 6
• Plots historical and forecasted temperature trends.
Conclusion
This project applies machine learning for temperature forecasting and air quality
classification using historical data. Time series forecasting helps predict temperature
trends, benefiting weather prediction and energy management.
Page | 7