-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Add Ames housing #155
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
require "csv" | ||
|
||
require_relative "dataset" | ||
|
||
module Datasets | ||
class AmesHousing < Dataset | ||
Record = Struct.new(:order, | ||
:pid, | ||
:ms_sub_class, | ||
:ms_zoning, | ||
:lot_frontage, | ||
:lot_area, | ||
:street_alley, | ||
:lot_shape, | ||
:land_contour, | ||
:utilities, | ||
:lot_config, | ||
:land_slope, | ||
:neighborhood, | ||
:condition_1, | ||
:condition_2, | ||
:bldg_type, | ||
:house_style, | ||
:overall_qual, | ||
:overall_cond, | ||
:year_built, | ||
:year_remod_add, | ||
:roof_style, | ||
:roof_matl, | ||
:exterior_1st, | ||
:exterior_2nd, | ||
:mas_vnr_type, | ||
:mas_vnr_area, | ||
:exter_qual, | ||
:exter_cond, | ||
:foundation, | ||
:bsmt_qual, | ||
:bsmt_cond, | ||
:bsmt_exposure, | ||
:bsmt_fin_type_1, | ||
:bsmt_fin_sf_1, | ||
:bsmt_fin_type_2, | ||
:bsmt_fin_sf_2, | ||
:bsmt_unf_sf, | ||
:total_bsmt_sf, | ||
:heating, | ||
:heating_qc, | ||
:central_air, | ||
:electrical, | ||
:first_flr_sf, | ||
:second_flr_sf, | ||
:low_qual, | ||
:fin_sf, | ||
:gr_liv_area, | ||
:bsmt_full_bath, | ||
:bsmt_half_bath, | ||
:full_bath, | ||
:half_bath, | ||
:bedroom_abv_gr, | ||
:kitchen_abv_gr, | ||
:kitchen_qual, | ||
:tot_rms_abv_grd, | ||
:functional, | ||
:fireplaces, | ||
:fireplace_qu, | ||
:garage_type, | ||
:garage_yr_blt, | ||
:garage_finish, | ||
:garage_cars, | ||
:garage_area, | ||
:garage_qual, | ||
:garage_cond, | ||
:paved_drive, | ||
:wood_deck_sf, | ||
:open_porch_sf, | ||
:enclosed_porch, | ||
:three_ssn_porch, | ||
:screen_porch, | ||
:pool_area, | ||
:pool_qc, | ||
:fence, | ||
:misc_feature, | ||
:misc_val, | ||
:mo_sold, | ||
:yr_sold, | ||
:sale_type, | ||
:sale_condition, | ||
:sale_price) | ||
|
||
|
||
def initialize | ||
super() | ||
@metadata.id = "ames-housing" | ||
@metadata.name = "Ames Housing" | ||
@metadata.url = "http://jse.amstat.org/v19n3/decock/DataDocumentation.txt" | ||
@metadata.licenses = ["Unknown"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. http://jse.amstat.org/jse_users.htm said:
Could you ask the author the license of this dataset? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still waiting for this. Will remind again beginning of December. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see! |
||
@metadata.description = <<-DESCRIPTION | ||
Data set contains information from the Ames Assessor’s Office | ||
used in computing assessed values for individual residential | ||
properties sold in Ames, IA from 2006 to 2010. | ||
De Cock, D., | ||
"Ames, Iowa: Alternative to the Boston Housing Data as an | ||
End of Semester Regression Project", | ||
Journal of Statistics Education, 19(3) (2011) 1-15. | ||
Available from http://jse.amstat.org/v19n3/decock.pdf. | ||
DESCRIPTION | ||
end | ||
|
||
def each | ||
return to_enum(__method__) unless block_given? | ||
|
||
open_data do |input| | ||
input.each do |row| | ||
next if row[0].nil? | ||
record = Record.new(*row) | ||
yield(record) | ||
end | ||
end | ||
end | ||
|
||
private | ||
def open_data | ||
data_path = cache_dir_path + "AmesHousing.txt" | ||
data_url = "http://jse.amstat.org/v19n3/decock/AmesHousing.txt" | ||
download(data_path, data_url) | ||
CSV.open(data_path, converters: [:numeric]) do |csv| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better that we preprocess the original data based on http://jse.amstat.org/v19n3/decock/DataDocumentation.txt . For example, the "MS SubClass" column values can be converted to "1-STORY 1946 & NEWER ALL STYLES" from "020" and so on:
|
||
yield(csv) | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
class AmesHousingTest < Test::Unit::TestCase | ||
def setup | ||
@dataset = Datasets::AmesHousing.new | ||
end | ||
|
||
def record(*args) | ||
Datasets::AmesHousing::Record.new(*args) | ||
end | ||
|
||
test("#each") do | ||
records = @dataset.each.to_a | ||
assert_equal([ | ||
2930, | ||
{ | ||
order: 1, | ||
pid: 0526301100, | ||
ms_sub_class: 020, | ||
ms_zoning: "RL", | ||
lot_frontage: 141, | ||
lot_area: 31770, | ||
street: "Pave", | ||
alley: "NA", | ||
lot_shape: "IR1", | ||
land_contour: "Lvl", | ||
utilities: "AllPub", | ||
lot_config: "Corner", | ||
land_slope: "Gtl", | ||
neighborhood: "NAmes", | ||
condition_1: "Norm", | ||
condition_2: "Norm", | ||
bldg_type: "1Fam", | ||
house_style: "1Story", | ||
overall_qual: 6, | ||
overall_cond: 5, | ||
year_built: 1960, | ||
year_remod_add: 1960, | ||
roof_style: "Hip", | ||
roof_matl: "CompShg", | ||
exterior_1st: "BrkFace", | ||
exterior_2nd: "Plywood", | ||
mas_vnr_type: "Stone", | ||
mas_vnr_area: 112, | ||
exter_qual: "TA", | ||
exter_cond: "TA", | ||
foundation: "CBlock", | ||
bsmt_qual: "TA", | ||
bsmt_cond: "Gd", | ||
bsmt_exposure: "Gd", | ||
bsmt_fin_type_1: "BLQ", | ||
bsmt_fin_sf_1: 639, | ||
bsmt_fin_type_2: "Unf", | ||
bsmt_fin_sf_2: 0, | ||
bsmt_unf_sf: 441, | ||
total_bsmt_sf: 1080, | ||
heating: "GasA", | ||
heating_qc: "Fa", | ||
central_air: "Y", | ||
electrical: "SBrkr", | ||
first_flr_sf: 1656, | ||
second_flr_sf: 0, | ||
low_qual_fin_sf: 0, | ||
gr_liv_area: 1656, | ||
bsmt_full_bath: 1, | ||
bsmt_half_bath: 0, | ||
full_bath: 1, | ||
half_bath: 0, | ||
bedroom_abv_gr: 3, | ||
kitchen_abv_gr: 1, | ||
kitchen_qual: "TA", | ||
tot_rms_abv_grd: 7, | ||
functional: "Typ", | ||
fireplaces: 2, | ||
fireplace_qu: "Gd", | ||
garage_type: "Attchd", | ||
garage_yr_blt: 1960, | ||
garage_finish: "Fin", | ||
garage_cars: 2, | ||
garage_area: 528, | ||
garage_qual: "TA", | ||
garage_cond: "TA", | ||
paved_drive: "P", | ||
wood_deck_sf: 210, | ||
open_porch_sf: 62, | ||
enclosed_porch: 0, | ||
three_ssn_porch: 0, | ||
screen_porch: 0, | ||
pool_area: 0, | ||
pool_qc: "NA", | ||
fence: "NA", | ||
misc_feature: "NA", | ||
misc_val: 0, | ||
mo_sold: 5, | ||
yr_sold: 2010, | ||
sale_type: "WD", | ||
sale_condition: "Normal", | ||
sale_price: 215000 | ||
}, | ||
{ | ||
order: 2930, | ||
pid: 0924151050, | ||
ms_sub_class: 060, | ||
ms_zoning: "RL", | ||
lot_frontage: 74, | ||
lot_area: 9627, | ||
street: "Pave", | ||
alley: "NA", | ||
lot_shape: "Reg", | ||
land_contour: "Lvl", | ||
utilities: "AllPub", | ||
lot_config: "Inside", | ||
land_slope: "Mod", | ||
neighborhood: "Mitchel", | ||
condition_1: "Norm", | ||
condition_2: "Norm", | ||
bldg_type: "1Fam", | ||
house_style: "2Story", | ||
overall_qual: 7, | ||
overall_cond: 5, | ||
year_built: 1993, | ||
year_remod_add: 1994, | ||
roof_style: "Gable", | ||
roof_matl: "CompShg", | ||
exterior_1st: "HdBoard", | ||
exterior_2nd: "HdBoard", | ||
mas_vnr_type: "BrkFace", | ||
mas_vnr_area: 94, | ||
exter_qual: "TA", | ||
exter_cond: "TA", | ||
foundation: "PConc", | ||
bsmt_qual: "Gd", | ||
bsmt_cond: "TA", | ||
bsmt_exposure: "Av", | ||
bsmt_fin_type_1: "LwQ", | ||
bsmt_fin_sf_1: 758, | ||
bsmt_fin_type_2: "Unf", | ||
bsmt_fin_sf_2: 0, | ||
bsmt_unf_sf: 238, | ||
total_bsmt_sf: 996, | ||
heating: "GasA", | ||
heating_qc: "Ex", | ||
central_air: "Y", | ||
electrical: "SBrkr", | ||
first_flr_sf: 996, | ||
second_flr_sf: 1004, | ||
low_qual_fin_sf: 0, | ||
gr_liv_area: 2000, | ||
bsmt_full_bath: 0, | ||
bsmt_half_bath: 0, | ||
full_bath: 2, | ||
half_bath: 1, | ||
bedroom_abv_gr: 3, | ||
kitchen_bv_gr: 1, | ||
kitchen_qual: "TA", | ||
tot_rms_abv_grd: 9, | ||
functional: "Typ", | ||
fireplaces: 1, | ||
fireplace_qu: "TA", | ||
garage_type: "Attchd", | ||
garage_yr_blt: 1993, | ||
garage_finish: "Fin", | ||
garage_cars: 3, | ||
garage_area: "650", | ||
garage_qual: "TA", | ||
garage_cond: "TA", | ||
paved_drive: "Y", | ||
wood_deck_sf: 190, | ||
open_porch_sf: 48, | ||
enclosed_porch: 0, | ||
three_ssn_porch: 0, | ||
screen_porch: 0, | ||
pool_area: 0, | ||
pool_qc: "NA", | ||
fence: "NA", | ||
misc_feature: "NA", | ||
misc_val: 0, | ||
mo_sold: 11, | ||
yr_sold: 2006, | ||
sale_type: "WD", | ||
sale_condition: "Normal", | ||
sale_price: 188000 | ||
}, | ||
], | ||
[ | ||
records.size, | ||
records[0].to_h, | ||
records[-1].to_h | ||
]) | ||
end | ||
|
||
sub_test_case("#metadata") do | ||
test("#description") do | ||
description = @dataset.metadata.description | ||
assert_equal(<<-DESCRIPTION, description) | ||
Data set contains information from the Ames Assessor’s Office | ||
used in computing assessed values for individual residential | ||
properties sold in Ames, IA from 2006 to 2010. | ||
De Cock, D., | ||
"Ames, Iowa: Alternative to the Boston Housing Data as an | ||
End of Semester Regression Project", | ||
Journal of Statistics Education, 19(3) (2011) 1-15. | ||
Available from http://jse.amstat.org/v19n3/decock.pdf. | ||
DESCRIPTION | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw this comment: #43 (comment)
Maybe should we use house_prices datasets in OpenML because sklearn.datasets.load_boston mentioned it here?
If we use this data, there is one problem. This dataset file is
.arff
. So we have to implement parser function about it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh I'm sorry. there are json and xml formats too. So how do you think we will get data from OpenML?
ref: https://www.openml.org/search?type=data&sort=runs&id=42165&status=active
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comments. The data is at https://api.openml.org/data/v1/download/21754539/house_prices.arff , the json and xml files contain metadata only.
arff is used in Weka, there are readers for R and Python, so such a reader may be helpful whether it is used here or not.
The data use in sklearn has been cleaned, but is in csv form.
As explained in https://www.tmwr.org/ames.html the data in the model data package has been transformed more than the data used in sklearn, with latitude and longitude information that is helpful for visualization. It seems higher quality, but is available in rda format https://github.com/topepo/AmesHousing/tree/master/data though it is possible to export to csv format as explained at https://stackoverflow.com/questions/4487065/convert-rda-to-csv An rda reader would likely also be helpful.
At the moment, all data is downloaded from external repositories which may disappear. It may be good to host some of the data at a location that has better control, but probably this can be a separate issue.
Similarly plugin readers for rda and arff similar to https://github.com/red-data-tools/red-datasets-pandas should be separate issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I thought there were Ames housing data too. But it wasn't.
Thank you for explaining the situation in details.
Now I agree with you to use this data resource. And it looks better way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation.
I agree with using http://jse.amstat.org/v19n3/decock/AmesHousing.txt (the original data) is suitable. I confirmed https://www.tandfonline.com/doi/citedby/10.1080/10691898.2011.11889627 too because http://jse.amstat.org/ was archived and move to https://tandfonline.com/toc/ujse20/current . It seems that new site https://www.tandfonline.com/doi/citedby/10.1080/10691898.2011.11889627 doesn't provide the original data. Other article such as https://www.tandfonline.com/doi/full/10.1080/26939169.2022.2074923 has the "Supplemental" tab but https://www.tandfonline.com/doi/citedby/10.1080/10691898.2011.11889627 doesn't have the tab.