<jupyter_start><jupyter_text>Splitting<jupyter_code>cr_x = cr.iloc[:,0:-1]
cr_y = cr.iloc[:,-1]
cr.shape
cr_x1 = cr_x # just a back up would be used later on
cr_x.columns
# !pip install Boruta
cr_x = np.array(cr_x)
cr_y = np.array(cr_y)
from boruta import BorutaPy
import numpy as np
from sklearn.ensemble import RandomForestClassifier
rfc = RandomForestClassifier()
cr_x = np.array(cr_x)

boruta_feature_selector = BorutaPy(rfc, max_iter=25, verbose=2)
boruta_feature_selector.fit(cr_x, cr_y)<jupyter_output>Iteration: 	1 / 25
Confirmed: 	0
Tentative: 	11
Rejected: 	0
Iteration: 	2 / 25
Confirmed: 	0
Tentative: 	11
Rejected: 	0
Iteration: 	3 / 25
Confirmed: 	0
Tentative: 	11
Rejected: 	0
Iteration: 	4 / 25
Confirmed: 	0
Tentative: 	11
Rejected: 	0
Iteration: 	5 / 25
Confirmed: 	0
Tentative: 	11
Rejected: 	0
Iteration: 	6 / 25
Confirmed: 	0
Tentative: 	11
Rejected: 	0
Iteration: 	7 / 25
Confirmed: 	0
Tentative: 	11
Rejected: 	0
Iteration: 	8 / 25
Confirmed: 	2
Tentative: 	1
Rejected: 	8
Iteration: 	9 / 25
Confirmed: 	2
Tentative: 	1
Rejected: 	8
Iteration: 	10 / 25
Confirmed: 	2
Tentative: 	1
Rejected: 	8
Iteration: 	11 / 25
Confirmed: 	2
Tentative: 	1
Rejected: 	8
Iteration: 	12 / 25
Confirmed: 	2
Tentative: 	1
Rejected: 	8
Iteration: 	13 / 25
Confirmed: 	2
Tentative: 	1
Rejected: 	8
Iteration: 	14 / 25
Confirmed: 	2
Tentative: 	1
Rejected: 	8
Iteration: 	15 / 25
Confirmed: 	2
Tentative: 	1
Rejected: 	8
Iteration: 	16 / 25
Confirmed: 	2
Tentative: 	1
Rejected: 	8
Iteration: 	17 / 25
Confir[...]<jupyter_text>To know the name of Variables that are important.<jupyter_code>boruta_feature_selector.support_
type(cr_x)
cr_x1.columns
feat_importance = pd.DataFrame({'Importance':boruta_feature_selector.support_, 'Feature_Names':cr_x1.columns})

## cr_x1 is a copy of cr_x1 is in df format and cr_x is in array format
feat_importance.sort_values('Importance', ascending= False)<jupyter_output><empty_output><jupyter_text>RFE Recursive Feature Selection.<jupyter_code># Difference in RFE and Baruta is we get important Feature in both but in barouta we dont get which feature is the most important
# but in RFE by giving value we will the Most Important Feature in this case it is Applicant Income. 
import pandas as pd
cr = pd.read_csv('C:/Users/shubh/Pranjal Sir class/fwd/CreditRisk.csv')
cr = cr.iloc[:,1:13]
cr = cr.dropna()

cr.Gender.replace({"Male" :1 , "Female":0} ,inplace = True)
cr.Married.replace({"No" :0 , "Yes":1} , inplace = True)
cr.Education.replace({"Graduate" :1 , "Not Graduate":0} , inplace = True)
cr.Self_Employed.replace({"No":0 , "Yes" :1 }, inplace = True)
cr.Property_Area.replace({"Semiurban" :1 ,"Urban": 2 , "Rural" :3} , inplace = True)
cr.Loan_Status.replace({"Y" :1 , "N" : 0}, inplace = True)
from sklearn.feature_selection import RFE
from sklearn.tree import DecisionTreeClassifier
dt = DecisionTreeClassifier()
rfe = RFE(dt, 1)
rfe.fit(cr_x, cr_y)
rfe.support_
feat_importance_rfe = pd.DataFrame({'Importance':rfe.support_, 'Feature_Names':cr_x1.columns})
feat_importance_rfe.sort_values('Importance', ascending= False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11157691067397614, 'fraction_numerical': 0.046114156723637535, 'mean_word_length': 4.84180790960452, 'pattern_counts': {'":': 5, '<': 12, '<?xml version=': 0, '>': 12, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '563425', 'license': 'Apache-2.0', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1289, 'n_words': 340, 'path': 'Feature Engineering/Credit_risk_feature_selection.ipynb', 'repo_name': 'KrushnaJadhav99/Feature_Engineering', 'size': '3101'}