<jupyter_start><jupyter_text>Random Forest<jupyter_code>rf_model = RandomForestClassifier(n_estimators=1000, max_features=2, oob_score=True)
features = ['Age', 'BusinessTravel', 'Department', 'DistanceFromHome',
       'Education', 'EducationField', 'Gender', 'JobLevel', 'JobRole',
       'MaritalStatus', 'MonthlyIncome', 'NumCompaniesWorked',
       'PercentSalaryHike', 'StockOptionLevel', 'TotalWorkingYears',
       'TrainingTimesLastYear', 'YearsAtCompany', 'YearsSinceLastPromotion',
       'YearsWithCurrManager']
rf_model.fit(X=df3[features], y = df3['Attrition'])
print('OOB Accuracy:')
print(rf_model.oob_score_)
for feature, imp in zip(features, rf_model.feature_importances_):
    print(feature, imp)<jupyter_output>Age 0.09822861529750367
BusinessTravel 0.027851909179650827
Department 0.025861680224511487
DistanceFromHome 0.06920109716389829
Education 0.04061308140624962
EducationField 0.04130090361777618
Gender 0.018527266864806945
JobLevel 0.038102683592929246
JobRole 0.05489561999497393
MaritalStatus 0.03970809423278251
MonthlyIncome 0.09297091170254097
NumCompaniesWorked 0.05553422789570587
PercentSalaryHike 0.06541077321146957
StockOptionLevel 0.03386076266138414
TotalWorkingYears 0.08725888141051351
TrainingTimesLastYear 0.04453865881296472
YearsAtCompany 0.06916755992875943
YearsSinceLastPromotion 0.04324572454866928
YearsWithCurrManager 0.05372154825290976<jupyter_text>Now taking DV - Attrition and IDV - Age, Monthly Income, Total Working Years   Decision Tree<jupyter_code>tree_model = tree.DecisionTreeClassifier(max_depth=6, max_leaf_nodes=12)
pred = pd.DataFrame([df3['Age'], df3['MonthlyIncome'], df3['TotalWorkingYears']]).T
tree_model.fit(X = pred, y = df3['Attrition'])
with open ('DtreeATT.dot', 'w') as f:
    f = tree.export_graphviz(tree_model, feature_names=['Age', 'MonthlyIncome', 'TotalWorkingYears'], out_file=f);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10595677385345283, 'fraction_numerical': 0.18977332630469163, 'mean_word_length': 8.683673469387756, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '545485', 'license': 'MIT', 'n_tokens_mistral': 930, 'n_tokens_neox': 684, 'n_words': 111, 'path': 'DAY-24/Attrition/Attrition.ipynb', 'repo_name': 'BhuvaneshHingal/LetsUpgrade-AI-ML', 'size': '1897'}