About data set:

https://www.kaggle.com/laavanya/stress-level-detection Humidity – Temperature – Step count – Stress levels” represents the titles for Stress-Lysis.csv file. Based on the human’s physical activity, the stress levels of the human being are detected and analyzed here. A dataset of 2001 samples is provided for human body humidity, body temperature and the number of steps taken by the user. Three different classifications of stress are performed, low stress, normal stress, and high stress

Code for Fold RM


def main():
    model, data = Stress()

    data_train, data_test = split_data(data, ratio=0.8)

    start = timer()
    model.fit(data_train, ratio=0.5)
    end = timer()

    model.print_asp(simple=True)
    Y = [d[-1] for d in data_test]
    Y_test_hat = model.predict(data_test)
    acc = get_scores(Y_test_hat, data_test)
    print('% acc', round(acc, 4), '# rules', len(model.crs))
    acc, p, r, f1 = scores(Y_test_hat, Y, weighted=True)
    print('% acc', round(acc, 4), 'macro p r f1', round(p, 4), round(r, 4), round(f1, 4), '# rules', len(model.crs))
    print('% foldrm costs: ', timedelta(seconds=end - start), '\n')

    k = 1
    for i in range(len(data_test)):
        print('Explanation for example number', k, ':')
        print(model.explain(data_test[i]))
        print('Proof Tree for example number', k, ':')
        print(model.proof(data_test[i]))
        k += 1

Dataset.py

def Stress():
    attrs = ['Humidity','Temperature','Step count']
    nums = ['Humidity','Temperature','Step count']
    model = Classifier(attrs=attrs, numeric=nums, label='Stress Level')
    data = model.load_data('data/Stress/Stress.csv')
    print('\n% Stress dataset', len(data), len(data[0]))
    return model, data

Rule Set:

% Stress dataset 2001 4 stress_level(X,'1') :- humidity(X,N0), N0>15.0, N0=<22.9. stress_level(X,'2') :- humidity(X,N0), N0>15.0. stress_level(X,'0') :- humidity(X,N0), N0>10.0. stress_level(X,'0') :- humidity(X,N0), N0=<10.0. % acc 1.0 # rules 4 % acc 1.0 macro p r f1 1.0 1.0 1.0 # rules 4

Explaination of a rule:

Explanation for example number 1 : [T]stress_level(X,'1') :- [T]humidity(X,N0), N0>15.0, [T]humidity(X,N0), N0=<22.9. {'Humidity: 21.07'}

Proof Tree for example number 1 : the value of Stress Level is 1 DOES HOLD because the value of humidity is 21.07 which should be greater than 15.0 (DOES HOLD) the value of humidity is 21.07 which should be less equal to 22.9 (DOES HOLD)

{'Humidity: 21.07'}

Built With

Share this project:

Updates