Skip to content

Instantly share code, notes, and snippets.

@petersen-poul
Last active May 12, 2016 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petersen-poul/d2fe25aac70cab11dec5cca21e490a10 to your computer and use it in GitHub Desktop.
Save petersen-poul/d2fe25aac70cab11dec5cca21e490a10 to your computer and use it in GitHub Desktop.
{
"name": "Redfin Deals",
"description": "Given a source of sold homes and listed homes, builds a model to predict the price and then shows possible deals.",
"inputs": [
{
"name": "redfin-sold-source",
"type": "source-id",
"description": "Source of sold homes from Redfin."
},
{
"name": "redfin-forsale-source",
"type": "source-id",
"description": "Source of houses currently forsale."
}
],
"outputs": [
{
"name": "redfin-deals-dataset",
"type": "dataset-id",
"description": "The ID of the Redfin deals dataset"
}
]
}
(define (redfin-dataset source-id fields)
(let (
dataset (create-and-wait-dataset {
"source" source-id
"input_fields" fields} ))
dataset))
(define (colA-colB dataset-id colA colB)
(create-and-wait-dataset {
"origin_dataset" dataset-id
"new_fields" [ {
"name" (str colA " - " colB)
"field" (flatline "( - ( field {{colA}} ) ( field {{colB}} ))") }]}))
(define (redfin-deals sold-src forsale-src)
(let (
default-fields [
"ADDRESS"
"BEDS"
"BATHS"
"LOCATION"
"SQFT"
"LOT SIZE"
"YEAR BUILT"
"PARKING SPOTS"
"PARKING TYPE"
"LATITUDE"
"LONGITUDE" ]
forsale-field "LIST PRICE"
sold-field "LAST SALE PRICE"
predicted-field "PREDICTED PRICE"
forsale-dataset (redfin-dataset forsale-src (append default-fields forsale-field))
sold-dataset (redfin-dataset sold-src (append default-fields sold-field))
sold-model (create-and-wait-model {
"dataset" sold-dataset
"objective_field" sold-field })
sold-batchp (create-and-wait-batchprediction {
"model" sold-model
"dataset" forsale-dataset
"all_fields" true
"prediction_name" predicted-field
"output_dataset" true})
batchp-dataset (get (fetch sold-batchp) "output_dataset_resource"))
(colA-colB (wait-forever batchp-dataset) forsale-field predicted-field)))
(define redfin-deals-dataset (redfin-deals redfin-sold-source redfin-forsale-source))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment