# -*- coding: utf-8 -*-
"""Final_SideEffects_Treatments.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1j7sqrPUFSTvquZgOla1nYNA7qg7Fg4yg
"""

import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score

from google.colab import drive
drive.mount('/content/drive/')

# Load the dataset into a Pandas DataFrame
df = pd.read_csv("/content/drive/MyDrive/RPDatasetFinal.csv")

# Import the dataset
#df=pd.read_csv('RPDatasetFinal.csv')

# Check the dimensions of the dataset
print("Dataset dimensions:", df.shape)

# Display column names and data types
print(df.info())

# Check for missing values
print(df.isnull().sum())

# remove rows with missing values
df = df.dropna()

#sum of missing values for each column
print(df.isnull().sum())

# Check for duplicate rows
duplicate_rows = df.duplicated()

# Print the duplicate rows
print(df[duplicate_rows])

# Remove duplicate rows
df = df.drop_duplicates()

# Verify that duplicates have been removed
print(df.duplicated().sum())

#Removing unwanted Columns
useless_col =  ['district_name', 'marital_status']
df.drop(useless_col, axis = 1, inplace = True)

# Display column names and data types
print(df.info())

# Calculate summary statistics
print(df.describe())

import matplotlib.pyplot as plt
import seaborn as sns

# Bar plot: Drug Type vs. Gender
plt.figure(figsize=(8, 6))
sns.countplot(x='drug_type', hue='gender', data=df)
plt.xlabel('Drug Type')
plt.ylabel('Count')
plt.title('Drug Type vs. Gender')
plt.show()

# Bar plot: Drug Type vs. Age
plt.figure(figsize=(12, 6))
sns.countplot(x='drug_type', hue='age', data=df)
plt.xlabel('Drug Type')
plt.ylabel('Count')
plt.title('Drug Type vs. Age')
plt.show()

# Preprocessing Categorical Variables
df = df.replace({'gender': {'Male': 1,
                                'Female': 2}})

df = df.replace({'drug_type': { 'Heroin': 1,
    'Cannabis': 2,
    'Opium': 3,
    'Hashish': 4,
    'Cocaine': 5,
    'Methamphetamine': 6}})

df = df.replace({'taking_co_occurring_substances': { 'Yes': 1,
    'No': 2}})

df = df.replace({'co_occurring_substances': { 'Cannabis': 1,
    'Cocaine': 2,
    'Hashish': 3,
    'Heroin': 4,
    'Methamphetamine': 5,
    'Alcohol': 6,
    'No': 7}})

df = df.replace({'route_of_administration': { 'Inhalation': 1,
    'Injection': 2,
    'Smoking': 3}})

df = df.replace({'pre_existing_condision': { 'Yes': 1,
    'No': 2}})

df = df.replace({'diseasers_or_side_effects_1': {'Addiction': 1,
'Agitation and restlessness': 2,
'Anxiety and paranoia': 3,
'Cardiovascular effects': 4,
'Cognitive impairments': 5,
'Constipation': 6,
'Decreased appetite': 7,
'Dental issues': 8,
'Dizziness': 9,
'Drowsiness and sedation': 10,
'Dry mouth and throat': 11,
'Elevated body temperature': 12,
'Gastrointestinal problems': 13,
'Headaches': 14,
'Heart attack': 15,
'Hormonal imbalances': 16,
'Hypotension': 17,
'Insomnia': 18,
'Itching and skin infections': 19,
'Liver and kidney damage': 20,
'Mental confusion': 21,
'Muscle spasms': 22,
'Nausea and vomiting': 23,
'Neurological effects': 24,
'Red eyes': 25,
'Respiratory problems': 26}})

df = df.replace({'diseasers_or_side_effects_2': {'Addiction': 1,
'Agitation and restlessness': 2,
'Anxiety and paranoia': 3,
'Cardiovascular effects': 4,
'Cognitive impairments': 5,
'Constipation': 6,
'Decreased appetite': 7,
'Dental issues': 8,
'Dizziness': 9,
'Drowsiness and sedation': 10,
'Dry mouth and throat': 11,
'Elevated body temperature': 12,
'Gastrointestinal problems': 13,
'Headaches': 14,
'Heart attack': 15,
'Hormonal imbalances': 16,
'Hypotension': 17,
'Insomnia': 18,
'Itching and skin infections': 19,
'Liver and kidney damage': 20,
'Mental confusion': 21,
'Muscle spasms': 22,
'Nausea and vomiting': 23,
'Neurological effects': 24,
'Red eyes': 25,
'Respiratory problems': 26}})

df = df.replace({'treatments_1': {'Behavioral Therapy, Medications, Support Groups, Inpatient Rehab,Outpatient Rehab': 1,
'Antipsychotics,Talk therapy, If nothing else works, physical restraint may be needed': 2,
'Cognitive behaviour therapy (CBT)': 3,
'Do not smoke, Eat healthy foods, Control blood pressure, Get a cholesterol test, Manage diabetes, Exercise, Maintain a healthy weight, Manage stress': 4,
'Using remediation techniques, compensatory strategies, adaptive approaches': 5,
'Gradually increase your daily fiber intake, make sure you drink plenty of fluids, and try to get more exercise': 6,
'Eating small meals regularly throughout the day, Managing any illnesses, infections or underlying conditions, Receiving IV nutrients which are liquid vitamins and minerals that you receive through a needle into your vein, Talking with a mental health specialist about your eating habits if they are irregular': 7,
'Fluoride treatments, Tooth extractions, Fillings, Crowns, Root canals': 8,
'Lie down until the dizziness passes, then get up slowly,move slowly and carefully, get plenty of rest, drink plenty of fluids, especially water, avoid coffee, cigarettes, alcohol and drugs': 9,
'Treating underlying sleep disorders, Lifestyle changes, Address the underlying cause': 10,
'Avoid alcohol (including alcohol-based mouthwashes), caffeine and smoking, suck on ice cubes': 11,
'Take paracetamol or ibuprofen in appropriate doses to help bring your temperature down, Drink plenty of fluids, particularly water, Avoid alcohol, tea and coffee, Avoid taking cold baths or showers': 12,
'Taking rest and drinking plenty of healthy liquids, Eating easily digestible foods, Avoiding spices, carbonated drinks, fried foods, alcohol, and other foods that are gastric irritants, Taking prescribed gastrointestinal medications': 13,
'Drink water, Inadequate hydration may lead you to develop a headache,Limit alcohol, Get adequate sleep, Avoid foods high in histamine, Soothe pain with a cold compress': 14,
'Clot-dissolving drugs (thrombolysis), balloon angioplasty (PCI), surgery': 15,
'Hormone replacement therapy, take oral medication (pills) or injection medication': 16,
'Use more salt, Drink more water, Wear compression stockings': 17,
'Stimulus control therapy, Relaxation techniques, Sleep restriction, Remaining passively awake, Light therapy': 18,
'Antibiotics, Antifungal medications, Moisturizers, Cool compresses, Avoiding triggers': 19,
'Liver transplant': 20,
'Find the source, Prioritize sleep, Make time to relax, Meditate, Feed yourself,Move your body': 21,
'Stretch the affected area, Massage the affected area with your hands or a massage roller, Stand up and walk around, Apply heat or ice, Put an ice pack together or apply a heating pad, or take a nice warm bath, Take painkillers such as ibuprofen and acetaminophen': 22,
'Drinking gradually larger amounts of clear liquids, Avoiding solid food until the vomiting episode has passed, Resting': 23,
'Deep brain stimulation, Spinal cord stimulation, Rehabilitation/physical therapy after brain injury or stroke, Spinal surgery': 24,
'Rest, Cool compresses over closed eyes, Lightly massaging your eyelids, Gently washing your eyelids': 25,
'Oxygen therapy, fluid therapy, pulmonary rehabilitation, Breathing exercises and surgery': 26}})

df = df.replace({'treatments_2': {'Behavioral Therapy, Medications, Support Groups, Inpatient Rehab,Outpatient Rehab': 1,
'Antipsychotics,Talk therapy, If nothing else works, physical restraint may be needed': 2,
'Cognitive behaviour therapy (CBT)': 3,
'Do not smoke, Eat healthy foods, Control blood pressure, Get a cholesterol test, Manage diabetes, Exercise, Maintain a healthy weight, Manage stress': 4,
'Using remediation techniques, compensatory strategies, adaptive approaches': 5,
'Gradually increase your daily fiber intake, make sure you drink plenty of fluids, and try to get more exercise': 6,
'Eating small meals regularly throughout the day, Managing any illnesses, infections or underlying conditions, Receiving IV nutrients which are liquid vitamins and minerals that you receive through a needle into your vein, Talking with a mental health specialist about your eating habits if they are irregular': 7,
'Fluoride treatments, Tooth extractions, Fillings, Crowns, Root canals': 8,
'Lie down until the dizziness passes, then get up slowly,move slowly and carefully, get plenty of rest, drink plenty of fluids, especially water, avoid coffee, cigarettes, alcohol and drugs': 9,
'Treating underlying sleep disorders, Lifestyle changes, Address the underlying cause': 10,
'Avoid alcohol (including alcohol-based mouthwashes), caffeine and smoking, suck on ice cubes': 11,
'Take paracetamol or ibuprofen in appropriate doses to help bring your temperature down, Drink plenty of fluids, particularly water, Avoid alcohol, tea and coffee, Avoid taking cold baths or showers': 12,
'Taking rest and drinking plenty of healthy liquids, Eating easily digestible foods, Avoiding spices, carbonated drinks, fried foods, alcohol, and other foods that are gastric irritants, Taking prescribed gastrointestinal medications': 13,
'Drink water, Inadequate hydration may lead you to develop a headache,Limit alcohol, Get adequate sleep, Avoid foods high in histamine, Soothe pain with a cold compress': 14,
'Clot-dissolving drugs (thrombolysis), balloon angioplasty (PCI), surgery': 15,
'Hormone replacement therapy, take oral medication (pills) or injection medication': 16,
'Use more salt, Drink more water, Wear compression stockings': 17,
'Stimulus control therapy, Relaxation techniques, Sleep restriction, Remaining passively awake, Light therapy': 18,
'Antibiotics, Antifungal medications, Moisturizers, Cool compresses, Avoiding triggers': 19,
'Liver transplant': 20,
'Find the source, Prioritize sleep, Make time to relax, Meditate, Feed yourself,Move your body': 21,
'Stretch the affected area, Massage the affected area with your hands or a massage roller, Stand up and walk around, Apply heat or ice, Put an ice pack together or apply a heating pad, or take a nice warm bath, Take painkillers such as ibuprofen and acetaminophen': 22,
'Drinking gradually larger amounts of clear liquids, Avoiding solid food until the vomiting episode has passed, Resting': 23,
'Deep brain stimulation, Spinal cord stimulation, Rehabilitation/physical therapy after brain injury or stroke, Spinal surgery': 24,
'Rest, Cool compresses over closed eyes, Lightly massaging your eyelids, Gently washing your eyelids': 26,
'Oxygen therapy, fluid therapy, pulmonary rehabilitation, Breathing exercises and surgery': 26}})

df

import pandas as pd
from sklearn.feature_selection import SelectKBest, chi2, f_classif

#Separate the features and target variables
features = df.drop(columns=['diseasers_or_side_effects_1', 'diseasers_or_side_effects_2', 'treatments_1', 'treatments_2'])
target_diseasers_or_side_effects_1 = df['diseasers_or_side_effects_1']
target_diseasers_or_side_effects_2 = df['diseasers_or_side_effects_2']
target_treatments_1 = df['treatments_1']
target_treatments_2 = df['treatments_2']

#Perform feature selection for 'diseasers_or_side_effects_1'
kbest_diseasers_or_side_effects_1 = SelectKBest(score_func=chi2, k=9)  # Select the top 9 features
X_selected_diseasers_or_side_effects_1 = kbest_diseasers_or_side_effects_1.fit_transform(features, target_diseasers_or_side_effects_1)

# Get the selected feature indices for 'diseasers_or_side_effects_1'
selected_feature_indices_diseasers_or_side_effects_1 = kbest_diseasers_or_side_effects_1.get_support(indices=True)
selected_feature_names_diseasers_or_side_effects_1 = features.columns[selected_feature_indices_diseasers_or_side_effects_1]

#Perform feature selection for 'diseasers_or_side_effects_2'
kbest_diseasers_or_side_effects_2 = SelectKBest(score_func=chi2, k=9)  # Select the top 9 features
X_selected_diseasers_or_side_effects_2 = kbest_diseasers_or_side_effects_2.fit_transform(features, target_diseasers_or_side_effects_2)

# Get the selected feature indices for 'diseasers_or_side_effects_1'
selected_feature_indices_diseasers_or_side_effects_2 = kbest_diseasers_or_side_effects_2.get_support(indices=True)
selected_feature_names_diseasers_or_side_effects_2 = features.columns[selected_feature_indices_diseasers_or_side_effects_2]

#Perform feature selection for 'treatments_1'
kbest_treatments_1 = SelectKBest(score_func=f_classif, k=9)  # Select the top 9 features
X_selected_treatments_1 = kbest_treatments_1.fit_transform(features, target_treatments_1)

# Get the selected feature indices for 'treatments_1'
selected_feature_indices_target_treatments_1 = kbest_treatments_1.get_support(indices=True)
selected_feature_names_target_treatments_1 = features.columns[selected_feature_indices_target_treatments_1]

#Perform feature selection for 'treatments_2'
kbest_treatments_2 = SelectKBest(score_func=f_classif, k=9)  # Select the top 9 features
X_selected_treatments_2 = kbest_treatments_2.fit_transform(features, target_treatments_2)

# Get the selected feature indices for 'treatments_2'
selected_feature_indices_target_treatments_2 = kbest_treatments_2.get_support(indices=True)
selected_feature_names_target_treatments_2 = features.columns[selected_feature_indices_target_treatments_2]

# Print the selected feature names for 'diseasers_or_side_effects_1'
print("Selected Features for 'diseasers_or_side_effects_1':")
for feature in selected_feature_names_diseasers_or_side_effects_1:
    print(feature)

# Print the selected feature names for 'diseasers_or_side_effects_2'
print("\nSelected Features for 'diseasers_or_side_effects_2':")
for feature in selected_feature_names_diseasers_or_side_effects_2:
    print(feature)

# Print the selected feature names for 'treatments_1'
print("Selected Features for 'treatments_1':")
for feature in selected_feature_names_target_treatments_1:
    print(feature)


# Print the selected feature names for 'treatments_2'
print("\nSelected Features for 'treatments_2':")
for feature in selected_feature_names_target_treatments_2:
    print(feature)

from sklearn.model_selection import train_test_split

# Separate the features and target variables
features_1 = df[['age', 'gender', 'drug_type', 'measures_of_drug_used_per_day', 'time_used', 'taking_co_occurring_substances', 'co_occurring_substances', 'route_of_administration', 'pre_existing_condision']]
target_diseasers_or_side_effects_1 = df['diseasers_or_side_effects_1']
target_diseasers_or_side_effects_2 = df['diseasers_or_side_effects_2']
target_treatments_1 = df['treatments_1']
target_treatments_2 = df['treatments_2']


# Split the data for diseasers_or_side_effects_1 prediction
X_train_diseasers_or_side_effects_1, X_test_diseasers_or_side_effects_1, y_train_diseasers_or_side_effects_1, y_test_diseasers_or_side_effects_1 = train_test_split(features_1, target_diseasers_or_side_effects_1, test_size=0.2, random_state=42)

# Split the data for diseasers_or_side_effects_2 prediction
X_train_diseasers_or_side_effects_2, X_test_diseasers_or_side_effects_2, y_train_diseasers_or_side_effects_2, y_test_diseasers_or_side_effects_2 = train_test_split(features_1, target_diseasers_or_side_effects_1, test_size=0.2, random_state=42)

# Split the data for treatments_1 prediction
X_train_treatments_1, X_test_treatments_1, y_train_treatments_1, y_test_treatments_1 = train_test_split(features_1, target_treatments_1, test_size=0.2, random_state=42)

# Split the data for treatments_2 prediction
X_train_treatments_2, X_test_treatments_2, y_train_treatments_2, y_test_treatments_2 = train_test_split(features_1, target_treatments_2, test_size=0.2, random_state=42)


# Print the shapes of the training and testing sets
print("Training set shape for diseasers_or_side_effects_1 prediction:", X_train_diseasers_or_side_effects_1.shape, y_train_diseasers_or_side_effects_1.shape)
print("Testing set shape for diseasers_or_side_effects_1 prediction:", X_test_diseasers_or_side_effects_1.shape, y_test_diseasers_or_side_effects_1.shape)
print("Training set shape for diseasers_or_side_effects_2 prediction:", X_train_diseasers_or_side_effects_2.shape, y_train_diseasers_or_side_effects_2.shape)
print("Testing set shape for diseasers_or_side_effects_2 prediction:", X_test_diseasers_or_side_effects_2.shape, y_test_diseasers_or_side_effects_2.shape)
print("Training set shape for treatments_1 prediction:", X_train_treatments_1.shape, y_train_treatments_1.shape)
print("Testing set shape for treatments_1 prediction:", X_test_treatments_1.shape, y_test_treatments_1.shape)
print("Training set shape for treatments_2 prediction:", X_train_treatments_2.shape, y_train_treatments_2.shape)
print("Testing set shape for treatments_2 prediction:", X_test_treatments_2.shape, y_test_treatments_2.shape)

# represent the features that will be used to train the models
X = df[['age', 'gender', 'drug_type', 'measures_of_drug_used_per_day', 'time_used', 'taking_co_occurring_substances', 'co_occurring_substances', 'route_of_administration', 'pre_existing_condision']]

# represents the target variables
y_diseasers_or_side_effects_1 = df['diseasers_or_side_effects_1']
y_diseasers_or_side_effects_2 = df['diseasers_or_side_effects_2']
y_treatments_1 = df['treatments_1']
y_treatments_2 = df['treatments_2']

# splitting the dataset into training and testing sets for diseasers or side_effects 1 prediction
X_train, X_test, y_train_diseasers_or_side_effects_1, y_test_diseasers_or_side_effects_1 = train_test_split(X, y_diseasers_or_side_effects_1, test_size=0.2, random_state=42)

# splitting the dataset into training and testing sets for diseasers or side_effects 2 prediction
X_train, X_test, y_train_diseasers_or_side_effects_2, y_test_diseasers_or_side_effects_2 = train_test_split(X, y_diseasers_or_side_effects_2, test_size=0.2, random_state=42)

# splitting the dataset into training and testing sets for treatments 1 prediction
X_train, X_test, y_train_treatments_1, y_test_treatments_1 = train_test_split(X, y_treatments_1, test_size=0.2, random_state=42)

# splitting the dataset into training and testing sets for treatments 2 prediction
X_train, X_test, y_train_treatments_2, y_test_treatments_2 = train_test_split(X, y_treatments_2, test_size=0.2, random_state=42)

# Importing the DecisionTreeClassifier class
from sklearn.tree import DecisionTreeClassifier

# Create decision tree classifier
dt_classifier = DecisionTreeClassifier()

# Train the model
# For diseasers_or_side_effects_1 prediction
diseasers_or_side_effects_1_model = DecisionTreeClassifier()

# For diseasers_or_side_effects_2 prediction
diseasers_or_side_effects_2_model = DecisionTreeClassifier()

# For treatments_1 prediction
treatments_1_model = DecisionTreeClassifier()

# For treatments_2 prediction
treatments_2_model = DecisionTreeClassifier()

# 2. Train the models
diseasers_or_side_effects_1_model.fit(X_train, y_train_diseasers_or_side_effects_1)
diseasers_or_side_effects_2_model.fit(X_train, y_train_diseasers_or_side_effects_2)
treatments_1_model.fit(X_train, y_train_treatments_1)
treatments_2_model.fit(X_train, y_train_treatments_2)

# 3. Make predictions
diseasers_or_side_effects_1_predictions = diseasers_or_side_effects_1_model.predict(X_test)
diseasers_or_side_effects_2_predictions = diseasers_or_side_effects_2_model.predict(X_test)
treatments_1_predictions = treatments_1_model.predict(X_test)
treatments_2_predictions = treatments_2_model.predict(X_test)

diseasers_or_side_effects_2_predictions = diseasers_or_side_effects_2_predictions.astype(y_test_diseasers_or_side_effects_2)
treatments_2_predictions = treatments_2_predictions.astype(y_test_treatments_2)

# Example evaluation for diseasers_or_side_effects_1 prediction (classification)
from sklearn.metrics import accuracy_score, precision_score, recall_score

diseasers_or_side_effects_1_accuracy = accuracy_score(y_test_diseasers_or_side_effects_1, diseasers_or_side_effects_1_predictions)
diseasers_or_side_effects_1_precision = precision_score(y_test_diseasers_or_side_effects_1, diseasers_or_side_effects_1_predictions, average='micro')
diseasers_or_side_effects_1_recall = recall_score(y_test_diseasers_or_side_effects_1, diseasers_or_side_effects_1_predictions, average='micro')

# Example evaluation for diseasers_or_side_effects_2 prediction (classification)
diseasers_or_side_effects_2_accuracy = accuracy_score(y_test_diseasers_or_side_effects_2, diseasers_or_side_effects_2_predictions)
diseasers_or_side_effects_2_precision = precision_score(y_test_diseasers_or_side_effects_2, diseasers_or_side_effects_2_predictions, average='micro')
diseasers_or_side_effects_2_recall = recall_score(y_test_diseasers_or_side_effects_2, diseasers_or_side_effects_2_predictions, average='micro')

# Example evaluation for treatments_1 prediction (classification)
treatments_1_accuracy = accuracy_score(y_test_treatments_1, treatments_1_predictions)
treatments_1_precision = precision_score(y_test_treatments_1, treatments_1_predictions, average='micro')
treatments_1_recall = recall_score(y_test_treatments_1, treatments_1_predictions, average='micro')

# Example evaluation for treatments_2 prediction (classification)
treatments_2_accuracy = accuracy_score(y_test_treatments_2, treatments_2_predictions)
treatments_2_precision = precision_score(y_test_treatments_2, treatments_2_predictions, average='micro')
treatments_2_recall = recall_score(y_test_treatments_2, treatments_2_predictions, average='micro')

# Print the evaluation results
print("Diseasers_or_side_effects_1 Accuracy:", diseasers_or_side_effects_1_accuracy)
print("Diseasers_or_side_effects_1 Precision:", diseasers_or_side_effects_1_precision)
print("Diseasers_or_side_effects_1 Recall:", diseasers_or_side_effects_1_recall)

print("Diseasers_or_side_effects_2 Accuracy:", diseasers_or_side_effects_2_accuracy)
print("Diseasers_or_side_effects_2 Precision:", diseasers_or_side_effects_2_precision)
print("Diseasers_or_side_effects_2 Recall:", diseasers_or_side_effects_2_recall)

print("Treatments_1 Accuracy:", treatments_1_accuracy)
print("Treatments_1 Precision:", treatments_1_precision)
print("Treatments_1 Recall:", treatments_1_recall)

print("Treatments_2 Accuracy:", treatments_2_accuracy)
print("Treatments_2 Precision:", treatments_2_precision)
print("Treatments_2 Recall:", treatments_2_recall)

diseasers_or_side_effects_1_model.fit(X, y_diseasers_or_side_effects_1)
diseasers_or_side_effects_2_model.fit(X, y_diseasers_or_side_effects_2)
treatments_1_model.fit(X, y_treatments_1)
treatments_2_model.fit(X, y_treatments_2)

import pandas as pd
import pickle
import numpy as np

# Save the trained model
with open('/content/drive/MyDrive/Research/trained_model.pkl', 'wb') as file:
    pickle.dump(diseasers_or_side_effects_1_model, file)
    pickle.dump(diseasers_or_side_effects_2_model, file)
    pickle.dump(treatments_1_model, file)
    pickle.dump(treatments_2_model, file)

# Load the new data
new_person_data = pd.DataFrame({
    'age': [45],
    'gender': [2],
    'drug_type': [1],
    'measures_of_drug_used_per_day': [12],
    'time_used': [15],
    'taking_co_occurring_substances': [2],
    'co_occurring_substances': [7],
    'route_of_administration': [1],
    'pre_existing_condision':[1]
})

# Load the trained model
with open('/content/drive/MyDrive/Research/trained_model.pkl', 'rb') as file:
    diseasers_or_side_effects_1_model = pickle.load(file)
    diseasers_or_side_effects_2_model = pickle.load(file)
    treatments_1_model = pickle.load(file)
    treatments_2_model = pickle.load(file)

# Make predictions for the new data
diseasers_or_side_effects_1_prediction = diseasers_or_side_effects_1_model.predict(new_person_data)
diseasers_or_side_effects_2_prediction = diseasers_or_side_effects_2_model.predict(new_person_data)
treatments_1_prediction = treatments_1_model.predict(new_person_data)
treatments_2_prediction = treatments_2_model.predict(new_person_data)

# Round the predictions
diseasers_or_side_effects_1_prediction = np.round(diseasers_or_side_effects_1_prediction)
diseasers_or_side_effects_2_prediction = np.round(diseasers_or_side_effects_2_prediction)
treatments_1_prediction = np.round(treatments_1_prediction)
treatments_2_prediction = np.round(treatments_2_prediction)

# Print the predicted Diseasers_or_side_effects
print('Predicted Diseasers or Side Effects 1:', diseasers_or_side_effects_1_prediction)
print('Predicted Diseasers or Side Effects 2:', diseasers_or_side_effects_2_prediction)
print('Predicted Treatments 1:', treatments_1_prediction)
print('Predicted Treatments 2:', treatments_2_prediction)

import pandas as pd
import pickle

# Save the trained model
with open('/content/drive/MyDrive/Research/trained_model.pkl', 'wb') as file:
    pickle.dump(diseasers_or_side_effects_1_model, file)

# Load the new data
new_person_data = pd.DataFrame({
    'age': [45],
    'gender': [2],
    'drug_type': [1],
    'measures_of_drug_used_per_day': [12],
    'time_used': [15],
    'taking_co_occurring_substances': [2],
    'co_occurring_substances': [7],
    'route_of_administration': [1],
    'pre_existing_condision':[1]
})

# Load the trained model
with open('/content/drive/MyDrive/Research/trained_model.pkl', 'rb') as file:
    diseasers_or_side_effects_1_model = pickle.load(file)


# Make predictions for the new data
diseasers_or_side_effects_1_prediction = diseasers_or_side_effects_1_model.predict(new_person_data)

# Round the predictions
diseasers_or_side_effects_1_prediction = np.round(diseasers_or_side_effects_1_prediction)

if diseasers_or_side_effects_1_prediction == 1:

  diseasers_or_side_effects_1 = 'Addiction'

elif diseasers_or_side_effects_1_prediction == 2:

  diseasers_or_side_effects_1 = 'Agitation and restlessness'

elif diseasers_or_side_effects_1_prediction == 3:

  diseasers_or_side_effects_1 = 'Anxiety and paranoia'

elif diseasers_or_side_effects_1_prediction == 4:

  diseasers_or_side_effects_1 = 'Cardiovascular effects'

elif diseasers_or_side_effects_1_prediction == 5:

  diseasers_or_side_effects_1 = 'Cognitive impairments'

elif diseasers_or_side_effects_1_prediction == 6:

  diseasers_or_side_effects_1 = 'Constipation'

elif diseasers_or_side_effects_1_prediction == 7:

  diseasers_or_side_effects_1 = 'Decreased appetite'

elif diseasers_or_side_effects_1_prediction == 8:

  diseasers_or_side_effects_1 = 'Dental issues'

elif diseasers_or_side_effects_1_prediction == 9:

  diseasers_or_side_effects_1 = 'Dizziness'

elif diseasers_or_side_effects_1_prediction == 10:

  diseasers_or_side_effects_1 = 'Drowsiness and sedation'

elif diseasers_or_side_effects_1_prediction == 11:

  diseasers_or_side_effects_1 = 'Dry mouth and throat'

elif diseasers_or_side_effects_1_prediction == 12:

  diseasers_or_side_effects_1 = 'Elevated body temperature'

elif diseasers_or_side_effects_1_prediction == 13:

  diseasers_or_side_effects_1 = 'Gastrointestinal problems'

elif diseasers_or_side_effects_1_prediction == 14:

  diseasers_or_side_effects_1 = 'Headaches'

elif diseasers_or_side_effects_1_prediction == 15:

  diseasers_or_side_effects_1 = 'Heart attak'

elif diseasers_or_side_effects_1_prediction == 16:

  diseasers_or_side_effects_1 = 'Hormonal imbalances'

elif diseasers_or_side_effects_1_prediction == 17:

  diseasers_or_side_effects_1 = 'Hypotension'

elif diseasers_or_side_effects_1_prediction == 18:

  diseasers_or_side_effects_1 = 'Insomnia'

elif diseasers_or_side_effects_1_prediction == 19:

  diseasers_or_side_effects_1 = 'Itching and skin infections'

elif diseasers_or_side_effects_1_prediction == 20:

  diseasers_or_side_effects_1 = 'Liver and kidney damage'

elif diseasers_or_side_effects_1_prediction == 21:

  diseasers_or_side_effects_1 = 'Mental confusion'

elif diseasers_or_side_effects_1_prediction == 22:

  diseasers_or_side_effects_1 = 'Muscle spasms'

elif diseasers_or_side_effects_1_prediction == 23:

  diseasers_or_side_effects_1 = 'Nausea and vomiting'

elif diseasers_or_side_effects_1_prediction == 24:

  diseasers_or_side_effects_1 = 'Neurological effects'

elif diseasers_or_side_effects_1_prediction == 25:

  diseasers_or_side_effects_1 = 'Red eyes'

else:

  diseasers_or_side_effects_1 = 'Respiratory problems'


# Print the predicted Diseasers_or_side_effects 1
print('Predicted Diseasers or Side Effects 1:', diseasers_or_side_effects_1_prediction)
print(diseasers_or_side_effects_1)

import pandas as pd
import pickle

# Save the trained model
with open('/content/drive/MyDrive/Research/trained_model.pkl', 'wb') as file:
    pickle.dump(diseasers_or_side_effects_2_model, file)

# Load the new data
new_person_data = pd.DataFrame({
    'age': [45],
    'gender': [2],
    'drug_type': [1],
    'measures_of_drug_used_per_day': [12],
    'time_used': [15],
    'taking_co_occurring_substances': [2],
    'co_occurring_substances': [7],
    'route_of_administration': [1],
    'pre_existing_condision':[1]
})

# Load the trained model
with open('/content/drive/MyDrive/Research/trained_model.pkl', 'rb') as file:
    diseasers_or_side_effects_2_model = pickle.load(file)


# Make predictions for the new person's data
diseasers_or_side_effects_2_prediction = diseasers_or_side_effects_2_model.predict(new_person_data)

# Round the predictions
diseasers_or_side_effects_2_prediction = np.round(diseasers_or_side_effects_2_prediction)

if diseasers_or_side_effects_2_prediction == 1:

  diseasers_or_side_effects_2 = 'Addiction'

elif diseasers_or_side_effects_2_prediction == 2:

  diseasers_or_side_effects_2 = 'Agitation and restlessness'

elif diseasers_or_side_effects_2_prediction == 3:

  diseasers_or_side_effects_2 = 'Anxiety and paranoia'

elif diseasers_or_side_effects_2_prediction == 4:

  diseasers_or_side_effects_2 = 'Cardiovascular effects'

elif diseasers_or_side_effects_2_prediction == 5:

  diseasers_or_side_effects_2 = 'Cognitive impairments'

elif diseasers_or_side_effects_2_prediction == 6:

  diseasers_or_side_effects_2 = 'Constipation'

elif diseasers_or_side_effects_1_prediction == 7:

  diseasers_or_side_effects_2 = 'Decreased appetite'

elif diseasers_or_side_effects_2_prediction == 8:

  diseasers_or_side_effects_2 = 'Dental issues'

elif diseasers_or_side_effects_2_prediction == 9:

  diseasers_or_side_effects_2 = 'Dizziness'

elif diseasers_or_side_effects_2_prediction == 10:

  diseasers_or_side_effects_2 = 'Drowsiness and sedation'

elif diseasers_or_side_effects_2_prediction == 11:

  diseasers_or_side_effects_2 = 'Dry mouth and throat'

elif diseasers_or_side_effects_2_prediction == 12:

  diseasers_or_side_effects_2 = 'Elevated body temperature'

elif diseasers_or_side_effects_2_prediction == 13:

  diseasers_or_side_effects_2 = 'Gastrointestinal problems'

elif diseasers_or_side_effects_2_prediction == 14:

  diseasers_or_side_effects_2 = 'Headaches'

elif diseasers_or_side_effects_2_prediction == 15:

  diseasers_or_side_effects_2 = 'Heart attak'

elif diseasers_or_side_effects_2_prediction == 16:

  diseasers_or_side_effects_2 = 'Hormonal imbalances'

elif diseasers_or_side_effects_2_prediction == 17:

  diseasers_or_side_effects_2 = 'Hypotension'

elif diseasers_or_side_effects_2_prediction == 18:

  diseasers_or_side_effects_2_model = 'Insomnia'

elif diseasers_or_side_effects_2_prediction == 19:

  diseasers_or_side_effects_2 = 'Itching and skin infections'

elif diseasers_or_side_effects_2_prediction == 20:

  diseasers_or_side_effects_2 = 'Liver and kidney damage'

elif diseasers_or_side_effects_2_prediction == 21:

  diseasers_or_side_effects_2 = 'Mental confusion'

elif diseasers_or_side_effects_2_prediction == 22:

  diseasers_or_side_effects_2 = 'Muscle spasms'

elif diseasers_or_side_effects_2_prediction == 23:

  diseasers_or_side_effects_2 = 'Nausea and vomiting'

elif diseasers_or_side_effects_2_prediction == 24:

  diseasers_or_side_effects_2 = 'Neurological effects'

elif diseasers_or_side_effects_2_prediction == 25:

  diseasers_or_side_effects_2 = 'Red eyes'

else:

  diseasers_or_side_effects_2 = 'Respiratory problems'


# Print the predicted Diseasers_or_side_effects 2
print('Predicted Diseasers or Side Effects 2:', diseasers_or_side_effects_2_prediction)
print(diseasers_or_side_effects_2)

import pandas as pd
import pickle

# Save the trained model
with open('/content/drive/MyDrive/Research/trained_model.pkl', 'wb') as file:
    pickle.dump(treatments_1_model, file)

# Load the new data
new_person_data = pd.DataFrame({
    'age': [45],
    'gender': [2],
    'drug_type': [1],
    'measures_of_drug_used_per_day': [12],
    'time_used': [15],
    'taking_co_occurring_substances': [2],
    'co_occurring_substances': [7],
    'route_of_administration': [1],
    'pre_existing_condision':[1]
})

# Load the trained model
with open('/content/drive/MyDrive/Research/trained_model.pkl', 'rb') as file:
    treatments_1_model = pickle.load(file)


# Make predictions for the new data
treatments_1_prediction = treatments_1_model.predict(new_person_data)

treatments_1_prediction = np.round(treatments_1_prediction)


if treatments_1_prediction == 1:

  treatments_1 = 'Behavioral Therapy, Medications, Support Groups, Inpatient Rehab,Outpatient Rehab'

elif treatments_1_prediction == 2:

  treatments_1 = 'Antipsychotics,Talk therapy, If nothing else works, physical restraint may be needed'

elif treatments_1_prediction == 3:

  treatments_1 = 'Cognitive behaviour therapy (CBT)'

elif treatments_1_prediction == 4:

  treatments_1 = 'Do not smoke, Eat healthy foods, Control blood pressure, Get a cholesterol test, Manage diabetes, Exercise, Maintain a healthy weight, Manage stress'

elif treatments_1_prediction == 5:

  treatments_1 = 'Using remediation techniques, compensatory strategies, adaptive approaches'

elif treatments_1_prediction == 6:

  treatments_1 = 'Gradually increase your daily fiber intake, make sure you drink plenty of fluids, and try to get more exercise'

elif treatments_1_prediction == 7:

  treatments_1 = 'Eating small meals regularly throughout the day, Managing any illnesses, infections or underlying conditions, Receiving IV nutrients which are liquid vitamins and minerals that you receive through a needle into your vein, Talking with a mental health specialist about your eating habits if they are irregular'

elif treatments_1_prediction == 8:

  treatments_1 = 'Fluoride treatments, Tooth extractions, Fillings, Crowns, Root canals'

elif treatments_1_prediction == 9:

  treatments_1 = 'Focus your attention on a distracting activity such as reading, singing, listening to music, gardening, or exercising'

elif treatments_1_prediction == 10:

  treatments_1 = 'Treating underlying sleep disorders, Lifestyle changes, Address the underlying cause'

elif treatments_1_prediction == 11:

  treatments_1 = 'Avoid alcohol (including alcohol-based mouthwashes), caffeine and smoking, suck on ice cubes'

elif treatments_1_prediction == 12:

  treatments_1 = 'Take paracetamol or ibuprofen in appropriate doses to help bring your temperature down, Drink plenty of fluids, particularly water, Avoid alcohol, tea and coffee, Avoid taking cold baths or showers'

elif treatments_1_prediction == 13:

  treatments_1 = 'Taking rest and drinking plenty of healthy liquids, Eating easily digestible foods, Avoiding spices, carbonated drinks, fried foods, alcohol, and other foods that are gastric irritants, Taking prescribed gastrointestinal medications'

elif treatments_1_prediction == 14:

  treatments_1 = 'Drink water, Inadequate hydration may lead you to develop a headache,Limit alcohol, Get adequate sleep, Avoid foods high in histamine, Soothe pain with a cold compress'

elif treatments_1_prediction == 15:

  treatments_1 = 'Clot-dissolving drugs (thrombolysis), balloon angioplasty (PCI), surgery'

elif treatments_1_prediction == 16:

  treatments_1 = 'Hormone replacement therapy, take oral medication (pills) or injection medication'

elif treatments_1_prediction == 17:

  treatments_1 = 'Use more salt, Drink more water, Wear compression stockings'

elif treatments_1_prediction == 18:

  treatments_1 = 'Stimulus control therapy, Relaxation techniques, Sleep restriction, Remaining passively awake, Light therapy'

elif treatments_1_prediction == 19:

  treatments_1 = 'Antibiotics, Antifungal medications, Moisturizers, Cool compresses, Avoiding triggers'

elif treatments_1_prediction == 20:

  treatments_1 = 'Liver transplant'

elif treatments_1_prediction == 21:

  treatments_1 = 'Find the source, Prioritize sleep, Make time to relax, Meditate, Feed yourself,Move your body'

elif treatments_1_prediction == 22:

  treatments_1 = 'Stretch the affected area, Massage the affected area with your hands or a massage roller, Stand up and walk around, Apply heat or ice, Put an ice pack together or apply a heating pad, or take a nice warm bath, Take painkillers such as ibuprofen and acetaminophen'

elif treatments_1_prediction == 23:

  treatments_1 = 'Drinking gradually larger amounts of clear liquids, Avoiding solid food until the vomiting episode has passed, Resting'

elif treatments_1_prediction == 24:

  treatments_1 = 'Deep brain stimulation, Spinal cord stimulation, Rehabilitation/physical therapy after brain injury or stroke, Spinal surgery'

elif treatments_1_prediction == 25:

  treatments_1 = 'Rest, Cool compresses over closed eyes, Lightly massaging your eyelids, Gently washing your eyelids'

else:

  treatments_1 = 'Oxygen therapy, fluid therapy, pulmonary rehabilitation, Breathing exercises and surgery'


# Print the predicted Treatments 1
print('Predicted Treatments 1:', treatments_1_prediction)
print(treatments_1)

import pandas as pd
import pickle

# Save the trained model
with open('/content/drive/MyDrive/Research/trained_model.pkl', 'wb') as file:
    pickle.dump(treatments_2_model, file)

# Load the new data
new_person_data = pd.DataFrame({
    'age': [45],
    'gender': [2],
    'drug_type': [1],
    'measures_of_drug_used_per_day': [12],
    'time_used': [15],
    'taking_co_occurring_substances': [2],
    'co_occurring_substances': [7],
    'route_of_administration': [1],
    'pre_existing_condision':[1]
})

# Load the trained model
with open('/content/drive/MyDrive/Research/trained_model.pkl', 'rb') as file:
    treatments_2_model = pickle.load(file)


# Make predictions for the new data
treatments_2_prediction = treatments_2_model.predict(new_person_data)

treatments_2_prediction = np.round(treatments_2_prediction)

if treatments_2_prediction == 1:

  treatments_2 = 'Behavioral Therapy, Medications, Support Groups, Inpatient Rehab,Outpatient Rehab'

elif treatments_2_prediction == 2:

  treatments_2 = 'Antipsychotics,Talk therapy, If nothing else works, physical restraint may be needed'

elif treatments_2_prediction == 3:

  treatments_2 = 'Cognitive behaviour therapy (CBT)'

elif treatments_2_prediction == 4:

  treatments_2 = 'Do not smoke, Eat healthy foods, Control blood pressure, Get a cholesterol test, Manage diabetes, Exercise, Maintain a healthy weight, Manage stress'

elif treatments_2_prediction == 5:

  treatments_2 = 'Using remediation techniques, compensatory strategies, adaptive approaches'

elif treatments_2_prediction == 6:

  treatments_2 = 'Gradually increase your daily fiber intake, make sure you drink plenty of fluids, and try to get more exercise'

elif treatments_2_prediction == 7:

  treatments_2 = 'Eating small meals regularly throughout the day, Managing any illnesses, infections or underlying conditions, Receiving IV nutrients which are liquid vitamins and minerals that you receive through a needle into your vein, Talking with a mental health specialist about your eating habits if they are irregular'

elif treatments_2_prediction == 8:

  treatments_2 = 'Fluoride treatments, Tooth extractions, Fillings, Crowns, Root canals'

elif treatments_2_prediction == 9:

  treatments_2 = 'Focus your attention on a distracting activity such as reading, singing, listening to music, gardening, or exercising'

elif treatments_2_prediction == 10:

  treatments_2 = 'Treating underlying sleep disorders, Lifestyle changes, Address the underlying cause'

elif treatments_2_prediction == 11:

  treatments_2 = 'Avoid alcohol (including alcohol-based mouthwashes), caffeine and smoking, suck on ice cubes'

elif treatments_2_prediction == 12:

  treatments_2 = 'Take paracetamol or ibuprofen in appropriate doses to help bring your temperature down, Drink plenty of fluids, particularly water, Avoid alcohol, tea and coffee, Avoid taking cold baths or showers'

elif treatments_2_prediction == 13:

  treatments_2 = 'Taking rest and drinking plenty of healthy liquids, Eating easily digestible foods, Avoiding spices, carbonated drinks, fried foods, alcohol, and other foods that are gastric irritants, Taking prescribed gastrointestinal medications'

elif treatments_2_prediction == 14:

  treatments_2 = 'Drink water, Inadequate hydration may lead you to develop a headache,Limit alcohol, Get adequate sleep, Avoid foods high in histamine, Soothe pain with a cold compress'

elif treatments_2_prediction == 15:

  treatments_2 = 'Clot-dissolving drugs (thrombolysis), balloon angioplasty (PCI), surgery'

elif treatments_2_prediction == 16:

  treatments_2 = 'Hormone replacement therapy, take oral medication (pills) or injection medication'

elif treatments_2_prediction == 17:

  treatments_2 = 'Use more salt, Drink more water, Wear compression stockings'

elif treatments_2_prediction == 18:

  treatments_2 = 'Stimulus control therapy, Relaxation techniques, Sleep restriction, Remaining passively awake, Light therapy'

elif treatments_2_prediction == 19:

  treatments_2 = 'Antibiotics, Antifungal medications, Moisturizers, Cool compresses, Avoiding triggers'

elif treatments_2_prediction == 20:

  treatments_2 = 'Liver transplant'

elif treatments_2_prediction == 21:

  treatments_2 = 'Find the source, Prioritize sleep, Make time to relax, Meditate, Feed yourself,Move your body'

elif treatments_2_prediction == 22:

  treatments_2 = 'Stretch the affected area, Massage the affected area with your hands or a massage roller, Stand up and walk around, Apply heat or ice, Put an ice pack together or apply a heating pad, or take a nice warm bath, Take painkillers such as ibuprofen and acetaminophen'

elif treatments_2_prediction == 23:

  treatments_2 = 'Drinking gradually larger amounts of clear liquids, Avoiding solid food until the vomiting episode has passed, Resting'

elif treatments_2_prediction == 24:

  treatments_2 = 'Deep brain stimulation, Spinal cord stimulation, Rehabilitation/physical therapy after brain injury or stroke, Spinal surgery'

elif treatments_2_prediction == 25:

  treatments_2 = 'Rest, Cool compresses over closed eyes, Lightly massaging your eyelids, Gently washing your eyelids'

else:

  treatments_2 = 'Oxygen therapy, fluid therapy, pulmonary rehabilitation, Breathing exercises and surgery'


# Print the predicted Treatments 2
print('Predicted Treatments 2:', treatments_2_prediction)
print(treatments_2)

#splitting the dataset into training and testing sets for diseasers or side_effects 1 prediction
X_train, X_test, y_train_diseasers_or_side_effects_1, y_test_diseasers_or_side_effects_1 = train_test_split(X, y_diseasers_or_side_effects_1, test_size=0.2, random_state=42)

# splitting the dataset into training and testing sets for diseasers or side_effects 2 prediction
X_train, X_test, y_train_diseasers_or_side_effects_2, y_test_diseasers_or_side_effects_2 = train_test_split(X, y_diseasers_or_side_effects_2, test_size=0.2, random_state=42)

# splitting the dataset into training and testing sets for treatments 1 prediction
X_train, X_test, y_train_treatments_1, y_test_treatments_1 = train_test_split(X, y_treatments_1, test_size=0.2, random_state=42)

# splitting the dataset into training and testing sets for treatments 2 prediction
X_train, X_test, y_train_treatments_2, y_test_treatments_2 = train_test_split(X, y_treatments_2, test_size=0.2, random_state=42)

# Importing the RandomForestClassifier class
from sklearn.ensemble import RandomForestClassifier

# For diseasers_or_side_effects_1 prediction
diseasers_or_side_effects_1_model = RandomForestClassifier()

# For diseasers_or_side_effects_2 prediction
diseasers_or_side_effects_2_model = RandomForestClassifier()

# For treatments_1 prediction
treatments_1_model = RandomForestClassifier()

# For treatments_2 prediction
treatments_2_model = RandomForestClassifier()

#Train the models
diseasers_or_side_effects_1_model.fit(X_train, y_train_diseasers_or_side_effects_1)
diseasers_or_side_effects_2_model.fit(X_train, y_train_diseasers_or_side_effects_2)
treatments_1_model.fit(X_train, y_train_treatments_1)
treatments_2_model.fit(X_train, y_train_treatments_2)

#Make predictions
diseasers_or_side_effects_1_predictions = diseasers_or_side_effects_1_model.predict(X_test)
diseasers_or_side_effects_2_predictions = diseasers_or_side_effects_2_model.predict(X_test)
treatments_1_predictions = treatments_1_model.predict(X_test)
treatments_2_predictions = treatments_2_model.predict(X_test)

diseasers_or_side_effects_2_predictions = diseasers_or_side_effects_2_predictions.astype(y_test_diseasers_or_side_effects_2)
treatments_2_predictions = treatments_2_predictions.astype(y_test_treatments_2)

# Importing evaluation metrics (accuracy_score, precision_score, recall_score) from sklearn.metrics and calculating the evaluation scores
# Evaluation for diseasers_or_side_effects_1 prediction (classification)
from sklearn.metrics import accuracy_score, precision_score, recall_score

diseasers_or_side_effects_1_accuracy = accuracy_score(y_test_diseasers_or_side_effects_1, diseasers_or_side_effects_1_predictions)
diseasers_or_side_effects_1_precision = precision_score(y_test_diseasers_or_side_effects_1, diseasers_or_side_effects_1_predictions, average='micro')
diseasers_or_side_effects_1_recall = recall_score(y_test_diseasers_or_side_effects_1, diseasers_or_side_effects_1_predictions, average='micro')

# Evaluation for diseasers_or_side_effects_2 prediction (classification)
diseasers_or_side_effects_2_accuracy = accuracy_score(y_test_diseasers_or_side_effects_2, diseasers_or_side_effects_2_predictions)
diseasers_or_side_effects_2_precision = precision_score(y_test_diseasers_or_side_effects_2, diseasers_or_side_effects_2_predictions, average='micro')
diseasers_or_side_effects_2_recall = recall_score(y_test_diseasers_or_side_effects_2, diseasers_or_side_effects_2_predictions, average='micro')

# Evaluation for treatments_1 prediction (classification)
treatments_1_accuracy = accuracy_score(y_test_treatments_1, treatments_1_predictions)
treatments_1_precision = precision_score(y_test_treatments_1, treatments_1_predictions, average='micro')
treatments_1_recall = recall_score(y_test_treatments_1, treatments_1_predictions, average='micro')

# Evaluation for treatments_2 prediction (classification)
treatments_2_accuracy = accuracy_score(y_test_treatments_2, treatments_2_predictions)
treatments_2_precision = precision_score(y_test_treatments_2, treatments_2_predictions, average='micro')
treatments_2_recall = recall_score(y_test_treatments_2, treatments_2_predictions, average='micro')

# Print the evaluation results
print("Diseasers_or_side_effects_1 Accuracy:", diseasers_or_side_effects_1_accuracy)
print("Diseasers_or_side_effects_1 Precision:", diseasers_or_side_effects_1_precision)
print("Diseasers_or_side_effects_1 Recall:", diseasers_or_side_effects_1_recall)

print("Diseasers_or_side_effects_2 Accuracy:", diseasers_or_side_effects_2_accuracy)
print("Diseasers_or_side_effects_2 Precision:", diseasers_or_side_effects_2_precision)
print("Diseasers_or_side_effects_2 Recall:", diseasers_or_side_effects_2_recall)

print("Treatments_1 Accuracy:", treatments_1_accuracy)
print("Treatments_1 Precision:", treatments_1_precision)
print("Treatments_1 Recall:", treatments_1_recall)

print("Treatments_2 Accuracy:", treatments_2_accuracy)
print("Treatments_2 Precision:", treatments_2_precision)
print("Treatments_2 Recall:", treatments_2_recall)


# fitting the Diseasers_or_side_effects_1 model, Diseasers_or_side_effects_2 model, Treatments_1 model and Treatments_2 model on the full dataset

diseasers_or_side_effects_1_model.fit(X, y_diseasers_or_side_effects_1)
diseasers_or_side_effects_2_model.fit(X, y_diseasers_or_side_effects_2)
treatments_1_model.fit(X, y_treatments_1)
treatments_2_model.fit(X, y_treatments_2)

from sklearn.svm import SVC, SVR
from sklearn.metrics import accuracy_score, precision_score, recall_score, mean_squared_error, r2_score

# For diseasers_or_side_effects_1 prediction
diseasers_or_side_effects_1_model = SVC()

# For diseasers_or_side_effects_2 prediction
diseasers_or_side_effects_2_model = SVC()

# For treatments_1 prediction
treatments_1_model = SVC()

# For treatments_2 prediction
treatments_2_model = SVC()

diseasers_or_side_effects_1_model.fit(X_train, y_train_diseasers_or_side_effects_1)
diseasers_or_side_effects_2_model.fit(X_train, y_train_diseasers_or_side_effects_2)
treatments_1_model.fit(X_train, y_train_treatments_1)
treatments_2_model.fit(X_train, y_train_treatments_2)

diseasers_or_side_effects_1_predictions = diseasers_or_side_effects_1_model.predict(X_test)
diseasers_or_side_effects_2_predictions = diseasers_or_side_effects_2_model.predict(X_test)
treatments_1_predictions = treatments_1_model.predict(X_test)
treatments_2_predictions = treatments_2_model.predict(X_test)


# Example evaluation for diseasers_or_side_effects_1 prediction (classification)
diseasers_or_side_effects_1_accuracy = accuracy_score(y_test_diseasers_or_side_effects_1, diseasers_or_side_effects_1_predictions)
diseasers_or_side_effects_1_precision = precision_score(y_test_diseasers_or_side_effects_1, diseasers_or_side_effects_1_predictions, average='micro')
diseasers_or_side_effects_1_recall = recall_score(y_test_diseasers_or_side_effects_1, diseasers_or_side_effects_1_predictions, average='micro')

# Example evaluation for diseasers_or_side_effects_2 prediction (classification)
diseasers_or_side_effects_2_accuracy = accuracy_score(y_test_diseasers_or_side_effects_2, diseasers_or_side_effects_2_predictions)
diseasers_or_side_effects_2_precision = precision_score(y_test_diseasers_or_side_effects_2, diseasers_or_side_effects_2_predictions, average='micro')
diseasers_or_side_effects_2_recall = recall_score(y_test_diseasers_or_side_effects_2, diseasers_or_side_effects_2_predictions, average='micro')

# Example evaluation for treatments_1 prediction (classification)
treatments_1_accuracy = accuracy_score(y_test_treatments_1, treatments_1_predictions)
treatments_1_precision = precision_score(y_test_treatments_1, treatments_1_predictions, average='micro')
treatments_1_recall = recall_score(y_test_treatments_1, treatments_1_predictions, average='micro')

# Example evaluation for treatments_2 prediction (classification)
treatments_2_accuracy = accuracy_score(y_test_treatments_2, treatments_2_predictions)
treatments_2_precision = precision_score(y_test_treatments_2, treatments_2_predictions, average='micro')
treatments_2_recall = recall_score(y_test_treatments_2, treatments_2_predictions, average='micro')

diseasers_or_side_effects_1_model.fit(X, y_diseasers_or_side_effects_1)
diseasers_or_side_effects_2_model.fit(X, y_diseasers_or_side_effects_2)
treatments_1_model.fit(X, y_treatments_1)
treatments_2_model.fit(X, y_treatments_2)

# Print the evaluation results
print("Diseasers_or_side_effects_1 Accuracy:", diseasers_or_side_effects_1_accuracy)
print("Diseasers_or_side_effects_1 Precision:", diseasers_or_side_effects_1_precision)
print("Diseasers_or_side_effects_1 Recall:", diseasers_or_side_effects_1_recall)

print("Diseasers_or_side_effects_2 Accuracy:", diseasers_or_side_effects_2_accuracy)
print("Diseasers_or_side_effects_2 Precision:", diseasers_or_side_effects_2_precision)
print("Diseasers_or_side_effects_2 Recall:", diseasers_or_side_effects_2_recall)

print("Treatments_1 Accuracy:", treatments_1_accuracy)
print("Treatments_1 Precision:", treatments_1_precision)
print("Treatments_1 Recall:", treatments_1_recall)

print("Treatments_2 Accuracy:", treatments_2_accuracy)
print("Treatments_2 Precision:", treatments_2_precision)
print("Treatments_2 Recall:", treatments_2_recall)

from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score

# Create linear regression model
regression_model = LinearRegression()

# Train the model
# For diseasers_or_side_effects_1 prediction
diseasers_or_side_effects_1_model = LinearRegression()

# For diseasers_or_side_effects_2 prediction
diseasers_or_side_effects_2_model = LinearRegression()

# For treatments_1 prediction
treatments_1_model = LinearRegression()

# For treatments_2 prediction
treatments_2_model = LinearRegression()

# 2. Train the models
diseasers_or_side_effects_1_model.fit(X_train, y_train_diseasers_or_side_effects_1)
diseasers_or_side_effects_2_model.fit(X_train, y_train_diseasers_or_side_effects_2)
treatments_1_model.fit(X_train, y_train_treatments_1)
treatments_2_model.fit(X_train, y_train_treatments_2)

# 3. Make predictions
diseasers_or_side_effects_1_predictions = diseasers_or_side_effects_1_model.predict(X_test)
diseasers_or_side_effects_2_predictions = diseasers_or_side_effects_2_model.predict(X_test)
treatments_1_predictions = treatments_1_model.predict(X_test)
treatments_2_predictions = treatments_2_model.predict(X_test)

diseasers_or_side_effects_1_predictions = diseasers_or_side_effects_1_predictions.astype(y_test_diseasers_or_side_effects_1)
diseasers_or_side_effects_2_predictions = diseasers_or_side_effects_2_predictions.astype(y_test_diseasers_or_side_effects_2)
treatments_1_predictions = treatments_1_predictions.astype(y_test_treatments_1)
treatments_2_predictions = treatments_2_predictions.astype(y_test_treatments_2)

# Example evaluation for diseasers_or_side_effects_1 prediction (classification)
from sklearn.metrics import accuracy_score, precision_score, recall_score

diseasers_or_side_effects_1_accuracy = accuracy_score(y_test_diseasers_or_side_effects_1, diseasers_or_side_effects_1_predictions)
diseasers_or_side_effects_1_precision = precision_score(y_test_diseasers_or_side_effects_1, diseasers_or_side_effects_1_predictions, average='micro')
diseasers_or_side_effects_1_recall = recall_score(y_test_diseasers_or_side_effects_1, diseasers_or_side_effects_1_predictions, average='micro')

# Example evaluation for diseasers_or_side_effects_2 prediction (classification)
diseasers_or_side_effects_2_accuracy = accuracy_score(y_test_diseasers_or_side_effects_2, diseasers_or_side_effects_2_predictions)
diseasers_or_side_effects_2_precision = precision_score(y_test_diseasers_or_side_effects_2, diseasers_or_side_effects_2_predictions, average='micro')
diseasers_or_side_effects_2_recall = recall_score(y_test_diseasers_or_side_effects_2, diseasers_or_side_effects_2_predictions, average='micro')

# Example evaluation for treatments_1 prediction (classification)
treatments_1_accuracy = accuracy_score(y_test_treatments_1, treatments_1_predictions)
treatments_1_precision = precision_score(y_test_treatments_1, treatments_1_predictions, average='micro')
treatments_1_recall = recall_score(y_test_treatments_1, treatments_1_predictions, average='micro')

# Example evaluation for treatments_2 prediction (classification)
treatments_2_accuracy = accuracy_score(y_test_treatments_2, treatments_2_predictions)
treatments_2_precision = precision_score(y_test_treatments_2, treatments_2_predictions, average='micro')
treatments_2_recall = recall_score(y_test_treatments_2, treatments_2_predictions, average='micro')

# Print the evaluation results
print("Diseasers_or_side_effects_1 Accuracy:", diseasers_or_side_effects_1_accuracy)
print("Diseasers_or_side_effects_1 Precision:", diseasers_or_side_effects_1_precision)
print("Diseasers_or_side_effects_1 Recall:", diseasers_or_side_effects_1_recall)

print("Diseasers_or_side_effects_2 Accuracy:", diseasers_or_side_effects_2_accuracy)
print("Diseasers_or_side_effects_2 Precision:", diseasers_or_side_effects_2_precision)
print("Diseasers_or_side_effects_2 Recall:", diseasers_or_side_effects_2_recall)

print("Treatments_1 Accuracy:", treatments_1_accuracy)
print("Treatments_1 Precision:", treatments_1_precision)
print("Treatments_1 Recall:", treatments_1_recall)

print("Treatments_2 Accuracy:", treatments_2_accuracy)
print("Treatments_2 Precision:", treatments_2_precision)
print("Treatments_2 Recall:", treatments_2_recall)

diseasers_or_side_effects_1_model.fit(X, y_diseasers_or_side_effects_1)
diseasers_or_side_effects_2_model.fit(X, y_diseasers_or_side_effects_2)
treatments_1_model.fit(X, y_treatments_1)
treatments_2_model.fit(X, y_treatments_2)