Skip to content

Commit

Permalink
Added case 4: w/ static from both regions
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunbatra committed Jan 5, 2017
1 parent 11dffe9 commit f6054c8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 63 deletions.
15 changes: 12 additions & 3 deletions mf_approach/code/both_regions_dd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
###################CASES#######################################
### CASE 1: Train and test on homes from SD w/o static features
### CASE 2: Train on homes from SD and Austin w/o static features
### Case 3: Train on homes from SD and Austin w/ temp feature
### Case 3: Train on homes from SD and Austin w/ static and temp feature
### Case 4: Train and test on homes from SD w static and temp features
################################################################


Expand Down Expand Up @@ -76,6 +77,14 @@ def create_region_df(region):
aus_dfc[key]=dds['Austin'][key_num]
df = pd.concat([sd_df, aus_df])
dfc = pd.concat([sd_dfc, aus_dfc])
elif case==4:
df = sd_df
dfc = sd_dfc
for key_num, key in enumerate(dd_keys):
sd_df[key]=dds['SanDiego'][key_num]
sd_dfc[key]=dds['SanDiego'][key_num]





Expand Down Expand Up @@ -107,7 +116,7 @@ def create_region_df(region):
start, end=1,13
X_matrix, X_normalised, col_max, col_min, appliance_cols, aggregate_cols = preprocess(df, dfc, appliance)

if case==3:
if case>=3:
static_features = get_static_features_region_level(dfc, X_normalised)
else:
static_features = get_static_features(dfc, X_normalised)
Expand All @@ -119,7 +128,7 @@ def create_region_df(region):
#all_feature_homes = dfc[(dfc.full_agg_available == 1) & (dfc.md_available == 1)][all_cols].dropna().index


if case==3:
if case>=3:
max_f = 20
else:
max_f=1
Expand Down
5 changes: 3 additions & 2 deletions mf_approach/notebooks/final-all-homes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -957,8 +957,9 @@
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python [default]",
"language": "python",
"name": "python2"
},
Expand All @@ -972,7 +973,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
"version": "2.7.12"
}
},
"nbformat": 4,
Expand Down
16 changes: 6 additions & 10 deletions mf_approach/notebooks/kdd17.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4345,9 +4345,7 @@
"output_type": "execute_result"
}
],
"source": [
""
]
"source": []
},
{
"cell_type": "code",
Expand All @@ -4356,31 +4354,29 @@
"collapsed": true
},
"outputs": [],
"source": [
""
]
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python [default]",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2.0
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
"version": "2.7.12"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
}
65 changes: 17 additions & 48 deletions mf_approach/notebooks/main-result-sd.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"outputs": [],
"source": [
"mf_pred = pickle.load(open('../data/mf_pred_all_homes.pkl','r'))\n",
"mf_pred = pickle.load(open('../data/out_3_dd.pkl','r'))\n",
"knn_results = pickle.load(open('../data/knn_pred_all_homes.pkl','r'))"
]
},
Expand All @@ -66,14 +66,14 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 8,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def compute_rmse_fraction(appliance, pred_df):\n",
" region = \"Austin\"\n",
" region = \"SanDiego\"\n",
" df = out_overall[region]\n",
" #pred_df = mf_pred[appliance][appliance_feature][latent_factors]\n",
" gt_df = df[pred_df.columns].ix[pred_df.index]\n",
Expand All @@ -89,8 +89,8 @@
" \n",
" pred_fraction = pred_fraction.dropna()\n",
" gt_fraction = gt_fraction.dropna()\n",
" print pred_fraction.describe()\n",
" print gt_fraction.describe()\n",
" #print pred_fraction.describe()\n",
" #print gt_fraction.describe()\n",
"\n",
"\n",
" rms = np.sqrt(mean_squared_error(pred_fraction,gt_fraction))\n",
Expand All @@ -99,44 +99,18 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 10,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"result = {'MF':{},'KNN':{},'FHMM':{}}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Computing for KNN"
"result = {'MF':{}}"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"for appliance, appliance_df in knn_results.iteritems():\n",
" \n",
" pred_df = appliance_df\n",
" pred_df.columns = [appliance+\"_\"+str(x) for x in pred_df.columns]\n",
" rmse_fraction = compute_rmse_fraction(appliance, pred_df)\n",
" \n",
"\n",
" #rms = np.sqrt(mean_squared_error(gt_df, pred_df))\n",
" result['KNN'][appliance]=rmse_fraction"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 11,
"metadata": {
"collapsed": false
},
Expand All @@ -145,13 +119,9 @@
"name": "stdout",
"output_type": "stream",
"text": [
"hvac\n",
"wm\n",
"fridge\n",
"mw\n",
"oven\n",
"dw\n",
"{'hvac': ('area', 9, 23.062443182449364), 'wm': ('occ', 3, 1.292907746177548), 'fridge': ('occ_area', 7, 56.419845955447094), 'mw': ('occ_area', 6, 0.9841175302519054), 'oven': ('occ', 8, 1.4241289192051436), 'dw': ('None', 5, 16.697917236289435)}\n"
"hvac\n",
"{'fridge': ('occ', 9, 13.431200129690193), 'hvac': ('dd_11', 3, 14.022029756205505)}\n"
]
}
],
Expand All @@ -163,7 +133,7 @@
" for appliance_feature, appliance_feature_struct in appliance_struct.iteritems():\n",
" for latent_factors, appliance_df in appliance_struct[appliance_feature].iteritems():\n",
" try:\n",
" region = \"Austin\"\n",
" region = \"SanDiego\"\n",
" df = out_overall[region]\n",
" pred_df = mf_pred[appliance][appliance_feature][latent_factors]\n",
" \n",
Expand Down Expand Up @@ -732,30 +702,29 @@
"collapsed": true
},
"outputs": [],
"source": [
""
]
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python [default]",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2.0
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
"version": "2.7.12"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
}

0 comments on commit f6054c8

Please sign in to comment.