File size: 757 Bytes
6e2fccb
edce0df
 
 
e30a662
 
edce0df
 
 
 
 
e30a662
 
 
 
6e2fccb
 
 
 
 
 
 
 
 
edce0df
6e2fccb
 
edce0df
 
 
f81298d
12a620b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from joblib import dump, load
from datetime import datetime
import pytz

MODEL_PATH = "heating_model.pkl"
DATA_PATH = "mantle_training.csv"
HISTORY = []

def get_ist_time():
    ist = pytz.timezone('Asia/Kolkata')
    return datetime.now(ist).strftime("%Y-%m-%d %H:%M:%S %Z")

def train_and_save_model():
    data = pd.read_csv(DATA_PATH)
    X = data[["temperature", "duration"]]
    y = data["risk_level"]
    model = RandomForestClassifier()
    model.fit(X, y)
    dump(model, MODEL_PATH)
    return model

def load_model():
    if not os.path.exists(MODEL_PATH):
        return train_and_save_model()
    return load(MODEL_PATH)

model = load_model()

def predict_risk_