<jupyter_start><jupyter_text>**no_of_trainings**<jupyter_code>print(input_train_data["no_of_trainings"].unique())
plt.figure(figsize=(25,10))
plt.subplot(2, 3, 1)
sns.distplot(input_train_data["no_of_trainings"])
plt.subplot(2, 3, 2)
sns.barplot(input_train_data["no_of_trainings"], target)
input_train_data["no_of_trainings_promoted"] = input_train_data["no_of_trainings"].apply(lambda x: 0 if x in [7, 8, 9, 10] else 1)
input_test_data["no_of_trainings_promoted"] = input_test_data["no_of_trainings"].apply(lambda x: 0 if x in [7, 8, 9, 10] else 1)
input_train_data["kpi_awards_trainingScore_promoted"] = input_train_data["no_of_trainings"].apply(lambda x: 0 if x in [7, 8, 9, 10] else 1)
input_test_data["no_of_trainings_promoted"] = input_test_data["no_of_trainings"].apply(lambda x: 0 if x in [7, 8, 9, 10] else 1)<jupyter_output><empty_output><jupyter_text>**age**<jupyter_code>plt.figure(figsize=(25, 10))
plt.subplot(2, 3, 1)
sns.distplot(input_train_data["age"])
plt.subplot(2, 3, 2)
sns.boxplot(input_train_data["age"])
plt.subplot(2, 3, 3)
sns.barplot(input_train_data["age"], target)
# input_train_data["age"] = input_train_data["age"].apply(lambda x: 54 if x>54 else x)    # Outlier
# input_test_data["by ghage"] = input_test_data["age"].apply(lambda x: 54 if x>54 else x)
#grouping age into categories
def age_wrangler(row):
    if row['age'] >= 20 and row['age'] <= 25:
        return '20-25'
    elif row['age']  >= 26 and row['age'] <= 30:
        return '26-30'
    elif row['age'] >= 31 and row['age'] <= 35:
        return '31-35'
    elif row['age'] >= 36 and row['age'] <= 40:
        return '36-40'
    elif row['age'] >= 41 and row['age'] <= 45:
        return '41-45'
    elif row['age'] >= 46 and row['age'] <= 50:
        return '46-50'
    elif row['age'] >= 51 and row['age'] <= 55:
        return '51-55'
    elif row['age'] >= 56 and row['age'] <= 60:
        return '56-60'
    
input_train_data['age_cat'] = input_train_data.apply(lambda row: age_wrangler(row), axis=1)
input_test_data['age_cat'] = input_test_data.apply(lambda row: age_wrangler(row), axis=1)

input_train_data.groupby(['age_cat'])['age_cat'].count()
log = np.log(input_train_data["age"])
sqrt = np.power(input_train_data["age"], 1/2)
cube = np.power(input_train_data["age"], 1/3)
plt.figure(figsize=(25, 10))
plt.subplot(2, 3, 1)
sns.distplot(log, label="Log")
plt.legend(loc="best")
plt.subplot(2, 3, 2)
sns.distplot(sqrt, label="Sqrt")
plt.legend(loc="best")
plt.subplot(2, 3, 3)
sns.boxplot(log)

input_train_data["age_log"] = np.log(input_train_data["age"])
input_test_data["age_log"] = np.log(input_test_data["age"])<jupyter_output><empty_output><jupyter_text>**length_of_service**<jupyter_code>plt.figure(figsize=(25, 10))
plt.subplot(2, 3, 1)
sns.distplot(input_train_data["length_of_service"])
plt.subplot(2, 3, 2)
sns.boxplot(input_train_data["length_of_service"])
plt.subplot(2, 3, 3)
sns.barplot(input_train_data["length_of_service"], target)
log = np.log(input_train_data["length_of_service"])
sqrt = np.power(input_train_data["length_of_service"], 1/2)
cube = np.power(input_train_data["length_of_service"], 1/3)
plt.figure(figsize=(25, 10))
plt.subplot(2, 3, 1)
sns.distplot(log, label="Log")
plt.legend(loc="best")
plt.subplot(2, 3, 2)
sns.distplot(sqrt, label="Sqrt")
plt.legend(loc="best")
plt.subplot(2, 3, 3)
sns.boxplot(cube)
input_train_data['length_of_service_log'] = np.log(input_train_data['length_of_service'])
input_test_data['length_of_service_log'] = np.log(input_test_data['length_of_service'])
# #grouping length_of_service into categories
# def length_of_service_wrangler(row):
#     if row['length_of_service'] >= 1 and row['length_of_service'] <= 5:
#         return '1-5'
#     elif row['length_of_service']  >= 6 and row['length_of_service'] <= 10:
#         return '6-10'
#     elif row['length_of_service'] >= 11 and row['length_of_service'] <= 15:
#         return '11-15'
#     elif row['length_of_service'] >= 16 and row['length_of_service'] <= 20:
#         return '16-20'
#     elif row['length_of_service'] >= 21 and row['length_of_service'] <= 25:
#         return '21-25'
#     elif row['length_of_service'] >= 26 and row['length_of_service'] <= 30:
#         return '26-30'
#     elif row['length_of_service'] >= 31: 
#         return 'Above30'

# input_train_data['length_of_service'] = input_train_data.apply(lambda row: length_of_service_wrangler(row), axis=1)
# input_test_data['length_of_service'] = input_test_data.apply(lambda row: length_of_service_wrangler(row), axis=1)

# input_train_data.groupby(['length_of_service'])['length_of_service'].count()<jupyter_output><empty_output><jupyter_text>**diff_age_service**<jupyter_code>input_train_data['diff_age_service'] = (input_train_data['age'] - input_train_data['length_of_service'])/input_train_data['age']
input_test_data['diff_age_service'] = (input_test_data['age'] - input_test_data['length_of_service'])/input_test_data['age']
log = np.log(input_train_data["length_of_service"])
sqrt = np.power(input_train_data["length_of_service"], 1/2)
plt.figure(figsize=(25, 10))
plt.subplot(2, 3, 1)
sns.distplot(log, label="Log")
plt.legend(loc="best")
plt.subplot(2, 3, 2)
sns.distplot(sqrt, label="Sqrt")
plt.legend(loc="best")
plt.subplot(2, 3, 3)
sns.distplot(input_train_data["length_of_service"])<jupyter_output><empty_output><jupyter_text>**KPIs_met >80%**<jupyter_code>plt.figure(figsize=(25, 10))
plt.subplot(2, 3, 1)
sns.distplot(input_train_data["KPIs_met >80%"])
plt.subplot(2, 3, 2)
sns.barplot(input_train_data["KPIs_met >80%"], target)<jupyter_output><empty_output><jupyter_text>**awards_won?**<jupyter_code>plt.figure(figsize=(25, 10))
plt.subplot(2, 3, 1)
sns.distplot(input_train_data["awards_won?"])
plt.subplot(2, 3, 2)
sns.barplot(input_train_data["awards_won?"], target)<jupyter_output><empty_output><jupyter_text>**avg_training_score**<jupyter_code>plt.figure(figsize=(25, 10))
plt.subplot(2, 3, 1)
sns.distplot(input_train_data["avg_training_score"])
plt.subplot(2, 3, 2)
sns.boxplot(input_train_data["avg_training_score"])
plt.subplot(2, 3, 3)
g = sns.barplot(input_train_data["avg_training_score"], target)
g.set_xticklabels(g.get_xticklabels(), rotation=90)<jupyter_output><empty_output><jupyter_text>avg_training_score >=90 have great chances of promotion<jupyter_code>log = np.log(input_train_data["avg_training_score"])
sqrt = np.power(input_train_data["avg_training_score"], 1/2)
cube = np.power(input_train_data["avg_training_score"], 1/3)
plt.figure(figsize=(25, 10))
plt.subplot(2, 3, 1)
sns.distplot(log, label="Log")
plt.legend(loc="best")
plt.subplot(2, 3, 2)
sns.distplot(sqrt, label="Sqrt")
plt.legend(loc="best")
plt.subplot(2, 3, 3)
sns.distplot(cube, label="Cube")
plt.legend(loc="best")
input_train_data["avg_training_score_promoted"] = input_train_data["avg_training_score"].apply(lambda x: 1 if x>=90 else 0)
input_test_data["avg_training_score_promoted"] = input_test_data["avg_training_score"].apply(lambda x: 1 if x>=90 else 0)

input_train_data["avg_training_score_log"] = np.log(input_train_data["avg_training_score"])
input_test_data["avg_training_score_log"] = np.log(input_test_data["avg_training_score"])<jupyter_output><empty_output><jupyter_text>department<jupyter_code>plt.figure(figsize=(25,10))
plt.subplot(2, 3, 1)
input_train_data["department"].value_counts().plot('bar')
plt.subplot(2, 3, 2)
sns.barplot(input_train_data["department"], target)<jupyter_output><empty_output><jupyter_text>region<jupyter_code>plt.figure(figsize=(25,10))
plt.subplot(2, 3, 1)
input_train_data["region"].value_counts().plot('bar')
plt.subplot(2, 3, 2)
temp = input_train_data["region"].apply(lambda x: int(x.split('_')[1]))
g = sns.barplot(temp.sort_values(), target)
g.set_xticklabels(g.get_xticklabels(), rotation=90)
pd.crosstab(input_train_data["region"], target).apply(lambda r: r/r.sum(), axis=1)[1].sort_values()<jupyter_output><empty_output><jupyter_text>Region are categoried as per region number. Try doing by promotion %<jupyter_code>#grouping regions into categories
def region_wrangler(row):
    if row['region'] >= 1 and row['region'] <= 10:
        return '1to10'
    elif row['region'] >= 11 and row['region'] <= 20:
        return '11to20'
    elif row['region'] >= 21 and row['region'] <= 30:
        return '21to30'
    elif row['region'] >= 31 and row['region'] <= 40:
        return '31to40'
    
    
#cleaning region's names and storing only numbers 
input_train_data['region']=input_train_data['region'].str.split("_").str[1].astype('int64')
input_test_data['region']=input_test_data['region'].str.split("_").str[1].astype('int64')

input_train_data['region'] = input_train_data.apply(lambda row: region_wrangler(row), axis=1)
input_test_data['region'] = input_test_data.apply(lambda row: region_wrangler(row), axis=1)

input_train_data.groupby(['region'])['region'].count()<jupyter_output><empty_output><jupyter_text>**education**<jupyter_code>plt.figure(figsize=(25,10))
plt.subplot(2, 3, 1)
input_train_data["education"].value_counts().plot('bar')
plt.subplot(2, 3, 2)
sns.barplot(input_train_data["education"], target)<jupyter_output><empty_output><jupyter_text>**gender**<jupyter_code>plt.figure(figsize=(25,10))
plt.subplot(2, 3, 1)
input_train_data["gender"].value_counts().plot('bar')
plt.subplot(2, 3, 2)
sns.barplot(input_train_data["gender"], target)<jupyter_output><empty_output><jupyter_text>**recruitment_channel**<jupyter_code>plt.figure(figsize=(25,10))
plt.subplot(2, 3, 1)
input_train_data["recruitment_channel"].value_counts().plot('bar')
plt.subplot(2, 3, 2)
sns.barplot(input_train_data["recruitment_channel"], target)
input_train_data.head()
input_train_data.drop(["age", "length_of_service"], axis=1, inplace=True)
input_test_data.drop(["age", "length_of_service"], axis=1, inplace=True)
train = pd.get_dummies(input_train_data)
test = pd.get_dummies(input_test_data)
print(train.shape)
print(test.shape)
train.info()
from sklearn.metrics import f1_score
from sklearn.grid_search import GridSearchCV
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
import xgboost as xgb
X_train, X_test, y_train, y_test = train_test_split(train, target, test_size=0.33, random_state=42)
clf = xgb.XGBClassifier( n_estimators=600, eta=0.01, learning_rate=0.05, max_depth=8, min_samples_leaf=75, reg_lambda=10 ,scale_pos_weight = 1, n_jobs=-1, random_state=42)
clf.fit(X_train, y_train)
pred = clf.predict(X_test)
f1_score(y_test, pred)<jupyter_output><empty_output><jupyter_text>last : 5146 GB n_estimators=600, eta=0.01, learning_rate=0.05, max_depth=8, min_samples_leaf=75, reg_lambda=10 ,scale_pos_weight = 1, n_jobs=-1, random_state=42<jupyter_code>clf = xgb.XGBClassifier(n_estimators=600, eta=0.01, learning_rate=0.05, max_depth=8, min_samples_leaf=75, reg_lambda=10 ,scale_pos_weight = 1, n_jobs=-1)
clf.fit(train, target)
pred = clf.predict(test)
#GradientBoosting Classifier

from sklearn.ensemble import GradientBoostingClassifier


def GradientBoostingClassifier_model(X_train, X_test, y_train, y_test):
    if __name__ == '__main__':
        
        
        gb = GradientBoostingClassifier()
        
        parameters = {'learning_rate': [0.01],
                      'max_depth': [5],
                      'min_samples_leaf': [16],
                      'max_features': [1.0],
                      'n_estimators': [200]}
        
        estimator = GridSearchCV(gb,n_jobs=-1,param_grid=parameters)
        
        estimator.fit(X_train, y_train)
        
        prediction_test_gb=estimator.predict(X_test)
        prediction_train_gb=estimator.predict(X_train)
        
        best_params = estimator.best_params_
                                 
        validation_accuracy_test = f1_score(y_test, prediction_test_gb)
        validation_accuracy_train = f1_score(y_train, prediction_train_gb)
        
        print('Validation accuracy_test: ', validation_accuracy_test)
        print('Validation accuracy_train: ', validation_accuracy_train)
        print(best_params)
GradientBoostingClassifier_model(X_train, X_test, y_train, y_test)
#GradientBoosting Classifier

from sklearn.ensemble import GradientBoostingClassifier
        
        
gb = GradientBoostingClassifier()

parameters = {'learning_rate': [0.1],
              'max_depth': [5],
              'min_samples_leaf': [16],
              'max_features': [1.0],
              'n_estimators': [200]}

estimator = GridSearchCV(gb,n_jobs=-1,param_grid=parameters)

estimator.fit(train, target)

prediction_test_gb=estimator.predict(test)
print(prediction_test_gb.shape)
submission["is_promoted"].shape
submission["is_promoted"]=prediction_test_gb
submission.to_csv("wns_submission.csv", index=False)
#from google.colab import files
#files.download("wns_submission.csv")
submission.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1598597038191738, 'fraction_numerical': 0.03787996882307093, 'mean_word_length': 6.416763005780346, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 88, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '529574', 'license': 'MIT', 'n_tokens_mistral': 5282, 'n_tokens_neox': 4866, 'n_words': 740, 'path': 'Employee promotion Prediction.ipynb', 'repo_name': 'kaustav1987/Employee-promotion-Prediction', 'size': '12830'}