<jupyter_start><jupyter_text>Load Dataset<jupyter_code>df = pd.read_csv('https://raw.githubusercontent.com/pplonski/datasets-for-start/master/adult/data.csv', skipinitialspace=True)

x_cols = [c for c in df.columns if c != 'income']

# set input matrix and target column
X = df[x_cols]
y = df['income']

# show first rows data
df.head()
# data split train / test
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state=1234)<jupyter_output><empty_output><jupyter_text>Data preprocessing<jupyter_code># Fill missing values
train_mode  = dict(X_train.mode().iloc[0])
X_train = X_train.fillna(train_mode)
print(train_mode)
# convert categoricals
encoders = {}
columns = ['workclass', 'education', 'marital-status', 'occupation', 'relationship', 'race', 'sex','native-country']
for column in columns:
    categorical_convert = LabelEncoder()
    X_train[column] = categorical_convert.fit_transform(X_train[column])
    encoders[column] = categorical_convert<jupyter_output><empty_output><jupyter_text>Algorithm training<jupyter_code># train the Random Forest algorithm
rf = RandomForestClassifier(n_estimators = 100)
rf = rf.fit(X_train, y_train)
# train the Extra Trees algorithm
et = ExtraTreesClassifier(n_estimators = 100)
et = et.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Save preprocessing objects and RF algorithm<jupyter_code>joblib.dump(train_mode, "./train_mode.joblib", compress=True)
joblib.dump(encoders, "./encoders.joblib", compress=True)
joblib.dump(rf, "./random_forest.joblib", compress=True)
joblib.dump(et, "./extra_trees.joblib", compress=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13183475091130012, 'fraction_numerical': 0.007897934386391251, 'mean_word_length': 7.489690721649485, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '408483', 'license': 'MIT', 'n_tokens_mistral': 604, 'n_tokens_neox': 581, 'n_words': 110, 'path': 'research/Untitled1.ipynb', 'repo_name': 'alcibiadesBustillo/ml_service', 'size': '1646'}