|
import joblib
|
|
import pandas as pd
|
|
|
|
def predict_medication(new_data):
|
|
|
|
knn = joblib.load('models\\medication_classification_model\\knn_model.pkl')
|
|
label_encoders = joblib.load('models\\medication_classification_model\\label_encoders.pkl')
|
|
age_scaler = joblib.load('models\\medication_classification_model\\age_scaler.pkl')
|
|
medication_encoder = joblib.load('models\\medication_classification_model\\medication_encoder.pkl')
|
|
|
|
|
|
for column in ['Gender', 'Blood Type', 'Medical Condition', 'Test Results']:
|
|
new_data[column] = label_encoders[column].transform(new_data[column])
|
|
|
|
|
|
new_data['Age'] = age_scaler.transform(new_data[['Age']])
|
|
|
|
|
|
predictions = knn.predict(new_data)
|
|
|
|
|
|
predicted_medications = medication_encoder.inverse_transform(predictions)
|
|
|
|
return predicted_medications
|
|
|