grkavi0912 commited on
Commit
8c40309
·
verified ·
1 Parent(s): 84b06c1

Upload training and testing datasets

Browse files
__pycache__/data_preparation.cpython-312.pyc ADDED
Binary file (1.93 kB). View file
 
data_preparation.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import os
3
+ from sklearn.model_selection import train_test_split
4
+
5
+ def prepare_data(input_csv_path='engine2/data/engine.csv', output_dir='engine/data'):
6
+ # 1. Load the dataset
7
+ df = pd.read_csv(input_csv_path)
8
+
9
+ # 2. Define column renaming mapping
10
+ column_name_mapping = {
11
+ 'Engine rpm': 'engine_rpm',
12
+ 'Lub oil pressure': 'lub_oil_pressure',
13
+ 'Fuel pressure': 'fuel_pressure',
14
+ 'Coolant pressure': 'coolant_pressure',
15
+ 'lub oil temp': 'lub_oil_temp',
16
+ 'Coolant temp': 'coolant_temp',
17
+ 'Engine Condition': 'engine_condition'
18
+ }
19
+
20
+ # 3. Rename columns
21
+ df.rename(columns=column_name_mapping, inplace=True)
22
+
23
+ # 4. Separate features (X) and target (y)
24
+ X = df.drop('engine_condition', axis=1)
25
+ y = df['engine_condition']
26
+
27
+ # 5. Split data into training and testing sets with stratification
28
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)
29
+
30
+ # 6. Create output directory if it doesn't exist
31
+ os.makedirs(output_dir, exist_ok=True)
32
+
33
+ # 7. Save prepared datasets
34
+ X_train.to_csv(os.path.join(output_dir, 'X_train.csv'), index=False)
35
+ X_test.to_csv(os.path.join(output_dir, 'X_test.csv'), index=False)
36
+ y_train.to_csv(os.path.join(output_dir, 'y_train.csv'), index=False)
37
+ y_test.to_csv(os.path.join(output_dir, 'y_test.csv'), index=False)
38
+
39
+ print(f"Data preparation complete. Saved files to {output_dir}")
40
+
41
+ # Example usage (can be called from another script or notebook)
42
+ # if __name__ == '__main__':
43
+ # prepare_data()