Create src/data_processing.py
Browse files- src/data_processing.py +22 -0
src/data_processing.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
from sklearn.model_selection import train_test_split
|
3 |
+
|
4 |
+
def load_data(file_path):
|
5 |
+
"""Load data from a CSV file."""
|
6 |
+
return pd.read_csv(file_path)
|
7 |
+
|
8 |
+
def clean_data(df):
|
9 |
+
"""Clean the dataset by handling missing values and duplicates."""
|
10 |
+
df = df.dropna()
|
11 |
+
df = df.drop_duplicates()
|
12 |
+
return df
|
13 |
+
|
14 |
+
def preprocess_data(df, target_column):
|
15 |
+
"""Preprocess the data by splitting into features and target."""
|
16 |
+
X = df.drop(columns=[target_column])
|
17 |
+
y = df[target_column]
|
18 |
+
return X, y
|
19 |
+
|
20 |
+
def split_data(X, y, test_size=0.2, random_state=42):
|
21 |
+
"""Split the data into training and testing sets."""
|
22 |
+
return train_test_split(X, y, test_size=test_size, random_state=random_state)
|