2023-10-24 21:38:48 +05:30
|
|
|
import pandas as pd
|
|
|
|
|
from sklearn.model_selection import train_test_split
|
|
|
|
|
from sklearn.linear_model import LogisticRegression
|
|
|
|
|
from sklearn.preprocessing import LabelEncoder
|
2023-11-08 14:04:39 +05:30
|
|
|
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix, roc_curve, roc_auc_score
|
2023-10-24 21:38:48 +05:30
|
|
|
import pickle
|
|
|
|
|
import statsmodels.api as sm
|
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
import seaborn as sns
|
|
|
|
|
import os
|
|
|
|
|
|
2023-11-08 14:04:39 +05:30
|
|
|
# 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)
|
2023-10-24 21:38:48 +05:30
|
|
|
|
2023-11-08 14:04:39 +05:30
|
|
|
# data.plot()
|
2023-10-24 21:38:48 +05:30
|
|
|
|
2023-11-08 14:04:39 +05:30
|
|
|
# label_encoder = LabelEncoder()
|
|
|
|
|
# categorical_cols = ['calculatedRatio', 'led1Buffer', 'led1Sample', 'led2Buffer', 'led2Sample']
|
|
|
|
|
# # for col in categorical_cols:
|
|
|
|
|
# # data[col] = label_encoder.fit_transform(data[col])
|
2023-10-24 21:38:48 +05:30
|
|
|
|
2023-11-08 14:04:39 +05:30
|
|
|
# X = data[['calculatedRatio', 'led1Buffer', 'led1Sample', 'led2Buffer', 'led2Sample']]
|
|
|
|
|
# y = data['classificationResult']
|
2023-10-24 21:38:48 +05:30
|
|
|
|
2023-11-08 14:04:39 +05:30
|
|
|
# corr = X.corr()
|
|
|
|
|
# print(corr)
|
|
|
|
|
# sm.graphics.plot_corr(corr, xnames=list(corr.columns))
|
|
|
|
|
# # plt.show()
|
2023-10-24 21:38:48 +05:30
|
|
|
|
2023-11-08 14:04:39 +05:30
|
|
|
# X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
2023-10-24 21:38:48 +05:30
|
|
|
|
2023-11-08 14:04:39 +05:30
|
|
|
# model = LogisticRegression()
|
|
|
|
|
# model.fit(X_train, y_train)
|
2023-10-24 21:38:48 +05:30
|
|
|
|
2023-11-08 14:04:39 +05:30
|
|
|
# y_pred = model.predict(X_test)
|
2023-10-24 21:38:48 +05:30
|
|
|
|
2023-11-08 14:04:39 +05:30
|
|
|
# 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)
|
2023-10-24 21:38:48 +05:30
|
|
|
|
|
|
|
|
|
2023-11-08 14:04:39 +05:30
|
|
|
# # Calculate the confusion matrix
|
|
|
|
|
# confusion = confusion_matrix(y_test, y_pred)
|
2023-10-24 21:38:48 +05:30
|
|
|
|
2023-11-08 14:04:39 +05:30
|
|
|
# # 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()
|
2023-10-24 21:38:48 +05:30
|
|
|
|
2023-11-08 14:04:39 +05:30
|
|
|
# print(f"Accuracy: {accuracy}")
|
|
|
|
|
# print("Classification Report:")
|
|
|
|
|
# print(classification_report_result)
|
2023-10-24 21:38:48 +05:30
|
|
|
|
2023-11-08 14:04:39 +05:30
|
|
|
# # dataset: [6163 rows x 15 columns]
|
|
|
|
|
# # Accuracy: 0.6593673965936739
|
|
|
|
|
# # Classification Report:
|
|
|
|
|
# # precision recall f1-score support
|
2023-10-24 21:38:48 +05:30
|
|
|
|
2023-11-08 14:04:39 +05:30
|
|
|
# # 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
|
2023-10-24 21:38:48 +05:30
|
|
|
|
2023-11-08 14:04:39 +05:30
|
|
|
# # accuracy 0.66 1233
|
|
|
|
|
# # macro avg 0.34 0.34 0.33 1233
|
|
|
|
|
# # weighted avg 0.58 0.66 0.61 1233
|
2023-10-24 21:38:48 +05:30
|
|
|
|
|
|
|
|
# with open('logistic_regression_model.pkl', 'wb') as model_file:
|
|
|
|
|
# pickle.dump(model, model_file)
|
|
|
|
|
|
|
|
|
|
|
2023-11-08 14:04:39 +05:30
|
|
|
with open('logistic_regression_model.pkl', 'rb') as model_file:
|
|
|
|
|
loaded_model = pickle.load(model_file)
|
2023-10-24 21:38:48 +05:30
|
|
|
|
2023-11-08 14:04:39 +05:30
|
|
|
# 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)
|