
<SYSTEM_TASK:>
Given the following text problem statement, write Python code to implement the functionality described below in problem statement
<END_TASK>
<USER_TASK:>
Problem:
Feature Engineering para XGBoost

<ASSISTANT_TASK:>
Python Code::
important_values = values.merge(labels, on="building_id")
important_values.drop(columns=["building_id"], inplace = True)
important_values["geo_level_1_id"] = important_values["geo_level_1_id"].astype("category")
important_values
X_train, X_test, y_train, y_test = train_test_split(important_values.drop(columns = 'damage_grade'), important_values['damage_grade'], test_size = 0.2, random_state = 123)
#OneHotEncoding
def encode_and_bind(original_dataframe, feature_to_encode):
	dummies = pd.get_dummies(original_dataframe[[feature_to_encode]])
    res = pd.concat([original_dataframe, dummies], axis=1)
    res = res.drop([feature_to_encode], axis=1)
    return(res) 
features_to_encode = ["geo_level_1_id", "land_surface_condition", "foundation_type", "roof_type","position", "ground_floor_type", "other_floor_type","plan_configuration", "legal_ownership_status"]
for feature in features_to_encode:
    X_train = encode_and_bind(X_train, feature)
    X_test = encode_and_bind(X_test, feature)
X_train
import time
def my_grid_search():
    print(time.gmtime())
    i = 1
    df = pd.DataFrame({'subsample': [],'gamma': [],'learning_rate': [],'max_depth': [],'score': []})
    for subsample in [0.75, 0.885, 0.95]:
        for gamma in [0.75, 1, 1.25]:
            for learning_rate in [0.4375, 0.45, 0.4625]:
                 for max_depth in [5, 6, 7]:
                    model = XGBClassifier(n_estimators = 350,booster = 'gbtree',subsample = subsample,gamma = gamma,max_depth = max_depth,learning_rate = learning_rate,label_encoder = False,verbosity = 0)
                    model.fit(X_train, y_train)
                    y_preds = model.predict(X_test)
                    score = f1_score(y_test, y_preds, average = 'micro')
					df = df.append(pd.Series(data={'subsample': subsample,'gamma': gamma,'learning_rate': learning_rate,'max_depth': max_depth,'score': score},name = i))
                    print(i, time.gmtime())
                    i += 1
    return df.sort_values('score', ascending = False)
current_df = my_grid_search()
df = pd.read_csv('grid-search/res-feature-engineering.csv')
df.append(current_df)
df.to_csv('grid-search/res-feature-engineering.csv')

<END_TASK>
