Use label encoding for categorical attributes
This commit is contained in:
parent
127e13d370
commit
96b888e2de
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue