text_html_output_1.png
def encode_cat(Xtrain, Xtest):
    model_age = Xtrain.groupby(['model'])['age'].agg('mean')
    brand_age = Xtrain.groupby(['brand'])['age'].agg('mean')
    Xtest['model_age'] = Xtest['model'].map(model_age)
    Xtrain['model_age'] = Xtrain['model'].map(model_age)
    Xtest['brand_age'] = Xtest['brand'].map(brand_age)
    Xtrain['brand_age'] = Xtrain['brand'].map(brand_age)
    return (Xtrain[['brand', 'model', 'old_model']], Xtest[['brand', 'model', 'old_model']])