Here is an dummy tool template that you can use to prototype your tool. This tool template assumes that each row of your training dataset corresponds to an address.
Note that this tool uses a dummy model. Please modify the inputs, outputs and model to fit your chosen hypothesis and training dataset.
Thanks to the following groups for making this work possible:
{address_table : Addresses ? Specify the addresses for which you would like to predict metrics}
# CrossCompute
address_table_path = 'address.csv'
target_folder = '/tmp'
import pandas as pd
address_table = pd.read_csv(address_table_path)
address_table[:3]
# Load model
from pickle import load
model = load(open('dummy-model.pkl', 'rb')) # !!! Replace dummy model with your model
model
# Run model
X = address_table[['Tree Count Within 100 Meters', 'Sum of Distances to Each Tree Within 100 Meters']].values
y = model.predict(X)
y
# Add column
address_table['Predicted Graduation Rate'] = y
address_table
# Save file to target folder to include it in the result download
target_path = target_folder + '/a.csv'
address_table.to_csv(target_path, index=False)
print(f'a_table_path = {target_path}') # Print table_path to render table
address_geotable = address_table.copy() # Prevent SettingwithCopyWarning
# Geocode address locations
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_geotable = address_geotable.apply(get_longitude_latitude, axis=1)
address_geotable[:3]
# Set radius for each point
address_geotable['RadiusInPixelsRange10-20'] = address_geotable['Tree Count Within 100 Meters']
# Set color for each point using a gradient
# address_geotable['FillReds'] = address_geotable['Predicted Graduation Rate']
# Set color for each point using a rule
address_geotable['FillColor'] = address_geotable.apply(
lambda row: 'r' if row['Predicted Graduation Rate'] < 50 else 'g',
axis=1)
# See what we did
address_geotable[:3]
# Save file to target folder to include it in the result download
target_path = target_folder + '/b.csv'
address_geotable.to_csv(target_path, index=False)
print(f'b_geotable_path = {target_path}') # Print geotable_path to render map
%matplotlib inline
axes = address_table[[
'Tree Count Within 100 Meters',
'Predicted Graduation Rate',
]].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}')
YOUR INTERPRETATION OF THE RESULTS
{a_table : YOUR TABLE NAME ? YOUR TABLE DESCRIPTION}
{b_geotable : YOUR MAP NAME ? YOUR MAP DESCRIPTION}
{c_image : YOUR PLOT NAME ? YOUR PLOT DESCRIPTION}