Commit aa7963e0 authored by IT20161538's avatar IT20161538

new commit

parent f6bb20e9
This source diff could not be displayed because it is too large. You can view the blob instead.
# -*- coding: utf-8 -*-
"""SideEffects_Treatments.ipynb
"""Final_SideEffects_Treatments.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1i7L4_HLgoGTfkpr9SIQUSVN8I2bLhfuG
https://colab.research.google.com/drive/1j7sqrPUFSTvquZgOla1nYNA7qg7Fg4yg
"""
import pandas as pd
......@@ -60,6 +60,25 @@ 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}})
......@@ -71,10 +90,10 @@ df = df.replace({'drug_type': { 'Heroin': 1,
'Cocaine': 5,
'Methamphetamine': 6}})
df = df.replace({'taking_co-occurring_substances': { 'Yes': 1,
df = df.replace({'taking_co_occurring_substances': { 'Yes': 1,
'No': 2}})
df = df.replace({'co-occurring_substances': { 'Cannabis': 1,
df = df.replace({'co_occurring_substances': { 'Cannabis': 1,
'Cocaine': 2,
'Hashish': 3,
'Heroin': 4,
......@@ -86,7 +105,7 @@ df = df.replace({'route_of_administration': { 'Inhalation': 1,
'Injection': 2,
'Smoking': 3}})
df = df.replace({'pre-existing_condision': { 'Yes': 1,
df = df.replace({'pre_existing_condision': { 'Yes': 1,
'No': 2}})
df = df.replace({'diseasers_or_side_effects_1': {'Addiction': 1,
......@@ -151,7 +170,7 @@ df = df.replace({'treatments_1': {'Behavioral Therapy, Medications, Support Grou
'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,
'Focus your attention on a distracting activity such as reading, singing, listening to music, gardening, or exercising': 9,
'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,
......@@ -265,14 +284,13 @@ for feature in selected_feature_names_target_treatments_2:
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(mg)', 'time_used(Month)', 'taking_co-occurring_substances', 'co-occurring_substances', 'route_of_administration', 'pre-existing_condision']]
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']
features_2 = df[['age', 'gender', 'drug_type', 'measures_of_drug_used_per_day(mg)', 'time_used(Month)', 'taking_co-occurring_substances', 'co-occurring_substances', 'route_of_administration', 'pre-existing_condision']]
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)
......@@ -280,10 +298,10 @@ X_train_diseasers_or_side_effects_1, X_test_diseasers_or_side_effects_1, y_train
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_2, target_treatments_1, test_size=0.2, random_state=42)
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_2, target_treatments_2, test_size=0.2, random_state=42)
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
......@@ -297,7 +315,7 @@ print("Training set shape for treatments_2 prediction:", X_train_treatments_2.sh
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(mg)', 'time_used(Month)', 'taking_co-occurring_substances', 'co-occurring_substances', 'route_of_administration', 'pre-existing_condision']]
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']
......@@ -411,15 +429,14 @@ new_person_data = pd.DataFrame({
'age': [45],
'gender': [2],
'drug_type': [1],
'measures_of_drug_used_per_day(mg)': [12],
'time_used(Month)': [15],
'taking_co-occurring_substances': [2],
'co-occurring_substances': [7],
'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]
'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)
......@@ -454,15 +471,15 @@ with open('/content/drive/MyDrive/Research/trained_model.pkl', 'wb') as file:
# Load the new data
new_person_data = pd.DataFrame({
'age': [44],
'gender': [1],
'drug_type': [2],
'measures_of_drug_used_per_day(mg)': [2],
'time_used(Month)': [7],
'taking_co-occurring_substances': [1],
'co-occurring_substances': [6],
'route_of_administration': [3],
'pre-existing_condision':[2]
'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
......@@ -594,15 +611,15 @@ with open('/content/drive/MyDrive/Research/trained_model.pkl', 'wb') as file:
# Load the new data
new_person_data = pd.DataFrame({
'age': [44],
'gender': [1],
'drug_type': [2],
'measures_of_drug_used_per_day(mg)': [10],
'time_used(Month)': [12],
'taking_co-occurring_substances': [1],
'co-occurring_substances': [6],
'route_of_administration': [3],
'pre-existing_condision':[2]
'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
......@@ -734,15 +751,15 @@ with open('/content/drive/MyDrive/Research/trained_model.pkl', 'wb') as file:
# Load the new data
new_person_data = pd.DataFrame({
'age': [44],
'gender': [1],
'drug_type': [2],
'measures_of_drug_used_per_day(mg)': [10],
'time_used(Month)': [12],
'taking_co-occurring_substances': [1],
'co-occurring_substances': [6],
'route_of_administration': [3],
'pre-existing_condision':[2]
'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
......@@ -874,15 +891,15 @@ with open('/content/drive/MyDrive/Research/trained_model.pkl', 'wb') as file:
# Load the new data
new_person_data = pd.DataFrame({
'age': [44],
'gender': [1],
'drug_type': [2],
'measures_of_drug_used_per_day(mg)': [10],
'time_used(Month)': [12],
'taking_co-occurring_substances': [1],
'co-occurring_substances': [6],
'route_of_administration': [3],
'pre-existing_condision':[2]
'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
......@@ -1003,3 +1020,241 @@ else:
# 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)
\ No newline at end of file
......@@ -267,7 +267,7 @@ def sideEffectTreatments(new_person_data):
elif treatments_1_prediction == 9:
treatments_1 = 'Focus your attention on a distracting activity such as reading, singing, listening to music, gardening, or exercising'
treatments_1 = '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'
elif treatments_1_prediction == 10:
......@@ -372,7 +372,7 @@ def sideEffectTreatments(new_person_data):
elif treatments_2_prediction == 9:
treatments_2 = 'Focus your attention on a distracting activity such as reading, singing, listening to music, gardening, or exercising'
treatments_2 = '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'
elif treatments_2_prediction == 10:
......
......@@ -7,29 +7,7 @@ import './DestinationStyles.css';
const Destination = () => {
return(
<div className="destination">
<h1>Popular Destination</h1>
<p>Tours give you the opportunity to see a lot,within a time frame.</p>
<DestinationData
className='first-des'
heading='Sydney Opera House'
text="The Sydney Opera House is a multi-venue performing arts centre in Sydney. Located on the foreshore of Sydney Harbour, it is widely regarded as one of the world's most famous and distinctive buildings and a masterpiece of 20th-century architecture."
img1={Mountain1}
img2={Mountain2}
/>
<DestinationData
className='first-des-reverse'
heading='Eiffel Tower'
text="The Eiffel Tower is a wrought-iron lattice tower on the Champ de Mars in Paris, France. It is named after the engineer Gustave Eiffel, whose company designed and built the tower. Locally nicknamed 'La dame de fer', it was constructed from 1887 to 1889 as the centerpiece of the 1889 World's Fair."
img1={Mountain3}
img2={Mountain4}
/>
</div>
<div className="destination"></div>
)
}
......
import './FeaturesStyles.css';
import React from 'react';
import TripData from './FeaturesData';
import Trip1 from '../assets/5.jpg';
import Trip2 from '../assets/6.jpg';
import Trip3 from '../assets/8.jpg';
import Trip1 from '../assets/face.png';
import Trip2 from '../assets/drug.jpg';
import Trip3 from '../assets/sideeffects.png';
import Trip4 from '../assets/rehabilitation.jpg';
import { Link } from "react-router-dom";
......@@ -17,24 +18,24 @@ export default function Trip() {
<TripData
Link="/test"
image={Trip1}
heading="Thisara"
heading="Image-based Substance Abuse Detection"
/>
<TripData
image={Trip3}
heading="Ravindu"
image={Trip2}
heading="Drug Type & Addiction Status"
/>
<TripData
Link="/sideEffectsAndTreatments"
image={Trip2}
image={Trip3}
heading="Side Effects & Treatments"
/>
<TripData
image={Trip1}
heading="Rehabilitation Process"
image={Trip4}
heading="Rehabilitation Status"
/>
</div>
......
......@@ -26,8 +26,8 @@
}
.form{
width: 35vw;
height: 950px;
width: 37vw;
height: 915px;
display: flex;
flex-direction: column;
justify-content: start;
......@@ -71,8 +71,30 @@ input{
margin-right:400px;
}
.input-group1{
.input-group1 {
text-align: left;
}
align-items: left;
.input-group1 p {
font-weight: bold;
margin-bottom: 5px;
}
.input-group1 ul {
list-style-type: none;
padding-left: 0;
}
.input-group1 li {
margin-bottom: 10px;
}
.error-message {
color: red;
font-size: 14px;
margin-top: 5px;
}
.required-star {
color: red;
}
\ No newline at end of file
......@@ -13,6 +13,8 @@ function SideEffectsAndTreatments() {
const [coOccurringSubstances, setCoOccurringSubstances] = useState('');
const [preExistingMedicalCondition, setPreExistingMedicalCondition] = useState('');
const [predictions, setPredictions] = useState(null);
const [formSubmitted, setFormSubmitted] = useState(false);
const mapGender = (selectedGender) => {
switch (selectedGender) {
......@@ -93,6 +95,52 @@ function SideEffectsAndTreatments() {
try {
// Form validation
if (!age) {
setFormSubmitted(true);
return;
}
if (!drugType) {
setFormSubmitted(true);
return;
}
if (!drugUsageMg) {
setFormSubmitted(true);
return;
}
if (!months) {
setFormSubmitted(true);
return;
}
if (!gender) {
setFormSubmitted(true);
return;
}
if (!routeOfAdministration) {
setFormSubmitted(true);
return;
}
if (!takingCooccurringSubstances) {
setFormSubmitted(true);
return;
}
if (!coOccurringSubstances) {
setFormSubmitted(true);
return;
}
if (!preExistingMedicalCondition) {
setFormSubmitted(true);
return;
}
//console.log('Parsed Data:', requestData);
const genderValue = mapGender(gender);
const drugTypeValue = mapDrugTypeToValue(drugType);
......@@ -133,18 +181,20 @@ function SideEffectsAndTreatments() {
<h1 className='title'>Side Effect & Treatments</h1><br/>
<form onSubmit={handleSubmit} className='form'>
<div className='input-group'>
<label>Age: </label>
<input type='number' placeholder='Age' value={age} onChange={(e)=>{setAge(e.target.value)}}/>
<label>Age <span className='required-star'> *</span>:</label>
<input type='number' placeholder='Age' value={age} onChange={(e) => {const inputValue = e.target.value;if (/^\d+$/.test(inputValue) || inputValue === '') {setAge(inputValue);}}}/>
{formSubmitted && !age && (<div className='error-message'>Age is Required!</div>)}
</div>
<div className='input-group'>
<label>Gender: </label>
<label>Gender<span className='required-star'> *</span>: </label>
<input type='radio' name='gender' value='male' onChange={(e) => setGender(e.target.value)}/>
<span>Male</span>
<input type='radio' name='gender' value='female' onChange={(e) => setGender(e.target.value)}/>
<span>Female</span>
{formSubmitted && !gender && (<div className='error-message'>Gender is Required!</div>)}
</div>
<div className='input-group'>
<label>Drug Type: </label>
<label>Drug Type<span className='required-star'> *</span>: </label>
<select value={drugType} name="drugtype" onChange={(e) => setDrugType(e.target.value)}>
<option>Choose a Drug Type</option>
<option>Heroin</option>
......@@ -154,17 +204,20 @@ function SideEffectsAndTreatments() {
<option>Cocaine</option>
<option>Methamphetamine</option>
</select>
{formSubmitted && !drugType && (<div className='error-message'>Drug Type is Required!</div>)}
</div>
<div className='input-group'>
<label>Measures of drug used per day(mg): </label>
<input type='number' placeholder='mg' value={drugUsageMg} onChange={(e)=>{setDrugUsageMg(e.target.value)}}/>
<label>Measures of drug used per day(mg)<span className='required-star'> *</span>: </label>
<input type='number' placeholder='mg' value={drugUsageMg} onChange={(e) => {const inputValue = e.target.value;if (/^\d+$/.test(inputValue) || inputValue === '') {setDrugUsageMg(inputValue);}}}/>
</div>
{formSubmitted && !drugUsageMg && (<div className='error-message'>Measures of drug used per day is Required!</div>)}
<div className='input-group'>
<label>Time Used(Month): </label>
<input type='number' placeholder='No of months' value={months} onChange={(e)=>{setMonths(e.target.value)}}/>
<label>Time Used(Month)<span className='required-star'> *</span>: </label>
<input type='number' placeholder='No of months' value={months} onChange={(e) => {const inputValue = e.target.value;if (/^\d+$/.test(inputValue) || inputValue === '') {setMonths(inputValue);}}}/>
{formSubmitted && !months && (<div className='error-message'>Time Used is Required!</div>)}
</div>
<div className='input-group'>
<label>Route of Administration: </label>
<label>Route of Administration<span className='required-star'> *</span>: </label>
<select value={routeOfAdministration} name="route_of_administration " onChange={(e) => setRouteOfAdministration(e.target.value)}>
<option>Choose a Route of Administration</option>
<option>Inhalation</option>
......@@ -172,15 +225,17 @@ function SideEffectsAndTreatments() {
<option>Smoking</option>
</select>
</div>
{formSubmitted && !routeOfAdministration && (<div className='error-message'>Route of Administration is Required!</div>)}
<div className='input-group'>
<label>Taking Co-occurring Substances: </label>
<label>Taking Co-occurring Substances<span className='required-star'> *</span>: </label>
<input type='radio' name='takingCooccurringSubstances' value='yes' checked={takingCooccurringSubstances === 'yes'} onChange={() => setTakingCooccurringSubstances('yes')}/>
<span>Yes</span>
<input type='radio' name='takingCooccurringSubstances' value='no' checked={takingCooccurringSubstances === 'no'} onChange={() => setTakingCooccurringSubstances('no')}/>
<span>No</span>
</div>
{formSubmitted && !takingCooccurringSubstances && (<div className='error-message'>Taking Co-occurring Substances is Required!</div>)}
<div className='input-group'>
<label>Co-occurring Substances: </label>
<label>Co-occurring Substances<span className='required-star'> *</span>: </label>
<select value={coOccurringSubstances} name="co-occurringsubstances " onChange={(e) => setCoOccurringSubstances(e.target.value)}>
<option>Choose a Co-occurring Substances</option>
<option>Cannabis</option>
......@@ -192,19 +247,35 @@ function SideEffectsAndTreatments() {
<option>No</option>
</select>
</div>
{formSubmitted && !coOccurringSubstances && (<div className='error-message'>Co-occurring Substances is Required!</div>)}
<div className='input-group'>
<label>Any pre-existing medical conditions?: </label>
<label>Any pre-existing medical conditions?<span className='required-star'> *</span>: </label>
<input type='radio' name='preExistingmedicalcondition' value='yes' checked={preExistingMedicalCondition === 'yes'} onChange={() => setPreExistingMedicalCondition('yes')}/>
<span>Yes</span>
<input type='radio' name='preExistingmedicalcondition' value='no' checked={preExistingMedicalCondition === 'no'} onChange={() => setPreExistingMedicalCondition('no')}/>
<span>No</span>
</div>
{formSubmitted && !preExistingMedicalCondition && (<div className='error-message'>Pre-existing medical conditions is Required!</div>)}
<div className='btn-area'>
<button type="submit" className='btn'>Predict</button>
</div>
<div className='input-group1'>
{predictions && (<p>Predictions: {JSON.stringify(predictions)}</p>)}
{predictions && (
<div>
<p><h1>Predictions</h1></p>
<ul>
{Object.keys(predictions).map((key) => {
const predictionText = predictions[key];
return (
<li key={key}>
<strong>{key}:</strong> {predictionText}
</li>
);
})}
</ul>
</div>
)}
</div>
</form>
</div></div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment