<jupyter_start><jupyter_text>S2RSLDB: a comprehensive manually curated, internet-accessible database of the sigma-2 receptor selective ligands  Imports<jupyter_code>from smdt import datasets
from smdt import data_processing
from smdt import molecular_descriptors
from smdt import regression
import pandas as pd<jupyter_output><empty_output><jupyter_text>Data  Reading Data<jupyter_code>Sigma2 = datasets.load_Sigma2ReceptorLigands()
Sigma2['Target'][0]
import numpy as np
-np.log10(2.1e-10)<jupyter_output><empty_output><jupyter_text>Calculating Descriptors<jupyter_code>data = molecular_descriptors.getAllDescriptors(Sigma2)
data = pd.read_csv('data.csv')<jupyter_output><empty_output><jupyter_text>Data Cleaning<jupyter_code>y = data['Target']
X = data.drop(['Target'], axis=1)<jupyter_output><empty_output><jupyter_text>Train Test Split<jupyter_code>from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
X_train.shape
X_test.shape
from sklearn.preprocessing import StandardScaler, Imputer
from sklearn.feature_selection import SelectKBest, mutual_info_regression
a = Imputer(missing_values='NaN', strategy='median', axis=0)
b = StandardScaler()
c = SelectKBest(score_func=mutual_info_regression)
X_train = b.fit_transform(X_train)
X_train = c.fit_transform(X_train,y_train)
mask = c.get_support()
new_features = X_train.columns[mask]
new_features<jupyter_output><empty_output><jupyter_text>Models  Random Forest<jupyter_code>model1, y_pred1, metrics1 = regression.fit_RandomForestRegressor(X_train, X_test, y_train, y_test)<jupyter_output><empty_output><jupyter_text>Lasso<jupyter_code>model2, y_pred2, metric2 = regression.fit_Lasso(X_train, X_test, y_train, y_test)<jupyter_output><empty_output><jupyter_text>Ridge<jupyter_code>model3, y_pred3, metric3 = regression.fit_Ridge(X_train, X_test, y_train, y_test)<jupyter_output><empty_output><jupyter_text>ElasticNet<jupyter_code>model4, y_pred4, metric4 = regression.fit_ElasticNet(X_train, X_test, y_train, y_test)<jupyter_output><empty_output><jupyter_text>Linear SVR<jupyter_code>model5, y_pred5, metric5 = regression.fit_LinearSVR(X_train, X_test, y_train, y_test)
import numpy as np
y_pred1 = np.load('ypred1.npy')
y_pred2 = np.load('ypred2.npy')
y_pred3 = np.load('ypred3.npy')
y_pred4 = np.load('ypred4.npy')
y_pred5 = np.load('ypred5.npy')

metric1 = np.load('metric1.npy')
metric2 = np.load('metric2.npy')
metric3 = np.load('metric3.npy')
metric4 = np.load('metric4.npy')
metric5 = np.load('metric5.npy')<jupyter_output><empty_output><jupyter_text>Parity Plots<jupyter_code>import matplotlib.pyplot as plt

plt.figure(figsize=(20,4))
plt.subplot(151)
plt.scatter(y_test, y_pred1, edgecolors=(0, 0, 0), alpha=0.5)
plt.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()],'r--', lw=4)
plt.xlabel('Measured')
plt.ylabel('Predicted')
plt.title('Parity Plot for Random Forest')

plt.subplot(152)
plt.scatter(y_test, y_pred2, edgecolors=(0, 0, 0), alpha=0.5)
plt.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()],'r--', lw=4)
plt.xlabel('Measured')
plt.ylabel('Predicted')
plt.title('Parity Plot for Lasso')

plt.subplot(153)
plt.scatter(y_test, y_pred3, edgecolors=(0, 0, 0), alpha=0.5)
plt.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()],'r--', lw=4)
plt.xlabel('Measured')
plt.ylabel('Predicted')
plt.title('Parity Plot for Ridge')

plt.subplot(154)
plt.scatter(y_test, y_pred4, edgecolors=(0, 0, 0), alpha=0.5)
plt.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()],'r--', lw=4)
plt.xlabel('Measured')
plt.ylabel('Predicted')
plt.title('Parity Plot for ElasticNet')

plt.subplot(155)
plt.scatter(y_test, y_pred5, edgecolors=(0, 0, 0), alpha=0.5)
plt.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()],'r--', lw=4)
plt.xlabel('Measured')
plt.ylabel('Predicted')
plt.title('Parity Plot for Linear SVR')

plt.show()
metric1
results = pd.DataFrame([metric1,metric2,metric3,metric4,metric5])
name = ['Random Forest','Lasso','Ridge','ElasticNet','Linear SVR']
results[0] = name
results.columns = ['Model','r2 score','mae','mse','median ae','explained variance score']
results
Sigma2<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15821885362387494, 'fraction_numerical': 0.027475130270014213, 'mean_word_length': 8.983451536643026, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '662147', 'license': 'MIT', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1693, 'n_words': 265, 'path': 'notebooks/Sigma-2 Receptor Selective Ligands.ipynb', 'repo_name': 'NeerajPise/PyMolSAR', 'size': '4222'}