# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory

import os
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        print(os.path.join(dirname, filename))

# 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" 
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.simplefilter("ignore")
from sklearn.model_selection import train_test_split
plt.rcParams.update({'font.size': 12})
plt.rcParams["figure.figsize"] = (10,5)
"""
# Inputting and Understanding Data
"""
df=pd.read_csv('/kaggle/input/room-occupancy/file.csv')
df.head()
df.count()
df.describe()
"""
# EDA + Preprocessing
"""
df.hist()
sns.heatmap(df.corr(), annot=True, fmt='.1g', cmap="viridis",);
raw_df=df.drop('Humidity',axis=1)
raw_df.head()
sns.heatmap(raw_df.corr(), annot=True, fmt='.1g', cmap="viridis",);
"""
# Model Building
"""
X = raw_df.drop('Occupancy', axis=1)
Y = raw_df['Occupancy']
X_train, X_test, Y_train, Y_test = train_test_split(X,Y,test_size=0.2)
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.tree import DecisionTreeClassifier
from xgboost import XGBClassifier
from sklearn.svm import SVC
model = LogisticRegression()
model.fit(X_train,Y_train)
Y_pred=model.predict(X_test)
LRScore = model.score(X_test,Y_test)
print("Accuracy for Method 1 - Logistic Regression:",LRScore*100)
model1 = RandomForestClassifier()
model1.fit(X_train,Y_train)
Y_pred_rf=model1.predict(X_test)
RandomForestClassifierScore = model.score(X_test,Y_test)
print("Accuracy obtained for Method 2 - Random Forest Classifier :",RandomForestClassifierScore*100)
tree = DecisionTreeClassifier()
tree.fit(X_train,Y_train)
DecisionTreeClassifierScore = tree.score(X_test,Y_test)
print("Accuracy obtained by Decision Tree Classifier model:",DecisionTreeClassifierScore*100)
modelXGB = XGBClassifier(n_estimators=100, subsample=0.9, colsample_bynode=0.2)
modelXGB.fit(X_train,Y_train)
preds=modelXGB.predict(X_test)
XGBScore=modelXGB.score(X_test,Y_test)
print("Accuracy obtained by XGB model:",XGBScore*100)
KNN_model = KNeighborsClassifier(n_neighbors=7, metric='manhattan', weights='distance')
KNN_model.fit(X_train, Y_train)
KNN_model.score(X_test, Y_test)*100
SVC_model = SVC()
SVC_model.fit(X_train,Y_train)
SVC_model.score(X_test, Y_test)*100
"""
# Predicting on overall Dataset with XGBoost
"""
final_df=pd.DataFrame(columns = ['Actual', 'Predicted'])
finalPreds=modelXGB.predict(X)
final_df['Actual']=Y
final_df['Predicted']=finalPreds
final_df.head()
XGBScore=modelXGB.score(X,Y)
print("Accuracy obtained by XGB model:",XGBScore*100)