ECSP




Pay Notebook Creator: Haige Cui0
Set Container: Numerical CPU with TINY Memory for 10 Minutes 0
Total0
In [2]:
# CrossCompute
address_table_path = 'address.csv'
search_radius_in_miles = 0.5
industry_select = """
Manufacturing

Manufacturing
Wholesale/Warehouse/Distribution
Commercial
Landlord
Public Benefit Corp
Other

"""
program_select = """
ICIP

City/State
ICAP
ICIP
IDA
Relocator
Tenant

"""
target_folder = '/tmp'
In [3]:
# Load inputs
import pandas as pd
address_table = pd.read_csv(address_table_path)
industry = industry_select.strip().splitlines()[0]
program = program_select.strip().splitlines()[0]
In [4]:
# Get longitude and latitude for each address
from geopy import GoogleV3
geocode = GoogleV3('AIzaSyDNqc0tWzXHx_wIp1w75-XTcCk4BSphB5w').geocode

def get_longitude_latitude(row):
    location = geocode(row['Address'])
    row['Longitude'] = location.longitude
    row['Latitude'] = location.latitude
    return row

address_table = address_table.apply(get_longitude_latitude, axis=1)
address_table[:3]

# Prepare prediction dataset
prediction_table = address_table.copy()
In [5]:
# Prepare prediction dataset
prediction_table = address_table.copy()
# Add "Average Monthly Savings of Buildings Within 0.5 Mile Radius" column
prediction_table['Average Monthly Savings of Buildings Within 0.5 Mile Radius'] = [100, 200, 300]
# Add "Tree Count Within 0.5 Mile Radius"
prediction_table['Tree Count Within 0.5 Mile Radius'] = [10, 20, 30]
In [6]:
# # Load your model
# from pickle import load
# model = load(open('dummy-model.pkl', 'rb'))
# model

# # Run your model to add column "Monthly Savings"
prediction_table['Monthly Savings'] = [1, 2, 3]
In [7]:
 X = prediction_table[['Average Monthly Savings of Buildings Within 0.5 Mile Radius', 'Tree Count Within 0.5 Mile Radius']].values
## prediction_table['Monthly Savings'] = model.predict(X)
In [8]:
target_path = target_folder + '/savings.csv'
prediction_table.to_csv(target_path, index=False)
print(f'prediction_table_path = {target_path}')
prediction_table_path = /tmp/savings.csv
In [9]:
target_path = target_folder + '/savings-map.csv'
map_table = prediction_table.copy()
map_table['RadiusInPixelsRange3-30'] = map_table['Monthly Savings']
In [10]:
map_table['FillColor'] = ['y' if index in address_table else 'b' for index in map_table.index]
map_table.to_csv(target_path, index=False)
print(f'prediction_geotable_path = {target_path}')
prediction_geotable_path = /tmp/savings-map.csv
In [11]:
%matplotlib inline
axes = prediction_table[[
    'Monthly Savings',
]].plot(kind='bar')

# Save file to target folder to include it in the result download
target_path = target_folder + '/c.png'
figure = axes.get_figure()
figure.savefig(target_path)
print(f'c_image_path = {target_path}')
c_image_path = /tmp/c.png
In [ ]: