-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
blockchain_integration/pi_network/PiPulse/ai/models/preprocessing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import pandas as pd | ||
import numpy as np | ||
from sklearn.preprocessing import MinMaxScaler | ||
|
||
def preprocess_data(data): | ||
# Handle missing values | ||
data.fillna(data.mean(), inplace=True) | ||
|
||
# Scale data using Min-Max Scaler | ||
scaler = MinMaxScaler() | ||
data[['cpu_usage', 'memory_usage', 'disk_usage']] = scaler.fit_transform(data[['cpu_usage', 'memory_usage', 'disk_usage']]) | ||
|
||
# Extract features and labels | ||
features = data.drop(['label'], axis=1) | ||
labels = data['label'] | ||
|
||
return features, labels | ||
|
||
def split_data(features, labels, test_size=0.2): | ||
from sklearn.model_selection import train_test_split | ||
X_train, X_test, y_train, y_test = train_test_split(features, labels, test_size=test_size, random_state=42) | ||
return X_train, X_test, y_train, y_test |