Day 65 of 100DaysofML

Charan Soneji
100DaysofMLcode
Published in
4 min readSep 1, 2020

Usage of ML models in IOT. This is one of the aspects which not a lot of people look at but ML can be used even in creating models that monitor IOT devices. ML and data science can be used in order to identify and manage the usage of IOT appliances. It can help in analyzing the amount of energy and appliance usage and help in order to switch to a more energy efficient mechanism. How do you think this is done? Using ML. ML helps in identifying the earlier usage patterns and help in reducing the usage by reducing the overall energy usage.

Let us get to the analysis and development of a model.

The first step would be to import all the packages and importing the dataset.

import pandas as pd
import numpy as np
#Loading csv into environment
data=pd.read_csv('../input/smart-home-dataset-with-weather-information/HomeC.csv')
data.head()
Data.head()

Familiarizing yourself with the dataset.

# removing the truncated record
data=data[:-1]
data.shape
Data.shape()

Trying to analyze the data with increments in terms of minutes from the dataset and dropping the unwanted columns.

#new daterange in increments of minutes
time_index = pd.date_range('2016-01-01 05:00', periods=len(data), freq='min')
time_index = pd.DatetimeIndex(time_index)
data['time']=time_index
#changing column names before doing some calculation as they look weird with "[kw]"
data.columns=['time', 'use', 'gen', 'House overall', 'Dishwasher',
'Furnace 1', 'Furnace 2', 'Home office', 'Fridge',
'Wine cellar', 'Garage door', 'Kitchen 12',
'Kitchen 14', 'Kitchen 38', 'Barn', 'Well',
'Microwave', 'Living room', 'Solar', 'temperature',
'icon', 'humidity', 'visibility', 'summary', 'apparentTemperature',
'pressure', 'windSpeed', 'cloudCover', 'windBearing', 'precipIntensity',
'dewPoint', 'precipProbability']
data=data.drop('House overall',axis=1)#getting hour, day,week, month from the date column
data['day']= data['time'].dt.day
data['month']= data['time'].dt.month
data['week']= data['time'].dt.week
data['hour']= data['time'].dt.hour

Visualizing the data is the next step in the process and I shall explain how these plots can be used for analytics.

def visualize(label, cols):
fig,ax=plt.subplots(figsize=(14,8))
colour= ['red','green','blue','yellow']
for colour,col in zip(colour,cols):
data.groupby(label)[col].mean().plot(ax=ax,label=col,color=colour)
plt.legend()
visualize('hour',['Furnace 1','Furnace 2'])
Comparing energy difference between two furnaces-ON HOURLY BASIS

The above diagram compares the energy usage between two different furnaces on an HOURLY BASIS in the same house and shows how one is different from the other.

Comparing energy difference between two furnaces-ON DAY TO DAY BASIS

The above graph compares the energy usage on a day to day basis and based on the given analysis, different models can be generated. Similarly, we shall be comparing the energy usage in 2 different kitchens on a monthly and weekly basis.

visualize('week',['Kitchen 12','Kitchen 14','Kitchen 38'])
Energy consumption in a kitchen on weekly basis.
visualize('month',['Kitchen 12','Kitchen 14','Kitchen 38'])

We can also create subplots to visualize them in a much better way.

data.groupby('hour')['Kitchen38'].mean().plot(ax=ax[0,0],color='green',label= 'kitchen 38')
data.groupby('day')['Kitchen38'].mean().plot(ax=ax[0,1],color='green',label= 'kitchen 38')
data.groupby('week')['Kitchen38'].mean().plot(ax=ax[1,0],color='green',label= 'kitchen 38')
data.groupby('month')['Kitchen38'].mean().plot(ax=ax[1,1],color='green',label= 'kitchen 38')

plt.legend()
Kitchen usage of energy in a day, week, month and in an hour.

I shall be sharing the entire notebook below but one of the graphs which gives us a rough overview of the overall energy usage is mentioned below:

Overall energy comparison amongst different appliances.

The link to the notebook is mentioned below:

In tomorrow's blog. I shall mention about creating a model for the comparison of energy.

Thanks for reading. Keep Learning.

Cheers.

--

--