<jupyter_start><jupyter_text>correlation matrixcorrmat = train_df.corr()f, ax = plt.subplots(figsize=(20, 9))sns.heatmap(corrmat, vmax=.8, annot=True);  most correlated featurescorrmat = train_df.corr()top_corr_features = corrmat.index[abs(corrmat["Criminal"])>0.5]plt.figure(figsize=(10,10))g = sns.heatmap(train_df[top_corr_features].corr(),annot=True,cmap="RdYlGn") from scipy import statsfrom scipy.stats import norm, skew for some statisticssns.distplot(train_df['Criminal'] , fit=norm); Get the fitted parameters used by the function(mu, sigma) = norm.fit(train_df['Criminal'])print( '\n mu = {:.2f} and sigma = {:.2f}\n'.format(mu, sigma))plt.legend(['Normal dist. ($\mu=$ {:.2f} and $\sigma=$ {:.2f} )'.format(mu, sigma)],            loc='best')plt.ylabel('Frequency')plt.title('Criminal')fig = plt.figure()res = stats.probplot(train_df['Criminal'], plot=plt)plt.show()<jupyter_code>print("Find most important features relative to target")
corr = train_df.corr()
corr.sort_values(["Criminal"], ascending = False, inplace = True)
print(corr.Criminal)
#this you can see at the time of heatmap also.
print("Before", train_df.shape, test_df.shape, combine[0].shape, combine[1].shape)
train_df = train_df.drop(["IRHH65_2","HLTINNOS","IROTHHLT","IIPRVHLT"], axis=1)
test_df = test_df.drop(["IRHH65_2","HLTINNOS","IROTHHLT","IIPRVHLT"], axis=1)
print (type(train_df))
print("Before", train_df.shape, test_df.shape, combine[0].shape, combine[1].shape)
print(train_df.columns.values)
train_df = train_df.drop("PERID", axis=1)
X_train = train_df.drop("Criminal", axis=1)
Y_train = train_df["Criminal"]
X_test  = test_df.drop("PERID", axis=1).copy()


from sklearn.ensemble import RandomForestClassifier
from sklearn.tree import DecisionTreeClassifier
from pandas import Series,DataFrame
import random as rnd
logreg = LogisticRegression()
logreg.fit(X_train, Y_train)
Y_pred = logreg.predict(X_test)
acc_log = round(logreg.score(X_train, Y_train) * 100, 2)
print(acc_log)<jupyter_output>93.01<jupyter_text>svc = SVC()svc.fit(X_train, Y_train)Y_pred = svc.predict(X_test)acc_svc = round(svc.score(X_train, Y_train) * 100, 2)acc_svc<jupyter_code>knn = KNeighborsClassifier(n_neighbors = 3)
knn.fit(X_train, Y_train)
Y_pred = knn.predict(X_test)
acc_knn = round(knn.score(X_train, Y_train) * 100, 2)
acc_knn
gaussian = GaussianNB()
gaussian.fit(X_train, Y_train)
Y_pred = gaussian.predict(X_test)
acc_gaussian = round(gaussian.score(X_train, Y_train) * 100, 2)
acc_gaussian
perceptron = Perceptron()
perceptron.fit(X_train, Y_train)
Y_pred = perceptron.predict(X_test)
acc_perceptron = round(perceptron.score(X_train, Y_train) * 100, 2)
acc_perceptron
# Linear SVC

linear_svc = LinearSVC()
linear_svc.fit(X_train, Y_train)
Y_pred = linear_svc.predict(X_test)
acc_linear_svc = round(linear_svc.score(X_train, Y_train) * 100, 2)
acc_linear_svc
# Stochastic Gradient Descent

sgd = SGDClassifier()
sgd.fit(X_train, Y_train)
Y_pred = sgd.predict(X_test)
acc_sgd = round(sgd.score(X_train, Y_train) * 100, 2)
acc_sgd
# Decision Tree
decision_tree = DecisionTreeClassifier()
decision_tree.fit(X_train, Y_train)
Y_pred = decision_tree.predict(X_test)
acc_decision_tree = round(decision_tree.score(X_train, Y_train) * 100, 2)
acc_decision_tree
# Random Forest

random_forest = RandomForestClassifier(n_estimators=100)
random_forest.fit(X_train, Y_train)
Y_pred = random_forest.predict(X_test)
random_forest.score(X_train, Y_train)
acc_random_forest = round(random_forest.score(X_train, Y_train) * 100, 2)
acc_random_forest
#Ensemble all models using voting classifier
from sklearn.ensemble import VotingClassifier
votingC = VotingClassifier(estimators=[('rfc', model_2),('dct',model_1),('adb',model_3),('grb',model_4)], voting='soft', n_jobs=4)
votingC.fit(X_train,y_train)
y_pred5=votingC.predict(X_test)
import pandas as pd
submission1 = pd.DataFrame({
        "PERID": test_df["PERID"],
        "Criminal": Y_pred
    })
submission1.to_csv('sample_submission9knn.csv', index=False,  columns = ["PERID","Criminal"])
models = pd.DataFrame({
    'Model': [ 'KNN', 'Logistic Regression', 
              'Random Forest', 'Naive Bayes', 'Perceptron', 
              'Stochastic Gradient Decent', 'Linear SVC', 
              'Decision Tree'],
    'Score': [ acc_knn, acc_log, 
              acc_random_forest, acc_gaussian, acc_perceptron, 
              acc_sgd, acc_linear_svc, acc_decision_tree]})
models.sort_values(by='Score', ascending=False)
submission = pd.DataFrame({
        "PERID": test_df["PERID"],
        "Criminal": Y_pred
    })
# submission.to_csv('../output/submission.csv', index=False)
submission.to_csv('sample_submission4.csv', index=False,  columns = ["PERID","Criminal"])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14670912951167728, 'fraction_numerical': 0.01762208067940552, 'mean_word_length': 6.549679487179487, 'pattern_counts': {'":': 4, '<': 8, '<?xml version=': 0, '>': 9, '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': '386608', 'license': 'MIT', 'n_tokens_mistral': 1921, 'n_tokens_neox': 1776, 'n_words': 311, 'path': '4_test.ipynb', 'repo_name': 'sanjeevcares4u/Predict-The-Criminal-Hackerearth', 'size': '4710'}