-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatapreprocessing.py
More file actions
49 lines (39 loc) · 1.9 KB
/
datapreprocessing.py
File metadata and controls
49 lines (39 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import pandas as pd
def preprocess(df_in):
df = df_in.copy()
# Native Country (Rassistisch?)
# Gender (sexismus)
# Race (Rassistisch!)
# Relationship (Husband, Wife einfach zu Married?)
# Educational-num oder education weg, je nach dem ob one hot encoding oder nicht
drop_this = ["institute","education","race","gender","native-country", "fnlwgt"]
df = df.drop(drop_this, axis = 1)
df.loc[df["relationship"].isin(["Husband", "Wife"]), "relationship"] = "Married"
df = pd.get_dummies(df, columns=["workclass", "marital-status", "occupation", "relationship"])
return df
def preprocess_no_removes(df_in):
df = df_in.copy()
drop_this = ["fnlwgt"]
df = df.drop(drop_this, axis = 1)
df.loc[df["relationship"].isin(["Husband", "Wife"]), "relationship"] = "Married"
df = pd.get_dummies(df, columns=["workclass", "marital-status", "occupation", "relationship", "institute","education","race","gender","native-country"])
return df
#daniel
# def split_data(df):
# # Drop "race" and "gender" columns
# df_processed = df.drop(['race', 'gender'], axis=1)
# # Encode categorical variables
# label_encoders = {}
# for column in df_processed.select_dtypes(include=['object']).columns:
# label_encoders[column] = LabelEncoder()
# df_processed[column] = label_encoders[column].fit_transform(df_processed[column])
# # Split data into features and target variable
# X = df_processed.drop('income', axis=1)
# y = df_processed['income']
# # Split data into training and testing sets
# X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# # Scale features using MinMaxScaler
# scaler = MinMaxScaler()
# X_train_scaled = scaler.fit_transform(X_train)
# X_test_scaled = scaler.transform(X_test)
# return X_train_scaled, X_test_scaled, y_train, y_test