<jupyter_start><jupyter_text>Importing Data<jupyter_code>train = pd.read_csv('train_s3TEQDk.csv')
test = pd.read_csv('test_mSzZ8RL.csv')<jupyter_output><empty_output><jupyter_text>Cleaning Train Data<jupyter_code># checking training data headers
train.head()
# visualizing missing training data (if any)
sns.heatmap(train.isnull(),yticklabels=False,cbar=False,cmap='viridis')
# replacing 'YES', 'NO' values by '1' and '0' in training data and filling the missing values with mean
train = train.replace(('Yes','No'),(1,0))
train = train.fillna(train.mean())
sns.heatmap(train.isnull(),yticklabels=False,cbar=False,cmap='viridis')
train.head()
# converting categorical features to dummy variables using pandas
gender = pd.get_dummies(train['Gender'],drop_first=True)
RCode = pd.get_dummies(train['Region_Code'],drop_first=True)
Occ = pd.get_dummies(train['Occupation'],drop_first=True)
CCode = pd.get_dummies(train['Channel_Code'],drop_first=True)
# dropping redundant feature columns after encoding 
train.drop(['ID','Gender','Region_Code','Occupation','Channel_Code'],axis=1,inplace=True)
# concatenating dataframes
train = pd.concat([train,gender,RCode,Occ,CCode],axis=1)
train.head()<jupyter_output><empty_output><jupyter_text>Cleaning Test Data<jupyter_code># checking testing data headers
test.head()
# visualizing missing testing data (if any)
sns.heatmap(test.isnull(),yticklabels=False,cbar=False,cmap='viridis')
# replacing 'YES', 'NO' values by '1' and '0' in testing data and filling the missing values with mean
test = test.replace(('Yes','No'),(1,0))
test = test.fillna(test.mean())
sns.heatmap(test.isnull(),yticklabels=False,cbar=False,cmap='viridis')
test.head()
# converting categorical features to dummy variables using pandas
gender = pd.get_dummies(test['Gender'],drop_first=True)
RCode = pd.get_dummies(test['Region_Code'],drop_first=True)
Occ = pd.get_dummies(test['Occupation'],drop_first=True)
CCode = pd.get_dummies(test['Channel_Code'],drop_first=True)
# dropping redundant feature columns after encoding 
ID = test['ID']
test.drop(['ID','Gender','Region_Code','Occupation','Channel_Code'],axis=1,inplace=True)
# concatenating dataframes
test = pd.concat([test,gender,RCode,Occ,CCode],axis=1)
test.head()
print('Training Data Shape :',train.shape)
print('\nTesting Data Shape :',test.shape)
X_train = train.drop(['Is_Lead'], axis=1)
X_test = test
y_train = train['Is_Lead']
print('Training Data Shape :',X_train.shape)
print('\nTesting Data Shape :',X_test.shape)<jupyter_output>Training Data Shape : (245725, 46)

Testing Data Shape : (105312, 46)<jupyter_text>Building A XGBoost Model<jupyter_code># importing random forest classifier and creating an instance
import xgboost as xgb
xgb_cl = xgb.XGBClassifier(objective='binary:logistic', n_estimators=10, seed=123)
xgb_cl.fit(X_train, y_train)
xgb_pred = xgb_cl.predict_proba(X_test)
xgb_pred<jupyter_output><empty_output><jupyter_text>Saving Predictions to a csv file<jupyter_code>ID = pd.DataFrame(ID)
ID.columns =['ID']
Is_lead = pd.DataFrame(xgb_pred[:,1])
Is_lead.columns =['Is_Lead']
det = pd.concat([ID, Is_lead], join = 'outer', axis = 1)
det.to_csv("Submission5.csv", index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15050062578222778, 'fraction_numerical': 0.012202753441802253, 'mean_word_length': 9.279742765273312, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '54985', 'license': 'MIT', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1132, 'n_words': 216, 'path': 'JOB-A-THON - May 2021/Code XGBoost.ipynb', 'repo_name': 'Tonumoy/ML-Assignments', 'size': '3196'}