Predicting Home Prices from Realty Descriptions
My wife and I recently bought a lovely house in Sunnyvale, CA. The overall process went very smoothly (thanks to our realtor Patrick Johnson) which gave me some spare time to do a little data mining on the property market in Silicon Valley. There are so many interesting applications for analytics in the real estate domain that I will probably write another couple of articles on the subject, but for now I'll focus on a fun data visualization derived from text-mining home descriptions.
I will also add that I had the pleasure of meeting some of the team at Trulia.com earlier this year and they are the ones to watch when it comes to real-estate analytics. They've got great people, huge amounts of data and a robust business model. It will be exciting to see what they bring to market over the next year.
So, back to the data mining. If you have ever read an MLS listing describing a house for sale you will be familiar with language like this:
Classic streamlined California home w/ abundant built-ins, rich hardwood flooring & tall picture windows to the exterior gardens. Large Living Room w/ built in shelving & fireplace. Updated Kitchen w/ granite & stainless steel. Formal Dining w/ sliding door to dining deck & grounds. Fresh air sunroom w/ doors to pool and gardens. Fourishing grounds w/ level lawns. Close to Stanford, dining and shopping.
That certainly sounds attractive...it almost makes me want to pay over the asking price! In fact, that is exactly what I wanted to explore: does the language used in the home description have any statistical relationship with whether or not the home sells for above or below asking price?
The graphic below lets us explore this question in detail. It was produced by text mining the descriptions of 1300 homes that sold in Silicon Valley in 2011 and then computing the average sale price (as a percentage above or below the initial asking price) of each home containing that word. So for example, homes with the word "midtown" in their description sold for well above their asking price (about 4% on average). Words such as "gorgeous" and "bonus" did not fare so well; you may want to underbid on houses with those terms in their description!
Tip: You can hover over a circle with your mouse to see a pop-up with some sample text from the MLS listings.
Update November 29, 2011: Added a full description of how the graphic was created at the end of the article.
... Desirable Location in the ...
... airy Eichler home in desirable Greenmeadow Community. Rare ...
... Desirable Willows location! This ...
... Desirable Palo alto location ...
... amp; flowing floor plan. Desirable neighborhood close to ...
... Turn-key house in desirable Sharon Heights neighborhood ...
... center of the very desirable Willows neighborhood. Gleaming ...
... remodeled Courtyard Eichler in desirable Midtown. Special features ...
... in kitchen, wood burning fireplace and enchanting garden ...
... pantry. Hardwood floors, LR fireplace, formal dining room ( ...
... deck. Vaulted ceilings, inviting fireplace. Gourmet kitchen with ...
... living room has woodburning fireplace with Mantle & ...
... room w/ wood-burning fireplace & windows w/ ...
... its classic charm. Corner fireplace in living room ...
... Huge living room with fireplace and access to ...
... flooring, and wood burning fireplace. Two covered patios, ...
... a quiet, Varsity Park street, this 5 bedroom, 3 bathroom ...
... desirable location and this street is only 3 blocks ...
... on a tree-lined street in the Green ...
... being built across the street. ...
... BEAUTIFUL 9000+ SF LOT! WONDERFUL STREET APPEARANCE + A HUGE, ...
... wide street, plenty of street parking for many ...
... on quiet tree-lined street in the heart ...
... home on tree-lined street one block from ...
... bedroom bungalow in an excellent location close to ...
... amp; downtown Palo Alto. Excellent Menlo Park Schools. ...
... Neighborhood parks, recreational facilities, excellent education, and convenient ...
... development. Lots of light, excellent floor plan, extra ...
... Pardee Park in an excellent neighborhood with charming ...
... mature plants and trees. Excellent Menlo Park schools. ...
... to downtown Menlo Park; excellent Menlo Park schools. ...
... Walk to Flood Park. Excellent Menlo Park schools. ...
... extensively remodeled '01 incl new roof * copper plumbing * double ...
... workshop with gas, newer roof, freshly painted and ...
... bathrooms & kitchen. New roof & professionally painted ...
... with traditional floorplan. Newer roof, newer water heater, ...
... newer windows, doors and roof, good insulation, plus ...
... PRIDE OF OWNWESHIP--NEW ROOF & GUTTERS, FRESH ...
... or in-law. Newer Roof, skylights, furnace & ...
... professionally landscaped gardens. New roof in 2011. Sunny eat- ...
... and deck. Artist Studio. Menlo Park schools. ...
... painted interior. Expansion potential. Menlo Park school district. ...
... Oak Knoll K-5, Hillview 6-8, Menlo Atherton 9-12). ...
... cul-de-sac - great Menlo location! Large yard ...
... Menlo Park rambling 2790 Sq ...
... border, near Sacred Heart, Menlo School. 5 spacious bedrooms, 4 ...
... and deck. Artist Studio. Menlo Park schools. ...
... Menlo Park rambling 2790 Sq ...
... works well for home office, & more ...
... rooms. Great layout. 4BR/office on the first ...
... garage perfect for home office, studio or in- ...
... a family room or office or even a ...
... for family room and office/4th bedroom & ...
... extended family or home office. Beautiful, spacious and ...
... in the bedroom and office, a 2 person spa/ ...
... a separate bonus/recreation/office room, a huge ...
... architectural illumination provide a fabulous evening experience. Unique ...
... Arts near the creek. Fabulous open floor plan ...
... SPACIOUS HOME FEATURES A FABULOUS FLOOR PLAN & ...
... ABUNDANCE OF NATURAL LIGHT. FABULOUS OPORTUNITY TO LIVE ...
... Fabulous Willows location! This 3 ...
... Fabulous stand-alone townhome ...
... Fabulous opportunity to immediately ...
... Fabulous Los Altos home ...
... al fresco dining and entertaining. Minutes-away proximity ...
... backyard is perfect for entertaining and gardening. Home ...
... pool * * Large patio for entertaining * * Spacious and light- ...
... an ideal area for entertaining with a cement ...
... and laundry/mud room. Entertaining backyard deck. Newer ...
... Spacious backyard - perfect for entertaining. Serviced by Huff ...
... granite counters perfect for entertaining guests. Gorgeous tile ...
... perfect for barbecue and entertaining. ...
... both inside and out. Kitchen with professional range, ...
... Maintained, 1/2 bathroom downstairs, Updated Kitchen and Bathrooms, Granite ...
... family room off of kitchen; kitchen ready for ...
... RM W/ SKYLIGHTS, GRANITE KITCHEN W/ STAINLESS STEEL ...
... with high ceilings, Updated kitchen with Caesarstone countertops, ...
... R. , & F. R-KITCHEN W/ BREAKFAST BAR, ...
... sq. ft. Recently remodeled kitchen. Excellent floor plan ...
... open-beamed ceiling, gourmet kitchen w spacious dining ...
... One bedroom and one bathroom can be rented ...
... kitchen and marble master bathroom. Desirable Palo Alto ...
... Park street, this 5 bedroom, 3 bathroom home features 1,976 +/- square ...
... floors underneath carpet, updated bathroom with separate tub ...
... guest area with full bathroom, large enclosed patio ...
... balcony, and a large bathroom. ...
... living space & full bathroom not included in ...
... home with updated kitchen, bathroom, spacious living room ...
... HOME WITH EXQUISITE GARDENS, JUST A SHORT DISTANCE ...
... and sophistication. Beautifully remodeled just 3 years ago, features ...
... this fantastic home located just blocks from both ...
... quiet tree lined st. just needs some tlc. ...
... heart of Greenmeadow and just steps from the ...
... to move right in! Just steps from the ...
... glass. Beautiful hardwood floors. Just moments from California ...
... This home has just refinished hardwood floors, ...
... office! Lovely entry with vaulted ceilings. Gleaming refinished ...
... THROUGHOUT * WELL CARED FOR * VAULTED CEILINGS * LOTS OF ...
... fabulous family room w/ vaulted ceilings, skylights, built- ...
... ROOM, HALLWAY & BEDROOMS. VAULTED OPEN BEAM CEILINGS. ...
... and Family Room feature vaulted ceilings and French ...
... amp; sunny w/ wood vaulted ceilings, mirrored wardrobe ...
... Elegant living room with vaulted ceilings and fireplace, ...
... Features of home include vaulted ceilings, skylights, hdwd ...
... alcove & a master bath w/ marble vanity & ...
... architectural features. Separate 1 bedroom 1 bath living unit. Partial ...
... a 1,200+ sq ft 2 bed 1 bath home & a ...
... with new kitchen, downstairs bath, paint in/out ...
... master suite with private bath, separate family room, ...
... with one bedroom/one bath studio great for ...
... closets, & luxurious master bath. ...
... exterior paint, updated hall bath, newer roof, family ...
... access to Stanford University, downtown Palo Alto and ...
... DOWNTOWN PALO ALTO LIVING ...
... Stunning home in prime downtown Menlo Park. Formal ...
... within walking distance to downtown Mountain View. Newly ...
... WALK TO MOUNTAIN VIEW DOWNTOWN AREA AND BUILD ...
... swim/community center & downtown Menlo Park. Top ...
... W/ ENCHANTING GARDENS NEAR DOWNTOWN PALO ALTO. LIGHT- ...
... distance to school & Downtown Mtn. View ...
... including a partial basement, laundry room off the ...
... appliances, gas stove, upstairs laundry & jacuzzi in ...
... with cozy fireplace. Inside laundry. Walking distance to ...
... wood-burning fireplace, sep laundry room, A/C ...
... Zero and Breakfast Bar, laundry with custom cabinetry. ...
... at top of stairs, laundry room, attached 2 car ...
... office or 3rd bdrm, laundry rm. Classic features ...
... in kitchen w/ adjoining laundry rm. 4th bedroom ...
... one bathroom & appx. 400 sq ft bonus room ...
... UPDATED 4 BD HM WITH 2400 SQ FT. PARTIAL BASEMENT ...
... A 10+! County records state 3154 sq ft. 539 is believed ...
... this lovely home incorporates 1,543 sq. ft. of living ...
... located 3 bedrooms, 2 bathrooms, over 1700 sq. ft. home with ...
... with 4b/2ba, approx 2,450 sq. ft. , formal tile ...
... kitchen. Lot size is 8,347 sq. ft. per City ...
... and stainless appliances. Large 9,920 sq. ft. lot. Truly ...
... UNIT! WOW! THIS HM OFFERS 2 MBR AN UPSTAIRS ...
... amp; OPEN FLOOR PLAN OFFERS FORMAL LIVING & ...
... lushly planted, romantic gardens offers a private setting ...
... drenched 2 bd/2 ba home offers single level living ...
... nestled on a knoll, offers almost 1/2 acre of ...
... with fireplace. Master suite offers a sitting area, ...
... This lovely 3BR home offers designer appeal and ...
... Sale Pending with 3 offers. Wonderful opportunity to ...
... in the heart of Midtown! Refinished hardwood floors ...
... Wonderful midtown location! Spacious 6,600 +/- sq ...
... in the heart of Midtown – this home ...
... Charming Home in Wonderful Midtown Location. Great curb ...
... Courtyard Eichler in desirable Midtown. Special features include ...
... de-sac, close to Midtown shopping. Easy access ...
... This charming Midtown contemporary home is ...
... IN THE HEART OF MIDTOWN * TOP QUALITY FINISHES ...
... with quartz counters and breakfast bar (permitted). New ...
... Light filled kitchen with breakfast bar leads to ...
... cherry cabinets, Corian counters, breakfast bar open to ...
... amp; inviting kitchen w/ breakfast nook, built-in ...
... bedroom. Spacious kitchen w/ breakfast bar, large dining ...
... lots of space w/ breakfast bar, separate family ...
... farmhouse style sink and breakfast nook. Freshly painted ...
... yard. Large kitchen with breakfast bar adjacent to ...
... a spacious living room dining room combo, with ...
... hardwood floors and formal dining area. Ideally located ...
... floor plan spacious with dining room. Immense backyard ...
... amp; nearby shopping and dining venues. It is ...
... w/ wood-burning fireplace, dining area & a ...
... Sep. Family Rm. , Sep. Dining Rm. , Eat-in ...
... inviting. Featuring a living/dining room w/ wood- ...
... bedrooms, 3baths, family room, dining room, breakfast room, ...
... hardwood floors, ample storage, interior and exterior painting. ...
... VACUUM SYSTEM * NEWLY PAINTED INTERIOR & EXTERIOR * LOW ...
... KITCHEN APPLIANCES, EXT. & INTERIOR DOORS & DUAL ...
... open flow. Freshly painted interior & exterior, new ...
... gorgeous gardens. Beautiful bright interior including stunning hardwood ...
... floors, crown moldings, upgraded interior wood doors. 2 fireplaces. ...
... outside with perfectly selected interior finishes * * Formal dining ...
... dble pane windows, new interior/exterior paint, new ...
... Spacious backyard w/ lush lawn & patio. ...
... New rear patio and lawn. ...
... cement patio and lush lawn. ...
... park-like bckyrd w/ lawn, brick patio, mature ...
... sized yard with pool, lawn, patio, barbeque area. ...
... Sunny backyard with verdant lawn. 3 large bedrooms + 4th ...
... Lovely, fenced yard with lawn, patio, garden & ...
... sunny backyard with new lawn. Sumptuous master suite ...
... Fabulous french pane windows, wood floors, partial basement, ...
... feet including a large wood frame sunroom that ...
... Fabulous french pane windows, wood floors, partial basement, ...
... expand! Features include gleaming wood floors, granite, upgrades, ...
... convenience and comfort. 3 levels, wood floors and air ...
... appliances, dual-pane windows, wood-burning gas-lit ...
... down living rm w/ wood beamed vaulted ceiling & ...
... a living room w/ wood-burning fireplace & ...
... large shade tree. Many fruit trees on property. ...
... and artist studio. Pool, fruit trees, 50's rancher ...
... quiet courtyard with many fruit trees. Updated kitchen ...
... secluded back yard, mature fruit trees and sunny ...
... yards with variety of fruit trees. Garage is ...
... rose garden with mature fruit trees, including many ...
... back yard with mature fruit trees-2 car garage-7,900 ...
... w/ mature landscaping and fruit trees. Renowned PA ...
... the epitome of indoor-outdoor living. Features incl ...
... solarium used as indoor/outdoor family room/game ...
... baths. For expansive indoor, outdoor living & entertaining ...
... entertaining options with the outdoor pergola covered patio, ...
... ideal setting for indoor/outdoor entertaining. High tech ...
... freshly painted. Great indoor-outdoor orientation! Light, bright ...
... custom built office. Wonderful Outdoor Living Room for ...
... w/ river & pond, outdoor bar, fruit trees, ...
... hardwood floors, separate dining area w/ French doors ...
... to the family room area and through french ...
... children. Eng. floors public area. ...
... appointed. Open plan living area. Hardwood floors throughout ...
... KIT. W/ ADJOINING DINING AREA, BONUS ROOM (CONVERTED ...
... in the Menlo Oaks area. Home features a ...
... lounging areas, spa, lawn area and auxillary house ...
... Spacious living & dining area with built in ...
... downtown Palo Alto and Stanford Shopping Center. 3 bedrooms, 3 ...
... from Paly High and Stanford. This spacious 4bd/3 ...
... EVERGREEN PARK LOCATION NEAR STANFORD UNIVERSITY AND CLOSE ...
... inported tiles. walking to stanford Univ. Shopping center, ...
... * Available to qualified Stanford faculty and staff ...
... to Peers Park, near Stanford University & California ...
... level lawns. Close to Stanford, dining and shopping. ...
... Stanford Shop. Center & Stanford Univ. this stunningly ...
... attached garage w/ Attic Storage. ...
... garage and lots of storage space! Palo Alto ...
... built-in desk and storage cabinets, beautifully remodeled ...
... and an abundance of storage. Duveneck Elementary(977 API), ...
... Gated area with two storage units. 2 car garage ...
... exterior paint, additional attic storage with pull-down ...
... bedrooms with built-in storage, a shared tile ...
... Spacious baths with great storage. Open kitchen-dining- ...
... backyard and Solar Heated Pool. Remodeled Kitchen with ...
... Good sized yard with pool, lawn, patio, barbeque ...
... Detached Workshop(permit unknown). Pool, BBQ area, Ideal ...
... floors, eat-in kitchen, pool. Excellent Menlo Park ...
... suite with updated bath. Pool with jacuzzi and ...
... th bedroom), gorgeous swimming pool, and a location ...
... custom designed solar heated pool, two outdoor entertainment ...
... Half Olympic Size Swimming Pool, Lots of Fruit ...
... in the kitchen, new carpet. Spacious charming yard ...
... KITCHEN & LAUNDRY, NEW CARPET IN FAMILY ROOM, ...
... parquet floor under the carpet in the living ...
... exterior paint, and new carpet. Top PA schools ...
... windows, hardwood floors under carpet, newer roof, well- ...
... amp; out plus new carpet. Move right in! ...
... with new stove, dishwasher, carpet, paint, landscaping, etc. ...
... hdwd flrs & new carpet in the FR ...
... years- it shines! 4 beds/3 full baths in 2130 SF ...
... and beautiful paver driveway. Full 2-car garage. Stroll ...
... Move-in condition, Full of light and ...
... plus guest quarters with full bath kitchenette ( refrig ...
... extra living space & full bathroom not included ...
... MATURE LANDSCAPING, AND A FULL SIZED THREE CAR ...
... attached artist studio with full bath (could be 4 ...
... additional bedrooms & 3rd full bath. Landscaped grounds ...
... on single-level. Spacious family room for added ...
... schools. Perfect for a family with an extended ...
... cherry cabinets. Sun-filled family rm w/ French ...
... Tremendous room for extended family, or multi-generational ...
... Ref. Bosch dishwasher, Spacious family room with FPLC. ...
... streets. Spacious home with Family room and living ...
... cabinetry and appliances, separate family room with fireplace ...
... on the market. Sep. Family Rm. , Sep. Dining ...
... STUNNING KITCHEN AND BATH * GORGEOUS HARDWOOD FLOORS ACCENTING ...
... Built in 2002, this gorgeous home sparkles like ...
... of colors in the gorgeous plantings in the ...
... perfect for entertaining guests. Gorgeous tile floors, new ...
... amp; MT VIEW HIGH. GORGEOUS UPDATED 4 BD HM ...
... cherry cabinetry, granite, etc. Gorgeous kitchen w/ top ...
... is awaiting YOU! Absolutely gorgeous yard backs up ...
... office/bonus room and gorgeous gardens. Beautiful bright ...
... yard deck, Fruit trees, huge master suite, refinished ...
... one new home with huge backyard or add ...
... top * Master Suite with huge wall-in closet, ...
... cared for and updated. Huge backyard has brick ...
... schools, restaurants, & markets!Huge LR w/ 2 big ...
... recreation/office room, a huge attic, and breezeway. ...
... leading to patio and huge backyard * Master bedroom ...
... ENTRY, LRG REMODELED KITCHEN, HUGE FAMILY ROOM, GROUND ...
... hardwood floors and fresh paint in warm colors. ...
... Spacious, well-maintained, fresh paint inside and out, ...
... fireplace, updated w/ fresh paint, new wall furnaces, ...
... kitchen, recessed lighting, fresh paint, new carpeting, and ...
... molding, wood floors, fresh paint, romantic master, cathedral ...
... tile floors. Fresh interior paint & dual-pane ...
... lovingly updated w/ fresh paint, stainless steel appliances, ...
... shrubs. New custom interior paint, stylish Berber carpet; ...
... of light, excellent floor plan, extra large public ...
... has a fantastic floor plan & the finest ...
... sf Lot Excellent Floor Plan, Double Pane Windows, ...
... FLOWING ONE-LEVEL FLOOR PLAN OFFERS A SPACIOUS ...
... SPACIOUS & VERSATILE FLR PLAN IDEAL FOR EVERYDAY ...
... shutters. The open floor plan in the Great ...
... DOWNTOWN PALO ALTO. FOOR PLAN FEATURES FORMAL LIVING ...
... a spacious open floor plan nested within a ...
... OF DWNTWNS BEST BLOCKS CLOSE TO CASTRO ST! ...
... stunning gardens. Outstanding schools! Close to downtown Menlo ...
... full baths 2 car garage close to schools. ...
... for you. Quiet area close to schools, Parks ...
... in. Large lovely lot close to schools, community ...
... tons of Natural Light! Close to ALL. Excellent ...
... storage. Duveneck Elementary(977 API), close to parks, library, ...
... drip. Walk to school. Close to hwy 101 & 85. ...
... for half a century, beautifully renovated ranch home ...
... BEAUTIFULLY EXPANDED & UPDATED ...
... Beautifully updated home at & ...
... long driveway of this beautifully landscaped flag-lot. ...
... Beautifully remodeled Greenmeadow Eichler ...
... bright and excellent condition. Beautifully maintained and updated ...
... Beautifully updated Eichler w/ ...
... Midtown home on a beautifully landscaped lot. Large ...
... office furniture and extra bonus area/loft. Triple ...
... in Master Bedroom & Bonus room with wood ...
... FOR RELAXING & ENTERTAINING. BONUS OFFICE. ...
... pvt bkyd with sep. bonus rm w/ 1/2 bath & ...
... COMMUNITY CENTER, MAIN LIBRARY. BONUS ROOM (ARTIST'S ...
... oak floors, upstairs carpeted, bonus room over garage. ...
... plumbed detached structure is bonus living space. Approved ...
... patio. Detached garage w/ bonus room. Great opportunity ...
... LOCATION LOCATION LOCATION. .. . ABSOLUTELY ...
... AVAILABLE FOR VIEWING. Fabulous location, timeless design, downstairs ...
... AVAILABLE FOR VIEWING! Fabulous location, timeless design, 5th ...
... Location Location location!! You will love ...
... Location! Location! Location! In ...
... Convenient location across from Lucie ...
... Location Location location!! You ...
... Desirable Palo alto location and neighborhood, tree ...
... TLC. Located in North Palo Alto. A stone ...
... Community Center neighborhood of Palo Alto. Recently remodeled ...
... and farmers' market. Top Palo Alto Schools. ...
... and quiet neighborhood. Great Palo Alto schools! Spacious ...
... to downtown Menlo Park, Palo Alto, and Stanford. ...
... PALO ALTO SCHOOLS! Very ...
... desirable neighborhood. Award winning Palo Alto schools. ...
... in desirable neighborhood of Palo Alto. House in ...
... Single story beauty! Newer and just updated ...
... Formal Dining Room, Glistening Newer Kitchen, Wolfe Range, ...
... Eichler w/ granite kitchen, newer appliances, fabulous open ...
... granite kitchen, hardwood floors, newer doors, baseboards, crown ...
... hot tub. Outdoor fireplace, newer roof, skylight in 1 ...
... floor, double-paned windows, newer paint, fireplace in ...
... Granite counters in kitchen, newer carpet, high ceilings, ...
... paint, stylish Berber carpet; Newer air conditioner, furnace, ...
... Mountain View poss additioon Single Story = total 1644 sq. ...
... HOMES! BRAND NEW CONSTRUCTION! SINGLE FAMILY DETACHED HOMES; ...
... three bedroom, one bath single family home in ...
... for 8 to 12. Plantation shutters. Single story, bedroom & ...
... to downtown Mountain View! Single level 4 bed/2 bath ...
... Charming craftsman, 5 yrs new, single family home, maintenance ...
... Floors, Light and Bright single story home with ...
... setting. 3 beds/2 baths on single-level. Spacious family ...
... European-influenced home peacefully located in MP's ...
... started home. Great value located close to downtown ...
... Located in the middle ...
... life, and is centrally located to major commute ...
... SPACIOUS AND OPEN HOME LOCATED IN A GARDEN ...
... light filled ranch home located on Willows cul- ...
... and possibilities are endless. Located in the heart ...
... expanded Waverly Park home. Located on a large, ...
... Darling, light filled home on ...
... Great indoor-outdoor orientation! Light, bright and gleaming ...
... Wonderful light filled home with ...
... remodeled, open floor plan, light and bright, gourmet ...
... ceilings and bright natural light define the living ...
... doors bring in natural light and illuminate the ...
... and an abundance of light, this home represents ...
... for entertaining * * Spacious and light-filled living room * * ...
... key and ready to move in and enjoy. ...
... Immaculate and ready to move right in! Remodeled ...
... maintain and ready for move-in! Garage built ...
... quot; 3 bedroom/2 bath home (move in ready) with ...
... br/1.5ba home is move in ready. Living ...
... flooring throughout. Ready to move in & enjoy ...
... inside, light & bright. Move in condition. Staged. ...
... Move in Ready! Fresh & ...
... plan & parklike grounds perfect for entertaining; welcoming ...
... large professionally landscaped yard--perfect for entertaining. Gourmet ...
... suite & separate entrance perfect for home office/ ...
... yard and private backyard. Perfect for someone looking ...
... Awesome indoor/outdoor living, perfect for entertaining * Built- ...
... this architectural home is perfect for indoor/outdoor ...
... Awesome indoor/outdoor living, perfect for entertaining * Built- ...
... covered fence and is perfect for entertaining. Custom ...
... that has both a covered and uncovered patio ...
... gardens complete w/ vine covered gazebo. Gourmet kitchen ...
... room. Inviting backyard with covered patio. Beautifully maintained ...
... schools. Gorgeous backyard with covered patio and spa ...
... for extended living space. Covered porch can be 2 ...
... city to be entirely covered by free wireless ...
... rear yard with arbor covered patio, lawn & ...
... fireplace. Expansive corner lot. Covered patio for outdoor ...
... amp; near Downtown Mtn View. Elegant step-down ...
... of the highlights Mountain View might offer for ...
... charming neighborhoods in Mt. View, designed around Sylvan ...
... Best Mountain View Location with Top ...
... spacious floorplan. LR has view to pretty patio & ...
... API 904) and downtown Mountain View. Many upgrades include ...
... in charming Old Mountain View, blocks to parks ...
... amp; outstanding west Mt View location near Cuesta ...
... house in Palo Alto. Hardwood floor thru-out. ...
... GreenPoint Rating of 93! Beautiful hardwood floors downstairs, Crown ...
... pool with spa. Refinished hardwood floors. New carpeting. ...
... decorative features! Everything from hardwood floors and granite ...
... appliances. High ceilings, gleaming hardwood floors & tall ...
... wood burning fireplace and hardwood floors. Large manicured ...
... Yard with stone patio! Hardwood floors throughout!Double ...
... with new exterior paint, hardwood floors, and an ...
... has large walk-in closet, jacuzzi tub, 2nd ...
... with large walk-in closet. Skylights. Formal entry. ...
... seat & walk-in closet, open beam ceilings, ...
... Master w/ walk-in closet, plenty of extra ...
... FULL BATH HAS CONVERTIBLE CLOSET & COULD BE 5 ...
... suite w/ walk-in closet & stunning custom ...
... suite with walk-in closet. Wonderful neighborhood, close ...
... bedroom w/ walk-in closet and access to ...
... Great Eichler in Charleston Gardens, ...
... Lovely Eichler in the desirable ...
... Contemporary Eichler artistically remodeled in 2010! ...
... amp; bright atrium style Eichler home on 9737 sq ...
... Wonderfully updated Eichler! Open floor plan ...
... major commute routes. 3 Bd Eichler with spacious yards & ...
... Beautiful Eichler. Spacious and inviting. ...
... FABULOUS EICHLER HOME IN A ...
... use of windows and skylights, close to Seminary ...
... windows, custom remodeled baths, skylights, refinished hardwd, BIG ...
... with high ceilings and skylights. Gourmet kitchen with ...
... piped radiant heat and skylights throughout. Beautifully landscaped ...
... and functional. Lots windows, Skylights. Hardwood flooring, Franch ...
... DOUBLE PANE WINDOWS AND SKYLIGHTS. SOLAR WATER SYSTEM. ...
... Molding, Ceiling Fans and Skylights. Close Proximity to ...
... tank-less water heater, skylights, imitation slate roof. ...
... HOMES. APPROVED PLNS FOR 2 HOMES AVAILABLE. 1/2 BTHRM PERMIT ...
... Redwood Gate by SummerHill Homes! Brand new construction. ...
... to Stanford University. Two homes, mirror image w/ ...
... Schools - Surrounded By Lovely Homes. A Great Opportunity. ...
... SATAKE ESTATES by SUMMERHILL HOMES! BRAND NEW CONSTRUCTION! ...
... Lot . Six single family homes with top Palo ...
... and quality finishes. The homes are energy efficient ...
... TWO homes on one lot. ...
... Mt. View, parks, library, Center for Performing Arts. ...
... throughout Close to shopping center, downtown Menlo Park & ...
... near the Greenmeadow Community Center & pool. ...
... Elementary, Lucie Stern Community Center, and University Ave. ...
... or the Performing Arts Center from this 11 year ...
... corner lot in the center of the Cuesta ...
... bath house in the center of the very ...
... in the wonderful Community Center neighborhood of Palo ...
... a detached two car garage plus workshop. Enjoy ...
... amp; Redwood Trees, Detached garage converted to storage ...
... Flrs. Lg 2-Car attached garage w/ Attic Storage. ...
... with auto sprinklers, 2 car garage w/ roll-up ...
... mature plants. Detached 1-car Garage. Sold "As ...
... hardwood flrs & new garage are just a ...
... deck. A two car garage with stairs leading ...
... carpeted, bonus room over garage. Short sale subject ...
... LR and DR, remodeled eat-in kitchen, 1 bath ...
... with vaulted ceilings, gourmet eat-in kitchen w/ ...
... w/ fireplace, formal dining, eat-in kitchen, partial ...
... separate dining room, and eat-in kitchen with ...
... IN CONDITION WITH GOURMET EAT IN KITCHEN, STAINLESS ...
... tile bath, a bright, eat-in kitchen, a ...
... door to patio & eat-in space. There ...
... approx 2,322 sqft. A/C. Eat-in kitchen & ...
... offers vaulted ceiling with granite countertops and ample ...
... Neighborhood * Remodeled Kitchen with Granite Slab Counters & ...
... from hardwood floors and granite counter-tops to ...
... doors, dkylites, bamboo floors, granite counters, central A/ ...
... Stunning features include a granite chef’s ...
... Kitchen w/ Cherry cabinets/granite counters center islnd/ ...
... built-in breakfast nook, granite countertops and stainless ...
... Club. Fabulous marble firepl, granite kit, cabinets! Dual, ...
Here's how I created the visualization:
- Download a CSV file from Redfin.com containing data on 1300 homes that sold in Menlo Park, Palo Alto or Mountain View in 2011 with a sale price between $600k and $2M.
- The CSV file contains a URL for each house; the URL links to a web page with its MLS description along with its initial and final selling price. Unfortunately you can only see this page if you are logged in to your Redfin account. That means you can't just use Python's urrllib module to webscrape the MLS text; you need to use some cookie handling code to let Python access the Redfin website. The script 1_compile_data.py below shows how this works. I exported my cookie file for use in the Python script using the Export Cookies add-on for Firefox.
- The output of 1_compile_data.py is a new CSV file containing cleaned data on each house, along with the text of its realty description. This is then parsed with the script 2_create_visualization.py that uses Matplotlib to create a PNG of the visualization. The script also creates the HTML divs that act as triggers for the tooltips over each word.
And here are the two Python scripts discussed above.
1_compile_data.py
# Import modules
# ==============
# Standard library modules (tested on Python 2.6 under Windows 7)
import csv
import cookielib
import urllib2
import re
# Beautifulsoup for webscraping (http://www.crummy.com/software/BeautifulSoup/)
import BeautifulSoup
# Define some constants
# =====================
# Inputs:
# - A CSV file downloaded from Redfin
# - Cookie file exported from Firefox allowing login to Redfin
#
# Outputs:
# - A CSV file containing coded features about a property plus the html
# description from the Redfin page
REDFIN_CSV_FILE = '../data/redfin_data.csv'
COOKIE_FILE = '../data/cookies.txt'
OUTPUT_CSV_FILE = '../data/features.csv'
# Main script starts here
# =======================
# Set up cookies so that we can access Redfin pages through urrllib2
cj = cookielib.MozillaCookieJar()
cj.load(COOKIE_FILE)
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
# Create input and output CSV files
input_csv = csv.reader(open(REDFIN_CSV_FILE, 'rb'))
output_csv = csv.writer(open(OUTPUT_CSV_FILE, 'wb'))
header = ['sq_ft',
'lot_size',
'beds',
'baths',
'yr_built',
'original_listprice',
'parking_spots',
'url',
'sale_price',
'description']
output_csv.writerow(header)
# Loop over rows in input CSV (downloaded from Redfin) that contain
# data on each home.
input_csv.next()
for row in input_csv:
# Select some potentially useful variables from the CSV
# that we will want to include in our output file
sq_ft = row[10]
lot_size = row[11]
beds = row[7]
baths = row[8]
yr_built = row[12]
original_listprice = row[20]
parking_spots = row[13]
url = row[23]
# The url field contains a link to the home's MLS page with
# realtor description and sale history
req = urllib2.Request(url)
handle = urllib2.urlopen(req)
# Use Beautiful soup to scrape the text of the property
# description and also the final sale price
html = handle.read()
soup = BeautifulSoup.BeautifulSoup(html)
try:
description = soup.find('div', id='property_description').text
except AttributeError:
description = ''
try:
sale_price = soup.find('div', attrs={'class': 'price'}).text
sale_price = re.sub('[^0-9]', '', sale_price)
except AttributeError:
sale_price = ''
# Create row of final output data
data = [sq_ft,
lot_size,
beds,
baths,
yr_built,
original_listprice,
parking_spots,
url,
sale_price,
description]
print url, description
output_csv.writerow(data)
2_create_visualization.py
# Import modules
# ==============
# Standard library modules (tested on Python 2.6 under Windows 7)
import random
import csv
import re
import math
import sys
# textmining package from http://christianpeccei.com/projects/textmining/
import textmining
# matplotlib from http://matplotlib.sourceforge.net/
import matplotlib.pyplot as plt
import matplotlib.patches
# Define some constants
# =====================
FEATURES_CSV_FILE = '../data/features.csv'
CONCORDANCE_WIDTH = 8
OUTPUT_PNG_FILE = '../output/visualization.png'
OUTPUT_HTML_FILE = '../output/visualization.html'
# Function definitions
# ====================
def circle_intersect(c1, c2):
# Tests if two circles intersect. Used to Avoid overlapping
# word bubbles in the visualization. A circle is defined by a
# tuple of the form (x_coordinate, y_coordinate, radius)
d = ((c1[0] - c2[0])**2 + (c1[1] - c2[1])**2)**0.5
r = c1[2] + c2[2]
return d < r
# Main script starts here
# =======================
# First step is to read in the CSV file produced by the script
# 1_compile_data.py. We will build up a dictionary called word_data
# that contains all the information for each word needed to create
# the final visualization.
word_data = {}
input_csv = csv.reader(open(FEATURES_CSV_FILE, 'rb'))
# Skip header line
input_csv.next()
for row in input_csv:
(sq_ft,
lot_size,
beds,
baths,
yr_built,
original_listprice,
parking_spots,
url,
sale_price,
description) = row
# Compute the variable 'pct', the percentage over the original list
# price at which a house eventually sold. This will be the y-axis
# of the final plot.
# Sometimes the sale price or original list price will be missing
# in the data so we use a try statement to skip over these records.
try:
pct = (float(sale_price) / float(original_listprice) - 1) * 100
except ValueError:
continue
# A data cleaning step: if the percentage increase/decrease is very
# large or small there is probably something strange going on. For
# example, the home sale might not have been an "at arm's length"
# transaction (e.g. a parent sold to their child for a big discount).
# We'll skip these records.
if abs(pct) > 20:
continue
# Use the text from the home description to create concordances
# for each word. A concordance is a snippet of text surrrounding
# a given word that provides the user with some context. It will
# appear in the tooltips in the final visualization.
#
# Strip any HTML tags from the home description
description = ' ' + re.sub('<.*?>', ' ', description) + ' '
# Split the text into alternating tokens of non-word, word, non-word, etc
tokens = re.split('([^A-Za-z]+)', description)
# Build the concordances for each word. Note that we are goign to add
# some HTML tags to the concordances so they will display nicely
# in the tooltips.
words = set()
for i in range(2, len(tokens) - 2, 2):
word = tokens[i].lower()
words.add(word)
i_start = max(i - CONCORDANCE_WIDTH, 0)
i_end = i + CONCORDANCE_WIDTH
# We will wrap the focus word of this concordance in a highlight
# tag so we can make it stand out in the tooltip.
concordance = '<p>... ' + ''.join(tokens[i_start:i] +
["<span class='hilite'>" + tokens[i] +
'</span>'] + tokens[i + 1:i_end]) + ' ...</p>'
if word not in word_data:
word_data[word] = {'concordances': [], 'pct': []}
word_data[word]['concordances'].append(concordance)
# Now that we know all the words that appeard in this description,
# we store the pct value in a list for each of the words. In the next
# step we will compute the mean pct for each word.
for word in words:
word_data[word]['pct'].append(pct)
# Compute the mean pct increase/decrease for all homes with
# a given word in their description. Also compute number of home
# descriptions containing that word.
for word in word_data:
pct = word_data[word]['pct']
word_data[word]['n'] = len(pct)
word_data[word]['mean_pct'] = sum(pct) / len(pct)
# To eliminate "noise" words we will filter the list of words in three
# ways.
# 1) Remove any words that occur in less than 50 home descriptions
# 2) Remove any common stopwords such as "and", "the", etc
# 3) Remove words that have a very high or low average pct. This
# ensures all the word bubbles will fit nicely on the y-axis of the plot.
for word in word_data.keys():
if word_data[word]['n'] < 50 or word in textmining.stopwords \
or abs(word_data[word]['mean_pct']) > 4:
del word_data[word]
# We will also scale the pct for each word to lie in the range 0 to 1.
# This will be used for indexing into a colormap to color the word
# bubbles.
min_mean_pct = min(word_data[word]['mean_pct'] for word in word_data)
max_mean_pct = max(word_data[word]['mean_pct'] for word in word_data)
for word in word_data:
word_data[word]['mean_pct_01'] = (word_data[word]['mean_pct'] -
min_mean_pct) / (max_mean_pct - min_mean_pct)
# Run layout algorithm to arrange circles
# =======================================
# Assign an initial x and y coordinate for each word bubble.
for word in word_data:
x = 0
y = word_data[word]['mean_pct']
# Set radius of the circle
r = 0.3
word_data[word]['circle'] = [x, y, r]
# The first step in the layout algorithm is to create a list
# of words sorted in descending order by their y-coordinate
words = sorted(word_data, key = lambda x: word_data[x]['circle'][1],
reverse=True)
# Loop over the words and adjust their x-coordinates so there are
# no overlaps. We will skip the first word (hence i starts at 1, not 0).
for i in range(1, len(words)):
x = 0
valid_circles = []
while 1:
# Find first available circle position to left
test_circle = word_data[words[i]]['circle'][:]
test_circle[0] = -x
intersect_left_any_above = False
for j in range(i):
if circle_intersect(test_circle, word_data[words[j]]['circle']):
intersect_left_any_above = True
if not intersect_left_any_above:
valid_circles.append(test_circle)
# Find first available circle position to right
test_circle = word_data[words[i]]['circle'][:]
test_circle[0] = x
intersect_right_any_above = False
for j in range(i):
if circle_intersect(test_circle, word_data[words[j]]['circle']):
intersect_right_any_above = True
if not intersect_right_any_above:
valid_circles.append(test_circle)
# Exit the loop if we have found a valid circle position
# on either the right or left
if valid_circles:
break
# If no valid circle, increase the x offset and try again
x += .1
# Pick randomly between the right or left circle position and use
# this as the placement for the word bubble
random.shuffle(valid_circles)
word_data[words[i]]['circle'] = valid_circles[0]
# Throw out any words which have an x-coordinate greater than +- 2.5.
# This step is to prevent creating a very wide graphic, since there
# are a lot of words and if we plotted them all the final
# visualization would be much wider than it was tall.
for word in word_data.keys():
if abs(word_data[word]['circle'][0]) > 2.5:
del word_data[word]
# Use Matplotlib to draw the visualization
# ========================================
# Set up figure area and axis
plt.figure(figsize=(7.77, 10), dpi=100)
plt.axis([-3, 4, -4.5, 4.5])
plt.subplots_adjust(left=0, right=1, top=1, bottom=0)
plt.gca().set_axis_off()
# Add horizontal lines with labels showing significant price deltas
plt.hold(True)
plt.plot((-3, 4), (-2, -2), 'k', zorder=-1)
plt.plot((-3, 4), (0, 0), 'k', zorder=-1)
plt.plot((-3, 4), (2, 2), 'k', zorder=-1)
plt.text(2.8, -1.9, 'Sold 2% below asking', fontsize=8)
plt.text(2.8, .1, 'Sold at asking', fontsize=8)
plt.text(2.8, 2.1, 'Sold 2% above asking', fontsize=8)
# Choose a colormap for the bubbles.
# You can try changing this to cm.Blues or any other colormap
# to get a different effect
cmap = plt.cm.jet
# Open the html file that will contain the tooltip information.
# Note that the tooltips are generated to be compatible with
# the jQuery Tools library. See http://flowplayer.org/tools/tooltip/index.html
f_html = open(OUTPUT_HTML_FILE, 'w')
# Loop over the words to create the final visualization
for word in word_data:
# Draw the bubble for the word
x, y, r = word_data[word]['circle']
c = word_data[word]['mean_pct_01']
plt.gca().add_patch(matplotlib.patches.Circle((x, y), r,
facecolor=cmap((c - .5) * .6 + .5),
edgecolor='none'))
# Add the word itself as some text inside the bubble
plt.text(x, y, word, fontsize=8,
horizontalalignment='center',
verticalalignment='center')
# We want to add a tooltip for each bubble so we will create a div
# in our HTML that covers the face of the bubble. Divs are rectangular
# but the bubbles are round, so the div won't cover the bubble completely.
# The coordinates of the div in the HTML are in pixels but we currently
# have the coordinates of the bubble in the coordinate system of
# the Matplotlib axis. We use the transform method to convert figure
# coordinates into pixels.
px, py = plt.gca().transData.transform((x, y))
# The half_width of the div rectangle is hard-coded to correspond
# to the radius of 0.3 defined earlier. I know, this should be
# computed dynamically.
half_width = 25
top = 1000 - py - half_width
left = px - half_width
# We will also include a random selection of 8 concordances
# for this word in the tooltip for the bubble. We shuffle the
# concordances so that we get a mix of word usage from across
# all houses in the dataset.
random.shuffle(word_data[word]['concordances'])
concordances = '\n'.join(word_data[word]['concordances'][:8])
f_html.write("""<div class="tooltip_div"
style="position:absolute; top:%dpx; left:%dpx;
width:%dpx; height:%dpx;"></div>
<div class="tooltip">
%s
</div>
""" % (top, left, half_width * 2, half_width * 2, concordances))
# Close HTML file
f_html.close()
# Save figure to PNG file
plt.savefig(OUTPUT_PNG_FILE, dpi=100)