Docsity

IOT Practical 7 code TE AIDS SPPU 2024 Pattern, Study Guides, Projects, Research of Internet and Information Access

Toggle sidebar
bg1
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.preprocessing import MinMaxScaler
# Sample IoT data
df = pd.DataFrame({
"temp": [22, 23, np.nan, 25, 100, 24, 23, 22],
"hum": [55, 56, 54, np.nan, 300, 57, 58, 59]
})
# 1. Remove simple outliers FIRST
df = df[(df["temp"] < 50) & (df["hum"] < 100)]
# 2. Cleaning (fill missing values with untainted median)
df.fillna(df.median(), inplace=True)
# 3. Reset index so the plot X-axis doesn't skip the missing outlier row
df.reset_index(drop=True, inplace=True)
# 4. Normalization
scaler = MinMaxScaler()
df[["temp_n", "hum_n"]] = scaler.fit_transform(df[["temp", "hum"]])
# 5. Visualization
plt.plot(df["temp_n"], label="Temp")
plt.plot(df["hum_n"], label="Humidity")
plt.xlabel("Sample Index")
plt.ylabel("Normalized Value (0-1)")
plt.title("Cleaned & Normalized IoT Sensor Data")
plt.legend()
plt.show()
OUTPUT:

Partial preview of the text

Download IOT Practical 7 code TE AIDS SPPU 2024 Pattern and more Study Guides, Projects, Research Internet and Information Access in PDF only on Docsity!

import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn.preprocessing import MinMaxScaler

Sample IoT data

df = pd.DataFrame({ "temp": [22, 23, np.nan, 25, 100, 24, 23, 22], "hum": [55, 56, 54, np.nan, 300, 57, 58, 59] })

1. Remove simple outliers FIRST

df = df[(df["temp"] < 50) & (df["hum"] < 100)]

2. Cleaning (fill missing values with untainted median)

df.fillna(df.median(), inplace=True)

3. Reset index so the plot X-axis doesn't skip the missing outlier row

df.reset_index(drop=True, inplace=True)

4. Normalization

scaler = MinMaxScaler() df[["temp_n", "hum_n"]] = scaler.fit_transform(df[["temp", "hum"]])

5. Visualization

plt.plot(df["temp_n"], label="Temp") plt.plot(df["hum_n"], label="Humidity") plt.xlabel("Sample Index") plt.ylabel("Normalized Value (0-1)") plt.title("Cleaned & Normalized IoT Sensor Data") plt.legend() plt.show()

OUTPUT: