KaiquanMah commited on
Commit
d8bbbd8
·
verified ·
1 Parent(s): 93b4792

Update DSIP/preprocess.py

Browse files
Files changed (1) hide show
  1. DSIP/preprocess.py +40 -1
DSIP/preprocess.py CHANGED
@@ -1,7 +1,43 @@
1
  import argparse
 
 
 
 
 
2
 
3
  def parse(csv_path):
4
  print(f"Location of the file: {csv_path}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
 
7
  if __name__ == '__main__':
@@ -10,4 +46,7 @@ if __name__ == '__main__':
10
 
11
 
12
  args = parser.parse_args()
13
- parse(args.csv_path)
 
 
 
 
1
  import argparse
2
+ import pandas as pd
3
+ from sklearn.model_selection import train_test_split
4
+ import os
5
+
6
+
7
 
8
  def parse(csv_path):
9
  print(f"Location of the file: {csv_path}")
10
+
11
+ # Step 1: Load the dataset
12
+ # file_path = "dataset.csv" # Path to the original dataset
13
+ data = pd.read_csv(csv_path)
14
+
15
+ # Step 2: Define the feature columns (X) and target column (y)
16
+ X = data[["name", "attendance percentage", "average sleep time", "average screen time"]] # Feature columns
17
+ y = data["grade"] # Target column
18
+
19
+ # Step 3: Split the dataset into training and testing sets
20
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
21
+
22
+ # Step 4: Combine X and y back into dataframes for train and test
23
+ train_data = pd.concat([X_train, y_train], axis=1) # Combine features and target for training data
24
+ test_data = pd.concat([X_test, y_test], axis=1) # Combine features and target for testing data
25
+
26
+ # Step 5: Create the 'data' folder if it doesn't exist
27
+ output_folder = "data"
28
+ os.makedirs(output_folder, exist_ok=True)
29
+
30
+ # Step 6: Save the train and test sets as CSV files
31
+ train_file_path = os.path.join(output_folder, "train.csv")
32
+ test_file_path = os.path.join(output_folder, "test.csv")
33
+
34
+ train_data.to_csv(train_file_path, index=False)
35
+ test_data.to_csv(test_file_path, index=False)
36
+
37
+ print(f"Train and test datasets saved in '{output_folder}' folder.")
38
+
39
+
40
+
41
 
42
 
43
  if __name__ == '__main__':
 
46
 
47
 
48
  args = parser.parse_args()
49
+ parse(args.csv_path)
50
+
51
+
52
+