{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport plotly.express as px\nimport plotly.graph_objs as go\n\nimport plotly\nplotly.offline.init_notebook_mode(connected=True)\n\n#Ignore warnings\nimport warnings\nwarnings.filterwarnings('ignore')\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-05-15T22:05:04.830336Z","iopub.execute_input":"2022-05-15T22:05:04.830784Z","iopub.status.idle":"2022-05-15T22:05:07.055579Z","shell.execute_reply.started":"2022-05-15T22:05:04.830679Z","shell.execute_reply":"2022-05-15T22:05:07.054837Z"},"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(\"/kaggle/input/energy-anomaly-detection/train.csv\", delimiter=',', encoding='utf8')\npd.set_option('display.max_columns', None)\ndf.tail()","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:08:35.467078Z","iopub.execute_input":"2022-05-15T22:08:35.467393Z","iopub.status.idle":"2022-05-15T22:08:36.204809Z","shell.execute_reply.started":"2022-05-15T22:08:35.467360Z","shell.execute_reply":"2022-05-15T22:08:36.203976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:09:12.203353Z","iopub.execute_input":"2022-05-15T22:09:12.203624Z","iopub.status.idle":"2022-05-15T22:09:12.292928Z","shell.execute_reply.started":"2022-05-15T22:09:12.203596Z","shell.execute_reply":"2022-05-15T22:09:12.292225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Beware, since head hour was 00:00:00 adter the next snippet it seemed that it was cleaned hr/min.sec.\n\nThough when we run tail, we say that they are still there.","metadata":{}},{"cell_type":"code","source":"#Code by Dasmehdixtr https://www.kaggle.com/code/dasmehdixtr/energy-anomally-detection-65-test-set-accuracy/notebook\n\ndf['timestamp'] = pd.to_datetime(df['timestamp'])\ndf.tail()","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:13:06.623730Z","iopub.execute_input":"2022-05-15T22:13:06.624680Z","iopub.status.idle":"2022-05-15T22:13:06.806098Z","shell.execute_reply.started":"2022-05-15T22:13:06.624629Z","shell.execute_reply":"2022-05-15T22:13:06.805322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Dasmehdixtr https://www.kaggle.com/code/dasmehdixtr/energy-anomally-detection-65-test-set-accuracy/notebook\n\ndf['year'] = df['timestamp'].dt.year\ndf['month'] = df['timestamp'].dt.month\ndf['day'] = df['timestamp'].dt.day\ndf['hour'] = df['timestamp'].dt.hour\ndf['minute'] = df['timestamp'].dt.minute\ndf['second'] = df['timestamp'].dt.second\ndf = df.drop(['timestamp'], axis=1)\ndf.tail()","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:17:21.886640Z","iopub.execute_input":"2022-05-15T22:17:21.887279Z","iopub.status.idle":"2022-05-15T22:17:22.969719Z","shell.execute_reply.started":"2022-05-15T22:17:21.887238Z","shell.execute_reply":"2022-05-15T22:17:22.968893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Energy Consumption by month","metadata":{}},{"cell_type":"code","source":"df[\"month\"].plot(figsize=(20,4));","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:21:12.177211Z","iopub.execute_input":"2022-05-15T22:21:12.177821Z","iopub.status.idle":"2022-05-15T22:21:12.518488Z","shell.execute_reply.started":"2022-05-15T22:21:12.177772Z","shell.execute_reply":"2022-05-15T22:21:12.517647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#I have No clue how to interpret the anomalies on the scatter bellow.","metadata":{}},{"cell_type":"code","source":"fig = px.scatter(df, x=\"meter_reading\", y=\"anomaly\",color_discrete_sequence=['#4257f5'], title=\"Energy Anomaly Detection\" )\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:28:28.043602Z","iopub.execute_input":"2022-05-15T22:28:28.043893Z","iopub.status.idle":"2022-05-15T22:28:35.306725Z","shell.execute_reply.started":"2022-05-15T22:28:28.043863Z","shell.execute_reply":"2022-05-15T22:28:35.305750Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Abhishek Sharma https://www.kaggle.com/code/anotherbadcode/apriori-analysis\n\nimport scipy.stats as ss\nfrom mlxtend.frequent_patterns import apriori, association_rules\nimport networkx as nx\nimport os\nimport json\nfrom datetime import datetime\nfrom itertools import combinations, groupby\nfrom collections import Counter\n\nimport itertools\nimport networkx as nx","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:41:41.584807Z","iopub.execute_input":"2022-05-15T22:41:41.585725Z","iopub.status.idle":"2022-05-15T22:41:41.591405Z","shell.execute_reply.started":"2022-05-15T22:41:41.585675Z","shell.execute_reply":"2022-05-15T22:41:41.590639Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Abhishek Sharma https://www.kaggle.com/code/anotherbadcode/apriori-analysis\n\ndef cramers_v(confusion_matrix):\n    \"\"\" \n    Calculate Cramers V statistic for categorial-categorial association.\n    Considering items & their occurences here as categories.\n    \n    \"\"\"\n    chi2 = ss.chi2_contingency(confusion_matrix)[0]\n    n = confusion_matrix.sum()\n    phi2 = chi2 / n\n    r, k = confusion_matrix.shape\n    phi2corr = max(0, phi2 - ((k-1)*(r-1))/(n-1))\n    rcorr = r - ((r-1)**2)/(n-1)\n    kcorr = k - ((k-1)**2)/(n-1)\n    return np.sqrt(phi2corr / min((kcorr-1), (rcorr-1)))","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:38:37.208089Z","iopub.execute_input":"2022-05-15T22:38:37.208389Z","iopub.status.idle":"2022-05-15T22:38:37.214899Z","shell.execute_reply.started":"2022-05-15T22:38:37.208360Z","shell.execute_reply":"2022-05-15T22:38:37.214068Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Abhishek Sharma https://www.kaggle.com/code/anotherbadcode/apriori-analysis\n\ndef find_association(method, data, columns, plot = True, returnCorr= False):\n    \"\"\"\n    Finding associations b/w different metrics based on Cramer's rule.\n    \"\"\"\n    \n    df = data\n    cols = columns\n    corrM = np.zeros((len(cols),len(cols)))\n    np.fill_diagonal(corrM, 1)\n\n    for col1, col2 in itertools.combinations(cols, 2):\n        idx1, idx2 = cols.index(col1), cols.index(col2)\n        corrM[idx1, idx2] = cramers_v((pd.crosstab(df[col1], df[col2])).values)\n        corrM[idx2, idx1] = corrM[idx1, idx2]\n\n    corr = pd.DataFrame(corrM, index=cols, columns=cols)\n    \n    corr = round(corr, 2)\n    mask = np.triu(np.ones_like(corr, dtype=bool))\n    \n    if plot:\n        fig, ax = plt.subplots(figsize=(20, 20))\n        ax = sns.heatmap(corr, cmap='coolwarm', annot=True, ax=ax, mask=mask, \n                         vmax=1.0, vmin=-1.0, linewidths=0.1,\n                        annot_kws={\"size\": 9}, square=True, cbar=True); \n        ax.set_title(\"Correlation between Variables\");\n\n        plt.savefig(\"association.png\", dpi = 300);\n        plt.show()\n    \n    if returnCorr:\n        return corr","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:38:46.108561Z","iopub.execute_input":"2022-05-15T22:38:46.108824Z","iopub.status.idle":"2022-05-15T22:38:46.118753Z","shell.execute_reply.started":"2022-05-15T22:38:46.108794Z","shell.execute_reply":"2022-05-15T22:38:46.118128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Abhishek Sharma https://www.kaggle.com/code/anotherbadcode/apriori-analysis\n\ndef drawNetworkGraph(df, startNode, nCols = 9):\n    \"\"\"\n    Takes input DataFrame & plots network graph based on Association.\n    Edges are weighted using correlation.\n    df : Transactional DataFrame\n    StartNode : \n    \n    \"\"\"\n    weightDict = {}\n    cols = (df.sum() / df.shape[0]).sort_values(ascending=False).head(9).index.tolist()\n    corrDf = find_association(\"cramers_v\", df, cols, plot=False, returnCorr=True)\n    weights = corrDf[startNode].sort_values(ascending=False)\n\n    for key, value in zip(weights.index.tolist(), weights.values.tolist()):\n        weightDict[key] = value\n\n    combs = [x for x in itertools.combinations(weightDict.keys(), 2)]\n    \n    edge_width = [round(45 * corrDf[u][v] , 3) for u, v in combs]\n    \n    G = nx.Graph()\n    plt.figure(figsize =(10, 7))\n    G.add_node(startNode)\n    for items in weightDict.keys():\n        G.add_node(items)\n\n    for items in combs:\n        G.add_edge(items[0], items[1])\n    \n    pos = nx.fruchterman_reingold_layout(G)\n\n    nx.draw_networkx(G, pos, with_labels = True, arrowstyle='-|>',\n                     alpha = 0.7, width = edge_width,\n                     arrows=True, node_size = weights * 500,\n                     edge_color ='.7', cmap = plt.cm.Blues, node_color ='green') \n    \n    plt.axis('off')\n    plt.tight_layout();\n    \ndrawNetworkGraph(df, startNode = 'anomaly', nCols = 9)","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:41:49.813883Z","iopub.execute_input":"2022-05-15T22:41:49.814632Z","iopub.status.idle":"2022-05-15T22:42:40.764010Z","shell.execute_reply.started":"2022-05-15T22:41:49.814593Z","shell.execute_reply":"2022-05-15T22:42:40.763196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Replacing Missing Values.","metadata":{}},{"cell_type":"code","source":"# Lets first handle numerical features with nan value\nnumerical_nan = [feature for feature in df.columns if df[feature].isna().sum()>1 and df[feature].dtypes!='O']\nnumerical_nan","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:51:38.035862Z","iopub.execute_input":"2022-05-15T22:51:38.036179Z","iopub.status.idle":"2022-05-15T22:51:38.065797Z","shell.execute_reply.started":"2022-05-15T22:51:38.036148Z","shell.execute_reply":"2022-05-15T22:51:38.064902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[numerical_nan].isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:51:44.837692Z","iopub.execute_input":"2022-05-15T22:51:44.838533Z","iopub.status.idle":"2022-05-15T22:51:44.854538Z","shell.execute_reply.started":"2022-05-15T22:51:44.838492Z","shell.execute_reply":"2022-05-15T22:51:44.853712Z"},"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## Replacing the numerical Missing Values\n\nfor feature in numerical_nan:\n    ## We will replace by using median since there are outliers\n    median_value=df[feature].median()\n    \n    df[feature].fillna(median_value,inplace=True)\n    \ndf[numerical_nan].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:52:00.736583Z","iopub.execute_input":"2022-05-15T22:52:00.737403Z","iopub.status.idle":"2022-05-15T22:52:00.796178Z","shell.execute_reply.started":"2022-05-15T22:52:00.737358Z","shell.execute_reply":"2022-05-15T22:52:00.795309Z"},"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#imports \nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LinearRegression, Ridge, Lasso, ElasticNet\nfrom sklearn.tree import DecisionTreeRegressor\n\nfrom sklearn import metrics\n\nfrom sklearn.model_selection import cross_validate","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:52:51.506212Z","iopub.execute_input":"2022-05-15T22:52:51.506523Z","iopub.status.idle":"2022-05-15T22:52:51.862772Z","shell.execute_reply.started":"2022-05-15T22:52:51.506490Z","shell.execute_reply":"2022-05-15T22:52:51.861874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = df[\"meter_reading\"]  # numpy array\ny = df[\"anomaly\"] # numpy array","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:56:14.591356Z","iopub.execute_input":"2022-05-15T22:56:14.591672Z","iopub.status.idle":"2022-05-15T22:56:14.596678Z","shell.execute_reply.started":"2022-05-15T22:56:14.591638Z","shell.execute_reply":"2022-05-15T22:56:14.595764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Julie Tian  https://www.kaggle.com/julietian/predicting-steam-usage-per-location\n\nmodel = LinearRegression() #instantiate model\n\nX_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2) #20% for testing \n\n#required reshaping to fit and predict for the model\nX_train_reshape = X_train.values.reshape(-1,1)\nX_test_reshape = X_test.values.reshape(-1,1)","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:56:51.752291Z","iopub.execute_input":"2022-05-15T22:56:51.752801Z","iopub.status.idle":"2022-05-15T22:56:52.009199Z","shell.execute_reply.started":"2022-05-15T22:56:51.752761Z","shell.execute_reply":"2022-05-15T22:56:52.008244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#proper shape for modelling and predicting \nprint(X_train_reshape.shape)\nprint(y_train.shape)\n\nprint(X_test_reshape.shape)\nprint(y_test.shape)","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:57:33.711690Z","iopub.execute_input":"2022-05-15T22:57:33.712365Z","iopub.status.idle":"2022-05-15T22:57:33.717672Z","shell.execute_reply.started":"2022-05-15T22:57:33.712326Z","shell.execute_reply":"2022-05-15T22:57:33.716853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(X_train_reshape, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:57:49.926860Z","iopub.execute_input":"2022-05-15T22:57:49.927464Z","iopub.status.idle":"2022-05-15T22:57:49.999043Z","shell.execute_reply.started":"2022-05-15T22:57:49.927421Z","shell.execute_reply":"2022-05-15T22:57:49.998063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = model.predict(X_test_reshape)","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:58:05.133332Z","iopub.execute_input":"2022-05-15T22:58:05.134094Z","iopub.status.idle":"2022-05-15T22:58:05.140688Z","shell.execute_reply.started":"2022-05-15T22:58:05.134054Z","shell.execute_reply":"2022-05-15T22:58:05.140080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for y, y_pred in list(zip(y_test, predictions))[:5]:\n    print(\"Real value: {:.3f} Estimated value: {:.5f}\".format(y, y_pred))","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:58:19.943838Z","iopub.execute_input":"2022-05-15T22:58:19.944488Z","iopub.status.idle":"2022-05-15T22:58:20.051355Z","shell.execute_reply.started":"2022-05-15T22:58:19.944445Z","shell.execute_reply":"2022-05-15T22:58:20.050378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#The Competition metric is Area Under Receiver Operating Characteristic Curve (AUC-ROC). \n\nHowever, I didn't find yet another script with AUC/ROC to help me.","metadata":{}},{"cell_type":"code","source":"#Code by Julie Tian  https://www.kaggle.com/julietian/predicting-steam-usage-per-location\n\nrsq = metrics.r2_score(y_test, predictions)\nprint(f\"the R-squaared score is {rsq}\")\n\nmse = metrics.mean_squared_error(y_test, predictions)\nprint(f\"the Mean Absolute Error is {mse}\")\n\nrmse = np.sqrt(metrics.mean_squared_error(y_test, predictions))\nprint(f\"the Root Mean Squared Error is {rmse}\")","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:58:45.067193Z","iopub.execute_input":"2022-05-15T22:58:45.068027Z","iopub.status.idle":"2022-05-15T22:58:45.083451Z","shell.execute_reply.started":"2022-05-15T22:58:45.067979Z","shell.execute_reply":"2022-05-15T22:58:45.082361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results = {} #to store results ","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:59:14.627838Z","iopub.execute_input":"2022-05-15T22:59:14.628131Z","iopub.status.idle":"2022-05-15T22:59:14.632402Z","shell.execute_reply.started":"2022-05-15T22:59:14.628089Z","shell.execute_reply":"2022-05-15T22:59:14.631691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Julie Tian  https://www.kaggle.com/julietian/predicting-steam-usage-per-location\n\ndef evaluate_model(estimator, X, y):\n    cv_results = cross_validate(estimator,\n                    X=X,\n                    y=y,\n                    scoring=\"neg_mean_squared_error\",\n                          n_jobs=-1, cv=50,\n                     return_train_score=True)\n    return pd.DataFrame(cv_results).abs().mean().to_dict()","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:59:39.386927Z","iopub.execute_input":"2022-05-15T22:59:39.387441Z","iopub.status.idle":"2022-05-15T22:59:39.392415Z","shell.execute_reply.started":"2022-05-15T22:59:39.387396Z","shell.execute_reply":"2022-05-15T22:59:39.391628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"linreg  = LinearRegression()\ndtree   = DecisionTreeRegressor()\nelastic = ElasticNet()\nlasso   = Lasso()\nridge   = Ridge()","metadata":{"execution":{"iopub.status.busy":"2022-05-15T22:59:55.252091Z","iopub.execute_input":"2022-05-15T22:59:55.252541Z","iopub.status.idle":"2022-05-15T22:59:55.257524Z","shell.execute_reply.started":"2022-05-15T22:59:55.252496Z","shell.execute_reply":"2022-05-15T22:59:55.256851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Julie Tian  https://www.kaggle.com/julietian/predicting-steam-usage-per-location\n\nresults[\"linear reg\"] = evaluate_model(linreg, X_train_reshape, y_train)\nresults[\"tree\"] = evaluate_model(dtree, X_train_reshape, y_train)\nresults[\"elasticnet\"] = evaluate_model(elastic, X_train_reshape, y_train)\nresults[\"lasso\"] = evaluate_model(lasso, X_train_reshape, y_train)\nresults[\"ridge\"] = evaluate_model(ridge, X_train_reshape, y_train)\n\npd.DataFrame.from_dict(results).T","metadata":{"execution":{"iopub.status.busy":"2022-05-15T23:00:11.715987Z","iopub.execute_input":"2022-05-15T23:00:11.716272Z","iopub.status.idle":"2022-05-15T23:02:21.141306Z","shell.execute_reply.started":"2022-05-15T23:00:11.716243Z","shell.execute_reply":"2022-05-15T23:02:21.140322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from scipy.stats import norm\nimport statsmodels.api as sm\nimport matplotlib.pyplot as plt\n\nfrom statsmodels.tsa.seasonal import seasonal_decompose\nfrom statsmodels.tsa.stattools import adfuller","metadata":{"execution":{"iopub.status.busy":"2022-05-15T23:02:30.146809Z","iopub.execute_input":"2022-05-15T23:02:30.147779Z","iopub.status.idle":"2022-05-15T23:02:30.832088Z","shell.execute_reply.started":"2022-05-15T23:02:30.147724Z","shell.execute_reply":"2022-05-15T23:02:30.831079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(df[\"anomaly\"],df[\"meter_reading\"] );","metadata":{"execution":{"iopub.status.busy":"2022-05-15T23:02:43.023972Z","iopub.execute_input":"2022-05-15T23:02:43.024693Z","iopub.status.idle":"2022-05-15T23:02:46.300773Z","shell.execute_reply.started":"2022-05-15T23:02:43.024650Z","shell.execute_reply":"2022-05-15T23:02:46.299890Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_model_data = df[[\"anomaly\"]]\ntrain = train_model_data.iloc[0:(len(train_model_data)-53)].copy()\ntest = train_model_data.iloc[len(train):(len(train_model_data) -1)].copy()","metadata":{"execution":{"iopub.status.busy":"2022-05-15T23:03:38.501624Z","iopub.execute_input":"2022-05-15T23:03:38.501889Z","iopub.status.idle":"2022-05-15T23:03:38.517256Z","shell.execute_reply.started":"2022-05-15T23:03:38.501863Z","shell.execute_reply":"2022-05-15T23:03:38.516013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape","metadata":{"execution":{"iopub.status.busy":"2022-05-15T23:03:53.328130Z","iopub.execute_input":"2022-05-15T23:03:53.328953Z","iopub.status.idle":"2022-05-15T23:03:53.334572Z","shell.execute_reply.started":"2022-05-15T23:03:53.328910Z","shell.execute_reply":"2022-05-15T23:03:53.333960Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#And more charts that I don't know what's their meaning.","metadata":{}},{"cell_type":"code","source":"ax = train.plot(figsize=(25,4))\ntest.plot(ax=ax);","metadata":{"execution":{"iopub.status.busy":"2022-05-15T23:04:24.543408Z","iopub.execute_input":"2022-05-15T23:04:24.543878Z","iopub.status.idle":"2022-05-15T23:04:30.612744Z","shell.execute_reply.started":"2022-05-15T23:04:24.543838Z","shell.execute_reply":"2022-05-15T23:04:30.611881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sm.graphics.tsa.plot_pacf(train,lags=30)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-05-15T23:05:05.318013Z","iopub.execute_input":"2022-05-15T23:05:05.318321Z","iopub.status.idle":"2022-05-15T23:05:07.734340Z","shell.execute_reply.started":"2022-05-15T23:05:05.318288Z","shell.execute_reply":"2022-05-15T23:05:07.733717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#It took so long that I commented it.\n\n#sm.graphics.tsa.plot_acf(train,lags=50)\n#plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-05-15T23:05:29.542759Z","iopub.execute_input":"2022-05-15T23:05:29.543484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Acknowledgements: \n\nAbhishek Sharma https://www.kaggle.com/code/anotherbadcode/apriori-analysis\n\nDasmehdixtr https://www.kaggle.com/code/dasmehdixtr/energy-anomally-detection-65-test-set-accuracy/notebook\n\nJulie Tian  https://www.kaggle.com/julietian/predicting-steam-usage-per-location\n\nClayton Miller https://www.kaggle.com/claytonmiller/weather-influence-on-energy-consumption-example","metadata":{}}]}