Use label encoding for categorical attributes

This commit is contained in:
coolneng 2020-11-09 13:21:38 +01:00
parent 127e13d370
commit 96b888e2de
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 8 additions and 4 deletions

View File

@ -16,11 +16,15 @@ def process_na(df, action):
def encode_columns(df): def encode_columns(df):
encoder = LabelEncoder() label_encoder = LabelEncoder()
encoder.fit(df["Shape"]) encoded_df = df.copy()
encoded_df["Shape"] = label_encoder.fit_transform(df["Shape"])
encoded_df["Severity"] = label_encoder.fit_transform(df["Severity"])
return encoded_df
def parse_data(source, action): def parse_data(source, action):
df = read_csv(filepath_or_buffer=source, na_values="?") df = read_csv(filepath_or_buffer=source, na_values="?")
processed_df = process_na(df, action) processed_df = process_na(df=df, action=action)
return processed_df encoded_df = encode_columns(df=processed_df)
return encoded_df