From f6054c81b09ade796b4524920670f717308da6e2 Mon Sep 17 00:00:00 2001 From: Nipun Batra Date: Thu, 5 Jan 2017 18:43:43 +0530 Subject: [PATCH] Added case 4: w/ static from both regions --- mf_approach/code/both_regions_dd.py | 15 ++++- mf_approach/notebooks/final-all-homes.ipynb | 5 +- mf_approach/notebooks/kdd17.ipynb | 16 ++--- mf_approach/notebooks/main-result-sd.ipynb | 65 ++++++--------------- 4 files changed, 38 insertions(+), 63 deletions(-) diff --git a/mf_approach/code/both_regions_dd.py b/mf_approach/code/both_regions_dd.py index 753333fa4..45faaade5 100644 --- a/mf_approach/code/both_regions_dd.py +++ b/mf_approach/code/both_regions_dd.py @@ -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 ################################################################ @@ -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] + + @@ -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) @@ -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 diff --git a/mf_approach/notebooks/final-all-homes.ipynb b/mf_approach/notebooks/final-all-homes.ipynb index ca9463aad..e65283710 100644 --- a/mf_approach/notebooks/final-all-homes.ipynb +++ b/mf_approach/notebooks/final-all-homes.ipynb @@ -957,8 +957,9 @@ } ], "metadata": { + "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 2", + "display_name": "Python [default]", "language": "python", "name": "python2" }, @@ -972,7 +973,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.11" + "version": "2.7.12" } }, "nbformat": 4, diff --git a/mf_approach/notebooks/kdd17.ipynb b/mf_approach/notebooks/kdd17.ipynb index eaa1cfe73..4b507aae2 100644 --- a/mf_approach/notebooks/kdd17.ipynb +++ b/mf_approach/notebooks/kdd17.ipynb @@ -4345,9 +4345,7 @@ "output_type": "execute_result" } ], - "source": [ - "" - ] + "source": [] }, { "cell_type": "code", @@ -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 -} \ No newline at end of file +} diff --git a/mf_approach/notebooks/main-result-sd.ipynb b/mf_approach/notebooks/main-result-sd.ipynb index fd8ce5c7f..9a581204d 100644 --- a/mf_approach/notebooks/main-result-sd.ipynb +++ b/mf_approach/notebooks/main-result-sd.ipynb @@ -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'))" ] }, @@ -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", @@ -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", @@ -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 }, @@ -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" ] } ], @@ -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", @@ -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 -} \ No newline at end of file +}