<jupyter_start><jupyter_text>Find missing values<jupyter_code>n = len(data)

for c in data.columns:
    
    cnt = data[c].count()
    
    if (cnt < 614):
        print( f"{c}: {data[c].count()},  {data[c].dtype}" )<jupyter_output>Gender: 601,  object
Married: 611,  object
Dependents: 599,  object
Self_Employed: 582,  object
LoanAmount: 592,  float64
Loan_Amount_Term: 600,  float64
Credit_History: 564,  float64<jupyter_text>Convert categorical values to integers<jupyter_code>catColumns = [ "Gender", "Married", "Dependents", "Education", "Self_Employed", "Property_Area", "Loan_Status" ] 

for c in catColumns:
    data[c] = data[c].astype('category')

data[ catColumns ] = data[ catColumns ].apply( lambda x: x.cat.codes )<jupyter_output><empty_output><jupyter_text>Fill Nans<jupyter_code>data["Dependents"] = data["Dependents"].fillna( 1 )
data["LoanAmount"] = data["LoanAmount"].fillna( data.LoanAmount.mean() )
data["Loan_Amount_Term"] = data["Loan_Amount_Term"].fillna( data.Loan_Amount_Term.mean() )
data["Credit_History"] = data["Credit_History"].fillna( data.Credit_History.mean() )
data.corr()<jupyter_output><empty_output><jupyter_text>Extract features and targets<jupyter_code>features = data[ [ "Gender", "Married", "Dependents", "Education", "Self_Employed", "ApplicantIncome", "CoapplicantIncome", "LoanAmount", "Loan_Amount_Term","Credit_History", "Property_Area"] ]
targets = data["Loan_Status"]
params = { "n_estimators" : [2, 3, 4, 5, 6, 7, 8, 9, 10 ,12, 16, 18, 20, 30 ],
           "max_depth" : [None, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20 ,30 ],
           "min_samples_leaf" : [1, 2, 4, 5, 10 ,15, 20] }

forest = RandomForestClassifier()

gridForest = GridSearchCV( forest, params, cv = 10, n_jobs = -1 )
gridForest.fit( features, targets)
gridForest.best_score_
gridForest.best_params_
model = RandomForestClassifier( **gridForest.best_params_ )
model.fit( features, targets )
pred = model.predict( features )
accuracy_score(pred, targets)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15881763527054107, 'fraction_numerical': 0.039579158316633264, 'mean_word_length': 5.934027777777778, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 16, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '428765', 'license': 'MIT', 'n_tokens_mistral': 825, 'n_tokens_neox': 737, 'n_words': 157, 'path': 'loanData/LoanData.ipynb', 'repo_name': 'm0baxter/dataProjects', 'size': '1996'}