0% found this document useful (0 votes)
3 views2 pages

Tested AI Models

The document outlines the process of testing AI models, specifically using Random Forests for prediction. It includes steps for importing necessary libraries, reading and preparing data from a CSV file, feature engineering to extract time-based features, and creating lag features for better model learning. Additionally, it describes a function for training and evaluating the model based on the processed data.

Uploaded by

anas
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Tested AI Models

The document outlines the process of testing AI models, specifically using Random Forests for prediction. It includes steps for importing necessary libraries, reading and preparing data from a CSV file, feature engineering to extract time-based features, and creating lag features for better model learning. Additionally, it describes a function for training and evaluating the model based on the processed data.

Uploaded by

anas
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Tested AI Models:

[Link] Forests:

1.1. Importing Libraries:

import pandas as pd (Handles reading and processing the CSV file)

import numpy as np(Used for mathematical operations)

from [Link] import StandardScaler(Normalizes feature values to improve model


performance)

from sklearn.model_selection import train_test_split(Splits data into training and test sets)

from [Link] import RandomForestRegressor(Machine learning model used for prediction)

from [Link] import mean_squared_error, mean_absolute_error, r2_score(Used to evaluate


model accuracy)

import [Link] as plt(Used to visualize predictions vs. actual values)

1.2. Reading and Preparing Data:

df = pd.read_csv('vm_metrics.csv'): Reads the CSV file (vm_metrics.csv) into a pandas DataFrame


(df).

df['Timestamp'] = pd.to_datetime(df['Timestamp'], unit='s'): Converts the 'Timestamp' column


into a datetime format for time-based feature extraction

1.3. Feature Engineering:

. Extracts time-based features from the Timestamp column:

def create_features(data):

data['hour'] = data['Timestamp'].[Link]

data['day'] = data['Timestamp'].[Link]

data['month'] = data['Timestamp'].[Link]

data['dayofweek'] = data['Timestamp'].[Link]

1.4. Creating Lag Features(previous measurements):

data['lag_1'] = data['Value'].shift(1)

data['lag_2'] = data['Value'].shift(2)

data['rolling_mean'] = data['Value'].rolling(window=3).mean()

return [Link]()

lag_1 and lag_2 → Stores the previous values to help the model learn from past trends.

rolling_mean → Computes the average value over the last 3 records to smooth out fluctuations.

dropna() → Removes rows with NaN values (caused by lagging)


1.5. Training and Evaluating the Model:

def train_evaluate_model(df_metric, metric_name):

df_processed = create_features(df_metric)

You might also like