<jupyter_start><jupyter_text>AirBnb Price Project DescriptionCreate a function for generating a prediction, a function that geocodes a string and a function that makes a plotly mapbox interactable plot<jupyter_code># Import required packages
import pandas as pd
import numpy as np
import tensorflow as tf
import requests
import re
import geopy

print(f'Numpy Version: {np.__version__}')
print(f'Tensorflow Version: {tf.__version__}')
print(f'Pandas Version: {pd.__version__}')
print(f'Requests Version: {requests.__version__}')
print(f'Geopy Version: {geopy.__version__}')<jupyter_output>Numpy Version: 1.19.5
Tensorflow Version: 2.5.0
Pandas Version: 1.1.5
Requests Version: 2.25.1
geopy Version: 2.1.0<jupyter_text>Load Final Model<jupyter_code>model = tf.keras.models.load_model('../models/nn_model')<jupyter_output><empty_output><jupyter_text>API Prototype `get_prediction` Function<jupyter_code># Can also add helper functions
# def clean_text(input_text):
#    return cleaned_text

def get_prediction(sample_input):
    """One line summary of this function.

    Args:
        param1: This is the first param.
        param2: This is a second param.

    Returns:
        This is a description of what is returned.
    """
    sample_input = pd.DataFrame(sample_input, index=[0])
    prediction = model.predict(sample_input)
    
    return {
        'price': prediction[0][0]
    }
# Test function with sample input
sample_input = {'latitude':40.75356, 'longitude':-73.98559, 'room_type':2, 'minimum_nights':5, 'availability_365':265, 'beds':4}
get_prediction(sample_input)
def encode_dict(input_dict):
    encoded_dict = {'Shared room': 3, 'Entire home/apt': 2, 'Private room': 1, 'Hotel room': 4}
    if input_dict['room_type'] == 'Shared room':
        input_dict['room_type'] = encoded_dict['Shared room']
    if input_dict['room_type'] == 'Entire home/apt':
        input_dict['room_type'] = encoded_dict['Entire home/apt']
    if input_dict['room_type'] == 'Private room':
        input_dict['room_type'] = encoded_dict['Private room']
    if input_dict['room_type'] == 'Hotel room':
        input_dict['room_type'] = encoded_dict['Hotel room']
    return input_dict
encode_dict({'room_type':'Shared room'})<jupyter_output><empty_output><jupyter_text>Geocoding address for api<jupyter_code>def geocode_address(string):
    string = re.sub(".", "", string)
    string = re.sub(", ", ",", string)
    address = re.sub(" ", "+", string)

    geoencoder = geopy.geocoders.OpenMapQuest(api_key=key)
    address = geoencoder.geocode(address)

    query = requests.get('http://open.mapquestapi.com/geocoding/v1/address?key='+key+'&location='+str(address))
    json_response = query.json()

    return {
        'latitude': json_response['results'][0]['locations'][0]['latLng']['lat'],
        'longitude': json_response['results'][0]['locations'][0]['latLng']['lng']
    }
geocode_address('100 W 40th St, New York, NY 10018')<jupyter_output><empty_output><jupyter_text>Plotly Graph<jupyter_code>def visualize(dictionary):
    nn = load('models/nn_model/knn_api.pkl')
    nearby_query = nn.kneighbors([[dictionary['latitude'], dictionary['longitude']]])
    vis_data = pd.read_csv('data/clean/latlng_prices.csv').drop(['Unnamed: 0'], axis=1)
    df = pd.DataFrame([vis_data.iloc[num] for num in nearby_query[1][0]])
    px.set_mapbox_access_token(key)
    fig = px.scatter_mapbox(df, lat='latitude', lon='longitude', color='price', color_continuous_scale='agsunset',
                            size_max=15, zoom=12)
    fig.write_html('api/templates/viz.html')
    return fig.to_json()
visualize({'latitude':40.75356, 'longitude':-73.98559})<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14549904813706827, 'fraction_numerical': 0.023388632036986674, 'mean_word_length': 5.029508196721311, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '351434', 'license': 'MIT', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1250, 'n_words': 254, 'path': 'notebooks/02_API_Prototype.ipynb', 'repo_name': 'mariokart345/air-bnb-solo', 'size': '3677'}