Beispiel #1
0
def calculate_distance(y, y_pred):
    distance = distance75(y, y_pred)
    return np.mean(distance)
Beispiel #2
0
best_params = param_search.best_params_

# %% Training the model with full data and optimized hyperparameters

knn_model = KNeighborsRegressor(**best_params)
knn_model.fit(X, y)

pred = knn_model.predict(X_valid)

pred_lon = pred[:, 0]
pred_lat = pred[:, 1]
pred_floor = np.round(pred[:, 2], decimals=0)
pred_building = np.round(pred[:, 3], decimals=0)

distance = distance75(y_valid, pred)
score = np.mean(distance)
lon_score = np.mean(np.absolute(pred_lon - y_valid.lon))
lat_score = np.mean(np.absolute(pred_lat - y_valid.lat))
right_floor = np.round(np.mean(pred_floor == y_valid.floor) * 100, 2)
right_building = np.round(np.mean(pred_building == y_valid.building) * 100, 2)

predictions = pd.DataFrame({
    "LATITUDE": pred_lat,
    "LONGITUDE": pred_lon,
    "FLOOR": pred_floor,
    "distance": distance,
})

true_values = pd.DataFrame({
    "LATITUDE": y_valid.lat,