import pandas as pd
import warnings
from tqdm import tqdm
from time import sleep
warnings.filterwarnings('ignore')
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
import matplotlib.pyplot as plt
import seaborn as sns


WaterData_Load = pd.read_csv("WaterData/DataSet.csv")
WaterData_Load = WaterData_Load.head()
print(WaterData_Load)

X = WaterData_Load[['Temperature', 'Humidity', 'Rainfall_Forcasting', 'Water_level', 'Light']]
y = WaterData_Load['Filling_Time_Minutes']

# Train Test split DataSet for ML
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20)

#  Fitting RandomForestClassifier
rf = RandomForestClassifier()
rf.fit(X_train, y_train)

# Dataload
for i in tqdm(range(5)):
    sleep(0.4)

# ML prediction
new_input = [[28, 29, 27, 0.5, 26]]
pred = rf.predict(new_input)
print(int(pred))


feature_imp = pd.Series(rf.feature_importances_,index= WaterData_Load['Filling_Time_Minutes']).sort_values(ascending=False)
sns.barplot(x=feature_imp, y=feature_imp.index)
# Add labels to your graph
plt.xlabel('Feature Importance')
plt.ylabel('Features')
plt.title("Visualizing Important Features")
plt.legend()

# Accurac Level
Y_pred_rf = rf.predict(X_test)
current_accuracy = round(accuracy_score(Y_pred_rf, y_test) * 100, 2)
print(current_accuracy)


