Prepare and Fit Spatial Regression Models 20190222

 Pay Notebook Creator: Roy Hyunjin Han 0 Set Container: Numerical CPU with TINY Memory for 10 Minutes 0 Total 0

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:

In [ ]:
# CrossCompute
target_folder = '/tmp'


In [ ]:
import pandas as pd


Run Model to Estimate Target Variable¶

In [ ]:
# Load model
model = load(open('dummy-model.pkl', 'rb'))  # !!! Replace dummy model with your model
model

In [ ]:
# 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

In [ ]:
# Add column


Render Table¶

In [ ]:
# Save file to target folder to include it in the result download
target_path = target_folder + '/a.csv'
print(f'a_table_path = {target_path}')  # Print table_path to render table


Render Map¶

In [ ]:
address_geotable = address_table.copy()  # Prevent SettingwithCopyWarning

In [ ]:
# Geocode address locations

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


In [ ]:
# Set radius for each point

In [ ]:
# Set color for each point using a gradient

In [ ]:
# Set color for each point using a rule
lambda row: 'r' if row['Predicted Graduation Rate'] < 50 else 'g',
axis=1)

In [ ]:
# See what we did

In [ ]:
# Save file to target folder to include it in the result download
target_path = target_folder + '/b.csv'
print(f'b_geotable_path = {target_path}')  # Print geotable_path to render map


Render Plot¶

In [ ]:
%matplotlib inline
'Tree Count Within 100 Meters',
]].plot(kind='bar')

In [ ]:
# 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}')