text_html_output_1.png
from sklearn.linear_model import Lasso

from sklearn.preprocessing import StandardScaler

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

df = pd.read_csv('room_occupancy_estimation_dataset.csv')

df.shape

df[df.duplicated()]

df.drop(columns=['Date', 'Time'], axis=1, inplace=True)

df[df.duplicated()]

# Setting output to have 5 subplots in a single row
fig, ax = plt.subplots(1, 5, figsize=(10, 5))

# To tune the spacing between the subplots
plt.subplots_adjust(wspace=0.5) 

# Drawing boxplot for S1_Light in the 1st subplot
sns.violinplot(data=df['S1_Light'], ax=ax[0], color='brown')
ax[0].set_xlabel('S1_Light')

# Drawing boxplot for S2_Light in the 1st subplot
sns.violinplot(data=df['S2_Light'], ax=ax[1], color='g')
ax[1].set_xlabel('S2_Light')

# Drawing boxplot for S3_Light in the 1st subplot
sns.violinplot(data=df['S3_Light'], ax=ax[2])
ax[2].set_xlabel('S3_Light')

# Drawing boxplot for S4_Light in the 1st subplot
sns.violinplot(data=df['S4_Light'], ax=ax[3], color='y')
ax[3].set_xlabel('S4_Light')

# Drawing boxplot for S5_CO2 in the 1st subplot
sns.violinplot(data=df['S5_CO2'], ax=ax[4], color = 'b')
ax[4].set_xlabel('S5_CO2')

# by default, you'll see x-tick label set to 0 in each subplot
# remove it by setting it to empty list
for subplot in ax:
    subplot.set_xticklabels([])
    
plt.show()

fig, axes = plt.subplots(nrows=5, ncols=4, figsize=(20, 15))
for idx, feat in enumerate(df.columns.to_list(), start=0):
    ax = axes[int(idx / 4), idx % 4]
    sns.boxplot(x="Room_Occupancy_Count", y=feat, data=df, ax=ax)
    ax.set_xlabel("")
    ax.set_ylabel(feat)
fig.tight_layout();

X = df.drop(['Room_Occupancy_Count'], axis=1)
y = df[['Room_Occupancy_Count']]

scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)

lasso_reg = Lasso()
lasso_reg.fit(X_scaled, y)