Kaggle competition: Northeastern SMILE Lab - Recognizing Faces in the Wild
class TargetEncoding(BaseEstimator, TransformerMixin):
def __init__(self, columns_names):
self.columns_names = columns_names
self.learned_values = {}
self.dataset_mean = np.nan
def fit(self, X, y, **fit_params):
X_ = X.copy()
self.learned_values = {}
X_["__target__"] = y
for c in [x for x in X_.columns if x in self.columns_names]:
self.learned_values[c] =(X_[[c,"__target__"]] 
.groupby(c)["__target__"].mean() 
.reset_index())
 self.dataset_mean = np.mean(y)
 return self
def transform(self, X, **fit_params):
transformed_X = X[self.columns_names].copy()
for c in transformed_X.columns:
transformed_X[c] =(transformed_X[[c]] 
.merge(self.learned_values[c], on = c, how = 'left')
)["__target__"]
transformed_X = transformed_X.fillna(self.dataset_mean)
 return transformed_X
def fit_transform(self, X, y, **fit_params):
self.fit(X,y)
 return self.transform(X )<find_best_model_class>
sub1 = pd.read_csv('.. /input/faceinthewild/vgg_face_88.csv')
 sub2 = pd.read_csv('.. /input/faceinthewild/vgg_face_90.csv')
 sub3 = pd.read_csv('.. /input/faceinthewild/vgg_face_891.csv')
 sub4 = pd.read_csv('.. /input/facesinrheworld/vgg_face_85.csv')
 sub5 = pd.read_csv('.. /input/facesinrheworld/vgg_face_v122.csv')
 sub6 = pd.read_csv('.. /input/facesinrheworld/vgg_face_v14.csv')
 sub7 = pd.read_csv('.. /input/facesinrheworld/vgg_face_v19.csv')
 temp= pd.read_csv('.. /input/faceinthewild/vgg_face_891.csv' )
<categorify><EOS> 
temp['is_related'] = 0.5*sub1['is_related'] + 0.125*sub2['is_related'] + 0.125*sub3['is_related'] + 0.15*sub4['is_related'] + 0.1*sub5['is_related'] + 0.1*sub6['is_related'] + 0.1*sub7['is_related']
temp.to_csv('submission4.csv', index=False )