import pandas as pd from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression from sklearn.preprocessing import LabelEncoder from sklearn.metrics import accuracy_score, classification_report, confusion_matrix, roc_curve, roc_auc_score import pickle import statsmodels.api as sm import matplotlib.pyplot as plt import seaborn as sns import os # curdir = os.getcwd() # path_delim = '/' # data = pd.read_excel(curdir + path_delim + 'data/tests_24_10_2023_20_53_cleaned.xlsx', sheet_name="data") # data = data.dropna() # # print(data) # data.plot() # label_encoder = LabelEncoder() # categorical_cols = ['calculatedRatio', 'led1Buffer', 'led1Sample', 'led2Buffer', 'led2Sample'] # # for col in categorical_cols: # # data[col] = label_encoder.fit_transform(data[col]) # X = data[['calculatedRatio', 'led1Buffer', 'led1Sample', 'led2Buffer', 'led2Sample']] # y = data['classificationResult'] # corr = X.corr() # print(corr) # sm.graphics.plot_corr(corr, xnames=list(corr.columns)) # # plt.show() # X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # model = LogisticRegression() # model.fit(X_train, y_train) # y_pred = model.predict(X_test) # accuracy = accuracy_score(y_test, y_pred) # classification_report_result = classification_report(y_test, y_pred) # # sns.heatmap(pd.DataFrame(classification_report_result).iloc[:-1, :].T, annot=True) # # Calculate the confusion matrix # confusion = confusion_matrix(y_test, y_pred) # # Plot the confusion matrix using Seaborn # plt.figure(figsize=(8, 6)) # sns.heatmap(confusion, annot=True, fmt='d', cmap='Blues', linewidths=0.5) # plt.xlabel('Predicted') # plt.ylabel('Actual') # plt.title('Confusion Matrix') # plt.show() # print(f"Accuracy: {accuracy}") # print("Classification Report:") # print(classification_report_result) # # dataset: [6163 rows x 15 columns] # # Accuracy: 0.6593673965936739 # # Classification Report: # # precision recall f1-score support # # Inconclusive. Repeat with test with lower volume of blood 0.00 0.00 0.00 6 # # Inconclusive. Very low Absorbance - Repeat test with Higher Blood Volume 0.88 0.71 0.79 21 # # Negative Borderline. Repeat Test 0.11 0.01 0.01 167 # # Normal 0.80 0.88 0.84 749 # # Positive for Sickle Cell. HPLC for Confirmation 0.00 0.00 0.00 41 # # Sickle Cell Disease 0.25 0.16 0.19 38 # # Sickle Cell Trait 0.37 0.62 0.46 211 # # accuracy 0.66 1233 # # macro avg 0.34 0.34 0.33 1233 # # weighted avg 0.58 0.66 0.61 1233 # with open('logistic_regression_model.pkl', 'wb') as model_file: # pickle.dump(model, model_file) with open('logistic_regression_model.pkl', 'rb') as model_file: loaded_model = pickle.load(model_file) # new_data = pd.DataFrame({'calculatedRatio': [0.126976079], 'led1Buffer': [24313.67], 'led1Sample': [20531], 'led2Buffer': [26565], 'led2Sample': [9975.33]}) #Normal # new_data = pd.DataFrame({'calculatedRatio': [0.17500836], 'led1Buffer': [24843.33], 'led1Sample': [19678], 'led2Buffer': [26715.33], 'led2Sample': [13842.67]}) #SCT # new_data = pd.DataFrame({'calculatedRatio': [0.251395102], 'led1Buffer': [24244], 'led1Sample': [17475], 'led2Buffer': [27059.67], 'led2Sample': [9258.33]}) #SCD # new_data = pd.DataFrame({'calculatedRatio': [0.251061035], 'led1Buffer': [24172], 'led1Sample': [19345], 'led2Buffer': [26918], 'led2Sample': [12964.33]}) # new_data = pd.DataFrame({'calculatedRatio': [0.242851779], 'led1Buffer': [25087.33], 'led1Sample': [20170.67], 'led2Buffer': [26578.33], 'led2Sample': [12724.67]}) # new_data = pd.DataFrame({'calculatedRatio': [0.189778691], 'led1Buffer': [23209.33], 'led1Sample': [17672], 'led2Buffer': [19850.33], 'led2Sample': [10360.33]}) #SCT new_data = pd.DataFrame({'calculatedRatio': [0.149174719], 'led1Buffer': [24122], 'led1Sample': [18368.33], 'led2Buffer': [21733.33], 'led2Sample': [9114.67]}) #Normal predicted_result = loaded_model.predict(new_data) print(predicted_result)