I create a function which return a score and print a message concern a result . Here the code :
def compute_score(X_cv, clf):
score = clf.predict_proba(X_cv[84582].reshape(1,-1))[0][1] # Prob of a Win
df_top10_feat = pd.DataFrame(data={"Feature":df_cv.columns[:-1],
"Coefficient":clf.coef_[0],
"Value":X_cv[84582],
"Importance":list(clf.coef_ * X_cv[84582])[0]}). \
sort_values("Importance",
ascending=False)
##extract positif importance
df_top10_feat_positif= df_top10_feat[df_top10_feat['Importance']>0]
#extract negatif importance
df_top10_feat_negatif= df_top10_feat[df_top10_feat['Importance']<0]
#print
print("The average of ", df_top10_pos_sort['Feature'].iloc[0], "is", format(df_cv[df_top10_pos_sort['Feature'].iloc[1]].mean(), '.3f'),". The", df_top10_pos_sort['Feature'].iloc[0], "for this opportunity line is", format(df_top10_pos_sort['Value'].iloc[0], '.3f'), "Therefore, the", df_top10_pos_sort['Feature'].iloc[0], "is lower than other similar opportunity lines.")
print("The average of", df_top10_pos_sort['Feature'].iloc[1], "is", format(df_cv[df_top10_pos_sort['Feature'].iloc[1]].mean(), '.3f'),". The ",df_top10_pos_sort['Feature'].iloc[1], "for this opportunity line is", format(df_top10_pos_sort['Value'].iloc[1], '.3f'), "Therefore, the", df_top10_pos_sort['Feature'].iloc[1], " is lower than other similar opportunity lines.")
print("The average of", df_top10_pos_sort['Feature'].iloc[2], "is", format(df_cv[df_top10_pos_sort['Feature'].iloc[2]].mean(), '.3f'),". The", df_top10_pos_sort['Feature'].iloc[1], "for this opportunity line is", format(df_top10_pos_sort['Value'].iloc[2], '.3f'), "Therefore, the", df_top10_pos_sort['Feature'].iloc[2], "is lower than other similar opportunity lines.")
print("The average of", df_top10_neg_sort['Feature'].iloc[0], "is", format(df_cv[df_top10_neg_sort['Feature'].iloc[0]].mean(), '.3f'), ". The",df_top10_neg_sort['Feature'].iloc[0], "for this opportunity line is", format(df_top10_neg_sort['Value'].iloc[0], '.3f'), "Therefore,", df_top10_neg_sort['Feature'].iloc[0], "is lower than other similar opportunity lines.")
print("The average of", df_top10_neg_sort['Feature'].iloc[1], "is", format(df_cv[df_top10_neg_sort['Feature'].iloc[1]].mean(), '.3f'),". The", df_top10_neg_sort['Feature'].iloc[1], "for this opportunity line is", format(df_top10_neg_sort['Value'].iloc[1], '.3f'), "Therefore,", df_top10_neg_sort['Feature'].iloc[1], "is lower than other similar opportunity lines.")
print("The average of", df_top10_neg_sort['Feature'].iloc[2],"is", format(df_cv[df_top10_neg_sort['Feature'].iloc[2]].mean(), '.3f'),". The", df_top10_neg_sort['Feature'].iloc[2], "for this opportunity line is", format(df_top10_neg_sort['Value'].iloc[2], '.3f'), "Therefore,", df_top10_neg_sort['Feature'].iloc[2], "is lower than other similar opportunity lines.")
return
My question is should I add an assumption in the "return " bloc? Or I keep it like this?
Thanks