File size: 582 Bytes
0a0b0ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pandas as pd

def predict(data, model, prep):
    df = pd.DataFrame([data])

    # Handle country
    top_country = ['PRT', 'GBR', 'FRA', 'ESP', 'DEU', 'ITA', 'IRL', 'BEL', 'BRA', 'NLD']
    df['country'] = df['country'].apply(lambda x: x if x in top_country else 'Other')

    # Fix missing columns
    if 'agent' not in df.columns:
        df['agent'] = 0

    if 'company' not in df.columns:
        df['company'] = 0

    # Transform
    df_processed = prep.transform(df)

    # Predict
    result = model.predict(df_processed)

    return result[0]