Powered By Blogger

Thursday, February 27, 2025

DRUG EFFICACY, DOSE RESPONSE

CODE:


# Example extension to predict drug efficacy
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import GridSearchCV

# Define df_original: Replace this with your actual data
data_original = {
    'Name': ['Drug_A', 'Drug_B', 'Drug_C', 'Drug_D', 'Drug_E'],  # Example drug names
    'Efficacy': [0.8, 0.6, 0.9, 0.7, 0.5],  # Example efficacy values
    'Volume ų': [1964.45, 1780.27, 488.96, 375.4, 285.7],  # Example volume values
    'Surface Ų': [2366.68, 2400.5, 833.79, 736.43, 409.39],  # Example surface area values
    'Binding Affinity': [5.2, 4.8, 6.1, 5.5, 7.2],  # Example binding affinity values
    'ADMET_Absorption': [0.8, 0.7, 0.9, 0.6, 0.5],  # Example absorption values
    'ADMET_Distribution': [0.9, 0.8, 0.7, 0.9, 0.6],  # Example distribution values
    'Toxicity': [0.1, 0.2, 0.1, 0.3, 0.2],  # Example toxicity values
}

df_original = pd.DataFrame(data_original)

# Calculate volume to surface ratio
df_original['Volume_to_Surface_Ratio'] = df_original['Volume ų'] / df_original['Surface Ų']

# Define features (X) and target (y) for efficacy prediction
X_efficacy = df_original[['Volume ų', 'Surface Ų', 'Volume_to_Surface_Ratio', 'Binding Affinity', 'ADMET_Absorption', 'ADMET_Distribution', 'Toxicity']]
y_efficacy = df_original['Efficacy']

# Split data into training and testing sets for efficacy prediction
# Since we have only 5 samples, we cannot split into train and test sets effectively.
# For demonstration purposes, we'll use all data for training.
X_train_efficacy_scaled = StandardScaler().fit_transform(X_efficacy)
y_train_efficacy = y_efficacy

# Perform hyperparameter tuning for efficacy model
# Reduced cv to 3, which is less than the number of samples (5) in X_train_efficacy
param_grid_efficacy = {
    'n_estimators': [10, 50, 100],
    'max_depth': [None, 5, 10],
    'min_samples_split': [2, 5],
    'min_samples_leaf': [1, 5]
}

grid_search_efficacy = GridSearchCV(RandomForestRegressor(), param_grid_efficacy, cv=3, scoring='neg_mean_squared_error')
grid_search_efficacy.fit(X_train_efficacy_scaled, y_train_efficacy)

# Evaluate the best efficacy model
best_model_efficacy = grid_search_efficacy.best_estimator_
print(f"Best Parameters for Efficacy Model: {grid_search_efficacy.best_params_}")
print(f"Best Score for Efficacy Model: {-grid_search_efficacy.best_score_}")

# Example prediction for drug efficacy
example_input_efficacy = pd.DataFrame({
    'Volume ų': [1000],
    'Surface Ų': [1500],
    'Volume_to_Surface_Ratio': [1000/1500],
    'Binding Affinity': [5.5],
    'ADMET_Absorption': [0.8],
    'ADMET_Distribution': [0.9],
    'Toxicity': [0.2]
})

example_input_efficacy_scaled = StandardScaler().fit_transform(example_input_efficacy)
example_prediction_efficacy = best_model_efficacy.predict(example_input_efficacy_scaled)
print(f"Example Prediction for Drug Efficacy: {example_prediction_efficacy[0]}")

OUTPUT:

Best Parameters for Efficacy Model: {'max_depth': 5, 'min_samples_leaf': 1, 'min_samples_split': 2, 'n_estimators': 50} Best Score for Efficacy Model: 0.025899333333333333 Example Prediction for Drug Efficacy: 0.6400000000000002

DOSE RESPONSE CURVE:

CODE:

import numpy as np
import matplotlib.pyplot as plt

# Example data for Methyle Blue and another drug
methyle_blue_concentrations = np.logspace(-6, -3, 10)  # Log concentrations
methyle_blue_responses = np.array([10, 20, 30, 40, 50, 60, 70, 80, 90, 95])  # Example responses

other_drug_concentrations = np.logspace(-6, -3, 10)
other_drug_responses = np.array([5, 15, 25, 35, 45, 55, 65, 75, 85, 90])

# Plotting
plt.figure(figsize=(8, 6))
plt.plot(methyle_blue_concentrations, methyle_blue_responses, label='Methyle Blue')
plt.plot(other_drug_concentrations, other_drug_responses, label='Other Drug')
plt.xscale('log')  # Logarithmic scale for x-axis
plt.xlabel('Drug Concentration (M)')
plt.ylabel('Response (%)')
plt.title('Dose-Response Curve')
plt.legend()
plt.show()




No comments:

Post a Comment

Reviving Life and Redefining Medicine: The ConsciousLeaf Vision

  Date : April 08, 2025 Author : Mrinmoy Chakraborty, Chairman of Devise Foundation, in collaboration with Grok 3 (xAI) Introduction At Devi...