{"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":"markdown","source":"Abdulrahman Emad 18101010\nMohamed Yasser Anwar 18100585\nMohamed Ashraf 18100765","metadata":{}},{"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)\nfrom sklearn.tree import DecisionTreeRegressor\nfrom sklearn import linear_model\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import mean_squared_error,mean_absolute_error\nimport matplotlib.pyplot as plt\nimport datetime\nfrom sklearn import metrics\nimport seaborn as sns\nimport sklearn.ensemble as ske\nimport gc\nfrom sklearn.linear_model import LinearRegression,SGDRegressor,ElasticNet,Ridge\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\nDATA_PATH = \"../input/ashrae-energy-prediction/\"\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-01-12T21:30:22.946410Z","iopub.execute_input":"2022-01-12T21:30:22.947701Z","iopub.status.idle":"2022-01-12T21:30:22.964674Z","shell.execute_reply.started":"2022-01-12T21:30:22.947643Z","shell.execute_reply":"2022-01-12T21:30:22.963439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **** Loading Data","metadata":{}},{"cell_type":"code","source":"Weather_Train = pd.read_csv(DATA_PATH + 'weather_train.csv')\nWeather_Test= weather_df = pd.read_csv(DATA_PATH + 'weather_test.csv')\nTest= pd.read_csv(DATA_PATH +'test.csv')\nTrain= pd.read_csv(DATA_PATH +'train.csv')\nBuilding= pd.read_csv(DATA_PATH +'building_metadata.csv')","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:22.966990Z","iopub.execute_input":"2022-01-12T21:30:22.967532Z","iopub.status.idle":"2022-01-12T21:30:27.619168Z","shell.execute_reply.started":"2022-01-12T21:30:22.967490Z","shell.execute_reply":"2022-01-12T21:30:27.614319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **** About the data","metadata":{}},{"cell_type":"code","source":"#Function that prints Shape of the data, Columns and their datatype, Head of the data, Description of the data, number of nulls in the data\n# and Year of the data and The Percentage of missing values in the dataset\ndef Data_info(filename):\n    path = \"../input/ashrae-energy-prediction\"\n    df = pd.read_csv('{0}/{1}'.format(path,filename))\n    print(\"~~~~~~Shape of the data~~~~~~ : \",df.shape)\n    print(\"~~~~~~Columns and their datatype~~~~~~ : \")\n    print(df.info())\n    print(\"~~~~~~Quick Look at the data~~~~~~ : \")\n    print(df.head())\n    print(\"~~~~~~Description of the data~~~~~~ : \")\n    print(df.describe())\n    print(\"~~~~~~number of nulls in the data~~~~~~ : \")\n    print(df.isna().sum())\n    if 'timestamp' in df.columns: \n        df['timestamp'] = pd.to_datetime(df['timestamp'],format = \"%Y-%m-%d %H:%M:%S\")\n        print(\"~~~~~~Year of the data~~~~~~ :\")\n        print(df.timestamp.dt.year.unique())\n    print(\"~~~~~~Percentage of missing values in the dataset~~~~~~\")\n    print(df.isna().sum()/len(df)*100)\n    return df","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.620411Z","iopub.status.idle":"2022-01-12T21:30:27.620814Z","shell.execute_reply.started":"2022-01-12T21:30:27.620611Z","shell.execute_reply":"2022-01-12T21:30:27.620631Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Using (\"Data_info\") function to get 'train.csv' info\ntrain = Data_info('train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.622296Z","iopub.status.idle":"2022-01-12T21:30:27.622755Z","shell.execute_reply.started":"2022-01-12T21:30:27.622520Z","shell.execute_reply":"2022-01-12T21:30:27.622545Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Using (\"Data_info\") function to get 'test.csv' info\ntest = Data_info('test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.624823Z","iopub.status.idle":"2022-01-12T21:30:27.625184Z","shell.execute_reply.started":"2022-01-12T21:30:27.624993Z","shell.execute_reply":"2022-01-12T21:30:27.625018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Using (\"Data_info\") function to get 'weather_train.csv' info\nwtrain = Data_info('weather_train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.626887Z","iopub.status.idle":"2022-01-12T21:30:27.627226Z","shell.execute_reply.started":"2022-01-12T21:30:27.627052Z","shell.execute_reply":"2022-01-12T21:30:27.627074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Using (\"Data_info\") function to get 'weather_test.csv' info\nwtest = Data_info('weather_test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.628697Z","iopub.status.idle":"2022-01-12T21:30:27.629130Z","shell.execute_reply.started":"2022-01-12T21:30:27.628903Z","shell.execute_reply":"2022-01-12T21:30:27.628934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Using (\"Data_info\") function to get 'building_metadata.csv' info\nbuilding = Data_info('building_metadata.csv')","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.632454Z","iopub.status.idle":"2022-01-12T21:30:27.632901Z","shell.execute_reply.started":"2022-01-12T21:30:27.632667Z","shell.execute_reply":"2022-01-12T21:30:27.632693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Function That reduces the used memory\ndef reduce_mem_usage(df):\n    \"\"\" iterate through all the columns of a dataframe and modify the data type\n        to reduce memory usage.        \n    \"\"\"\n    start_mem = df.memory_usage().sum() / 1024**2\n    print('Memory usage of dataframe is {:.2f} MB'.format(start_mem))\n    \n    for col in df.columns:\n        col_type = df[col].dtype\n        \n        if col_type != object:\n            c_min = df[col].min()\n            c_max = df[col].max()\n            if str(col_type)[:3] == 'int':\n                if c_min > np.iinfo(np.int8).min and c_max < np.iinfo(np.int8).max:\n                    df[col] = df[col].astype(np.int8)\n                elif c_min > np.iinfo(np.int16).min and c_max < np.iinfo(np.int16).max:\n                    df[col] = df[col].astype(np.int16)\n                elif c_min > np.iinfo(np.int32).min and c_max < np.iinfo(np.int32).max:\n                    df[col] = df[col].astype(np.int32)\n                elif c_min > np.iinfo(np.int64).min and c_max < np.iinfo(np.int64).max:\n                    df[col] = df[col].astype(np.int64)  \n            else:\n                if c_min > np.finfo(np.float16).min and c_max < np.finfo(np.float16).max:\n                    df[col] = df[col].astype(np.float16)\n                elif c_min > np.finfo(np.float32).min and c_max < np.finfo(np.float32).max:\n                    df[col] = df[col].astype(np.float32)\n                else:\n                    df[col] = df[col].astype(np.float64)\n        else:\n            df[col] = df[col].astype('category')\n\n    end_mem = df.memory_usage().sum() / 1024**2\n    print('Memory usage after optimization is: {:.2f} MB'.format(end_mem))\n    print('Decreased by {:.1f}%'.format(100 * (start_mem - end_mem) / start_mem))\n    return df","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.635959Z","iopub.status.idle":"2022-01-12T21:30:27.636470Z","shell.execute_reply.started":"2022-01-12T21:30:27.636191Z","shell.execute_reply":"2022-01-12T21:30:27.636219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#using reduce_mem_usage function to reduce memory usage\nTrain = reduce_mem_usage(Train)\nTest = reduce_mem_usage(Test)\nWeather_Train = reduce_mem_usage(Weather_Train)\nWeather_Test = reduce_mem_usage(Weather_Test)\nBuilding = reduce_mem_usage(Building)","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.637816Z","iopub.status.idle":"2022-01-12T21:30:27.638300Z","shell.execute_reply.started":"2022-01-12T21:30:27.638021Z","shell.execute_reply":"2022-01-12T21:30:27.638049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **EDA**","metadata":{}},{"cell_type":"code","source":"#Merging tables\nresults = Building.merge(Train,left_on='building_id',right_on='building_id',how='left')\ndata = results.merge(Weather_Train,left_on=['site_id','timestamp'],right_on=['site_id','timestamp'],how='left')\ndata.columns","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.639841Z","iopub.status.idle":"2022-01-12T21:30:27.640188Z","shell.execute_reply.started":"2022-01-12T21:30:27.640006Z","shell.execute_reply":"2022-01-12T21:30:27.640028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Function that sets up the hist plot and its dimension\ndef plot_hist(df,var_name):\n    plt.figure(figsize=(17,8))\n    plt.hist(df[var_name],bins = 50)\n    plt.title(f\"Histogram - {var_name}\")\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.641658Z","iopub.status.idle":"2022-01-12T21:30:27.642102Z","shell.execute_reply.started":"2022-01-12T21:30:27.641845Z","shell.execute_reply":"2022-01-12T21:30:27.641874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Hist plot for 'year_built'\nplot_hist(Building,'year_built')","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.643703Z","iopub.status.idle":"2022-01-12T21:30:27.644251Z","shell.execute_reply.started":"2022-01-12T21:30:27.643905Z","shell.execute_reply":"2022-01-12T21:30:27.643930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Hist plot for 'floor_count'\nplot_hist(Building,'floor_count')","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.646334Z","iopub.status.idle":"2022-01-12T21:30:27.646814Z","shell.execute_reply.started":"2022-01-12T21:30:27.646570Z","shell.execute_reply":"2022-01-12T21:30:27.646596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Hist plot for 'cloud_coverage'\nplot_hist(data,'cloud_coverage')","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.649230Z","iopub.status.idle":"2022-01-12T21:30:27.649938Z","shell.execute_reply.started":"2022-01-12T21:30:27.649727Z","shell.execute_reply":"2022-01-12T21:30:27.649751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Hist plot for 'wind_speed'\nplot_hist(data,'wind_speed')","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.651462Z","iopub.status.idle":"2022-01-12T21:30:27.651834Z","shell.execute_reply.started":"2022-01-12T21:30:27.651645Z","shell.execute_reply":"2022-01-12T21:30:27.651672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Hist plot for 'dew_temperature','air_temperature' & 'wind_speed'\nfor var in ['dew_temperature','air_temperature','wind_speed']:\n    plot_hist(Weather_Train,var)","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.653067Z","iopub.status.idle":"2022-01-12T21:30:27.653552Z","shell.execute_reply.started":"2022-01-12T21:30:27.653232Z","shell.execute_reply":"2022-01-12T21:30:27.653307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Scatter plot between Air Temperature and Meter Reading\nsns.scatterplot(x='air_temperature', y='meter_reading', data=data)","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.655141Z","iopub.status.idle":"2022-01-12T21:30:27.655520Z","shell.execute_reply.started":"2022-01-12T21:30:27.655309Z","shell.execute_reply":"2022-01-12T21:30:27.655331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Scatter plot between Cloud Coverage and Meter Reading\n#sns.scatterplot(x='cloud_coverage', y='meter_reading', hue='year_built',data=data)\n#it works but it takes a lot of time to run","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.657314Z","iopub.status.idle":"2022-01-12T21:30:27.657779Z","shell.execute_reply.started":"2022-01-12T21:30:27.657508Z","shell.execute_reply":"2022-01-12T21:30:27.657530Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Boxplots for Meter reading for Floorcounts\nfig, axes = plt.subplots(1, 1, figsize=(14, 6))\nsns.boxplot(x='floor_count', y='meter_reading', data=data, showfliers=False);","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.659070Z","iopub.status.idle":"2022-01-12T21:30:27.659458Z","shell.execute_reply.started":"2022-01-12T21:30:27.659232Z","shell.execute_reply":"2022-01-12T21:30:27.659262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Boxplots for 'site_id' and 'dew_temperature'\nfig, axes = plt.subplots(1, 1, figsize=(14, 6))\nsns.boxplot(x='site_id', y='dew_temperature', data=data, showfliers=False);","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.660880Z","iopub.status.idle":"2022-01-12T21:30:27.661208Z","shell.execute_reply.started":"2022-01-12T21:30:27.661034Z","shell.execute_reply":"2022-01-12T21:30:27.661058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Heatmap for the correlation between the columns and themselvs\ncorrmat=data.corr()\nfig,ax=plt.subplots(figsize=(12,10))\nsns.heatmap(corrmat,annot=True,annot_kws={'size': 12})","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.662883Z","iopub.status.idle":"2022-01-12T21:30:27.663204Z","shell.execute_reply.started":"2022-01-12T21:30:27.663034Z","shell.execute_reply":"2022-01-12T21:30:27.663056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Features Engineering**","metadata":{}},{"cell_type":"code","source":"#dropping unnecessary columns\ndata = data.drop(columns=['year_built', 'floor_count', 'wind_direction', 'dew_temperature'])","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.664904Z","iopub.status.idle":"2022-01-12T21:30:27.665260Z","shell.execute_reply.started":"2022-01-12T21:30:27.665070Z","shell.execute_reply":"2022-01-12T21:30:27.665095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#fixing timestamp and taking only the day and the month and then dropping timestamp column\ndata[\"timestamp\"] = pd.to_datetime(data[\"timestamp\"])\ndata[\"day\"]= data[\"timestamp\"].dt.day\ndata[\"month\"]= data[\"timestamp\"].dt.month\ndata= data.drop(\"timestamp\", axis = 1)","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.667363Z","iopub.status.idle":"2022-01-12T21:30:27.667762Z","shell.execute_reply.started":"2022-01-12T21:30:27.667551Z","shell.execute_reply":"2022-01-12T21:30:27.667580Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Printing the \"Percentage of missing values\" to see what is going to be dropped and what is going to be filled\nprint(\"Percentage of missing values in the data dataset\")\ndata.isna().sum()/len(data)*100","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.668741Z","iopub.status.idle":"2022-01-12T21:30:27.669100Z","shell.execute_reply.started":"2022-01-12T21:30:27.668911Z","shell.execute_reply":"2022-01-12T21:30:27.668937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Since there is a problem in printing the columns, instead printing head of the data besides the columns inside (\"data\")\ndata.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.672266Z","iopub.status.idle":"2022-01-12T21:30:27.672628Z","shell.execute_reply.started":"2022-01-12T21:30:27.672443Z","shell.execute_reply":"2022-01-12T21:30:27.672467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#setting a list of integer ranging from 0 to length of data as index\ndata = data.reset_index()","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.673826Z","iopub.status.idle":"2022-01-12T21:30:27.674207Z","shell.execute_reply.started":"2022-01-12T21:30:27.673990Z","shell.execute_reply":"2022-01-12T21:30:27.674020Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Change data type to float 32 for filling NA value before transforming them into int for smooth modeling processing\ndata['wind_speed'] = data['wind_speed'].astype('float32')\ndata['air_temperature'] = data['air_temperature'].astype('float32')\ndata['precip_depth_1_hr'] = data['precip_depth_1_hr'].astype('float32')\ndata['cloud_coverage'] = data['cloud_coverage'].astype('float32')","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.675764Z","iopub.status.idle":"2022-01-12T21:30:27.676139Z","shell.execute_reply.started":"2022-01-12T21:30:27.675956Z","shell.execute_reply":"2022-01-12T21:30:27.675986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Filling Null Values\ndata['precip_depth_1_hr'].fillna(data['precip_depth_1_hr'].mean(), inplace = True)\ndata['cloud_coverage'].fillna(data['cloud_coverage'].mean(), inplace = True)\ndata['wind_speed'].fillna(data['wind_speed'].mean(), inplace=True)\ndata['air_temperature'].fillna(data['air_temperature'].mean(), inplace=True)\n\n# Printing the sum of nulls inside the columns\ndata.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.677737Z","iopub.status.idle":"2022-01-12T21:30:27.678182Z","shell.execute_reply.started":"2022-01-12T21:30:27.677938Z","shell.execute_reply":"2022-01-12T21:30:27.677965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#printing the shape of the \"results\"\nresults.shape","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.679681Z","iopub.status.idle":"2022-01-12T21:30:27.680013Z","shell.execute_reply.started":"2022-01-12T21:30:27.679834Z","shell.execute_reply":"2022-01-12T21:30:27.679857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#printing the columns of the \"results\"\nresults.columns","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.681218Z","iopub.status.idle":"2022-01-12T21:30:27.681573Z","shell.execute_reply.started":"2022-01-12T21:30:27.681395Z","shell.execute_reply":"2022-01-12T21:30:27.681419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#printing the shape of the \"data\"\ndata.shape","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.683484Z","iopub.status.idle":"2022-01-12T21:30:27.683798Z","shell.execute_reply.started":"2022-01-12T21:30:27.683634Z","shell.execute_reply":"2022-01-12T21:30:27.683654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#printing the shape of the \"data\"\ndata.columns","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.684906Z","iopub.status.idle":"2022-01-12T21:30:27.685336Z","shell.execute_reply.started":"2022-01-12T21:30:27.685095Z","shell.execute_reply":"2022-01-12T21:30:27.685126Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Linear Model**","metadata":{}},{"cell_type":"code","source":"# Here column 'primaty_use' was treated by get_dummies function and get_dummies is used for data manipulation\ndata_linearR = pd.get_dummies(data, columns=['primary_use'])","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.686661Z","iopub.status.idle":"2022-01-12T21:30:27.687023Z","shell.execute_reply.started":"2022-01-12T21:30:27.686809Z","shell.execute_reply":"2022-01-12T21:30:27.686831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#printing the columns of \"data_linearR\"\ndata_linearR.columns","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.687975Z","iopub.status.idle":"2022-01-12T21:30:27.688334Z","shell.execute_reply.started":"2022-01-12T21:30:27.688148Z","shell.execute_reply":"2022-01-12T21:30:27.688179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Using the important features \nX =data_linearR[['building_id', 'meter', 'air_temperature', 'wind_speed', 'precip_depth_1_hr', 'cloud_coverage',\n       'square_feet', 'primary_use_Education', 'primary_use_Entertainment/public assembly',\n       'primary_use_Food sales and service', 'primary_use_Healthcare',\n       'primary_use_Lodging/residential',\n       'primary_use_Manufacturing/industrial', 'primary_use_Office',\n       'primary_use_Other', 'primary_use_Parking',\n       'primary_use_Public services', 'primary_use_Religious worship',\n       'primary_use_Retail', 'primary_use_Services',\n       'primary_use_Technology/science', 'primary_use_Utility',\n       'primary_use_Warehouse/storage', 'month', 'day']]\n\n# Create target variable\ny = data_linearR['meter_reading']\n\n# Train, test, split\n\nX_train, X_test, y_train, y_test = train_test_split(X,y, test_size = .20, random_state= 0)","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.689803Z","iopub.status.idle":"2022-01-12T21:30:27.690152Z","shell.execute_reply.started":"2022-01-12T21:30:27.689978Z","shell.execute_reply":"2022-01-12T21:30:27.690000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Create linear regression object\nregressor = LinearRegression()\n\n# Fit model to training data\nregressor.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.691709Z","iopub.status.idle":"2022-01-12T21:30:27.692142Z","shell.execute_reply.started":"2022-01-12T21:30:27.691962Z","shell.execute_reply":"2022-01-12T21:30:27.691988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Predicting test set results\ny_pred = regressor.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.694630Z","iopub.status.idle":"2022-01-12T21:30:27.695021Z","shell.execute_reply.started":"2022-01-12T21:30:27.694832Z","shell.execute_reply":"2022-01-12T21:30:27.694854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Printing R^2 and the accuracy of the linear model\nprint('Accuracy %d', regressor.score(X_test, y_test))\nprint('R^2 =', metrics.explained_variance_score(y_test,y_pred))\nregressor.score(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-01-12T21:30:27.695885Z","iopub.status.idle":"2022-01-12T21:30:27.696252Z","shell.execute_reply.started":"2022-01-12T21:30:27.696049Z","shell.execute_reply":"2022-01-12T21:30:27.696072Z"},"trusted":true},"execution_count":null,"outputs":[]}]}