<jupyter_start><jupyter_text>Case Study by: <NAME>  Domain –Chemical Industry focus –Classify chemical Business challenge/requirement FuPont is a leading chemical company across the globe.  The Company is on a CSR (Corporate Social Responsibility) mission. It wants to identify biodegradable products based on a study of the relationships between chemical structure and biodegradation of molecules. You as ML expert have to create a ML model to classify the chemical structure as  'Ready BioDegradable' –RB vs 'Not Ready Biodegradable' –NRB    Key issues - Data has lots of attributes and classification could be tricky    Considerations-NONE    Data volume-Approx 1055   records –file bio-degradabale-data.csv Fields in Data    •Details in .ipynb notebook    Additional information-NA    Business benefitsResearch can lead FuPont to create truly unique Biodegradable packaging material. This could lead to massive profits in future  Data Set : QSAR BioDegradation Data SetThe data have been used to develop QSAR (Quantitative Structure Activity Relationships) models for the study of the relationships between chemical structure and biodegradation of molecules. Biodegradation experimental values of 1055 chemicals were collected.Data can be found on UCI Machine Learning Repository: https://archive.ics.uci.edu/ml/datasets/QSAR+biodegradationAttribute Information:1) SpMax_L: Leading eigenvalue from Laplace matrix 2) J_Dz(e): Balaban-like index from Barysz matrix weighted by Sanderson electronegativity 3) nHM: Number of heavy atoms 4) F01[N-N]: Frequency of N-N at topological distance 1 5) F04[C-N]: Frequency of C-N at topological distance 4 6) NssssC: Number of atoms of type ssssC 7) nCb-: Number of substituted benzene C(sp2) 8) C%: Percentage of C atoms 9) nCp: Number of terminal primary C(sp3) 10) nO: Number of oxygen atoms 11) F03[C-N]: Frequency of C-N at topological distance 3 12) SdssC: Sum of dssC E-states 13) HyWi_B(m): Hyper-Wiener-like index (log function) from Burden matrix weighted by mass 14) LOC: Lopping centric index 15) SM6_L: Spectral moment of order 6 from Laplace matrix 16) F03[C-O]: Frequency of C - O at topological distance 3 17) Me: Mean atomic Sanderson electronegativity (scaled on Carbon atom) 18) Mi: Mean first ionization potential (scaled on Carbon atom) 19) nN-N: Number of N hydrazines 20) nArNO2: Number of nitro groups (aromatic) 21) nCRX3: Number of CRX3 22) SpPosA_B(p): Normalized spectral positive sum from Burden matrix weighted by polarizability 23) nCIR: Number of circuits 24) B01[C-Br]: Presence/absence of C - Br at topological distance 1 25) B03[C-Cl]: Presence/absence of C - Cl at topological distance 3 26) N-073: Ar2NH / Ar3N / Ar2N-Al / R..N..R 27) SpMax_A: Leading eigenvalue from adjacency matrix (Lovasz-Pelikan index) 28) Psi_i_1d: Intrinsic state pseudoconnectivity index - type 1d 29) B04[C-Br]: Presence/absence of C - Br at topological distance 4 30) SdO: Sum of dO E-states 31) TI2_L: Second Mohar index from Laplace matrix 32) nCrt: Number of ring tertiary C(sp3) 33) C-026: R--CX--R 34) F02[C-N]: Frequency of C - N at topological distance 2 35) nHDon: Number of donor atoms for H-bonds (N and O) 36) SpMax_B(m): Leading eigenvalue from Burden matrix weighted by mass 37) Psi_i_A: Intrinsic state pseudoconnectivity index - type S average 38) nN: Number of Nitrogen atoms 39) SM6_B(m): Spectral moment of order 6 from Burden matrix weighted by mass 40) nArCOOR: Number of esters (aromatic) 41) nX: Number of halogen atoms 42) experimental class: ready biodegradable (RB) and not ready biodegradable (NRB)<jupyter_code>import pandas as pd 
import numpy as np
names = ['SpMax_L', 'J_Dz', 'nHM', 'F01[N-N]', 'F04[C-N]', 'NssssC', 'nCb-', 'C%','nCp','nO','F03[C-N]','SdssC','HyWi_B','LOC','SM6_L','F03[C-O]','Me','Mi','nN-N','nArNO2','nCRX3','SpPosA','nCIR','B01[C-Br]','B03[C-Cl]','N-073','SpMax_A','Psi_i_1d','B04[C-Br]','SdO','TI2_L','nCrt','C-026','F02[C-N]','nHDon','SpMax_B','Psi_i_A','nN','SM6_B','nArCOOR','nX','experimentalclass']
df = pd.read_csv('bio-degradabale-data.csv',sep=';',names=names)
df
df.info()
import seaborn as sns

sns.countplot(df['experimentalclass'])
from sklearn.preprocessing import LabelEncoder
labelencoder = LabelEncoder()

df['experimentalclass'] = labelencoder.fit_transform(df['experimentalclass'])
df<jupyter_output><empty_output><jupyter_text>Input and Output Variables<jupyter_code>X = df.loc[:,'SpMax_L':'nX']
y = df['experimentalclass']<jupyter_output><empty_output><jupyter_text>Scaling the data<jupyter_code>from sklearn.preprocessing import StandardScaler
sc = StandardScaler()

X_scaled = sc.fit_transform(X)
X_scaled = pd.DataFrame(X_scaled, columns=X.columns)
X_scaled<jupyter_output><empty_output><jupyter_text>Logistic Regression Model<jupyter_code>from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
x_train, x_test, y_train, y_test = train_test_split(X_scaled,y, test_size=0.3, random_state=10)
model = LogisticRegression()
model.fit(x_train, y_train)
y_pred = model.predict(x_test)
from sklearn import metrics
from sklearn.model_selection import cross_val_score
metrics.accuracy_score(y_test,y_pred)<jupyter_output><empty_output><jupyter_text>Cross Validation<jupyter_code>cross_val_score(model,X_scaled,y,cv=10,scoring='accuracy').mean()
metrics.confusion_matrix(y_test,y_pred)
print(metrics.classification_report(y_test,y_pred))<jupyter_output>precision    recall  f1-score   support

           0       0.90      0.92      0.91       212
           1       0.82      0.79      0.81       105

    accuracy                           0.87       317
   macro avg       0.86      0.85      0.86       317
weighted avg       0.87      0.87      0.87       317<jupyter_text>Ada Boost Classifier<jupyter_code>from sklearn.ensemble import AdaBoostClassifier #For Classification
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import cross_val_score
def get_result_score(num_trees):
    model = AdaBoostClassifier(n_estimators=num_trees, random_state=100)
    results = cross_val_score(model,X_scaled,y, cv=10)
    return results.mean()
num_tree_list = [50,75,100,150,200,250,300]
for num_tree_count in num_tree_list:
    score = get_result_score(num_tree_count)
    print ("Score for {} count is {}:".format(num_tree_count,score))<jupyter_output>Score for 50 count is 0.8330637915543576:
Score for 75 count is 0.8359209344115005:
Score for 100 count is 0.8340161725067385:
Score for 150 count is 0.8510691823899371:
Score for 200 count is 0.8444294699011682:
Score for 250 count is 0.8406469002695418:
Score for 300 count is 0.8350044923629831:
{'fraction_non_alphanumeric': 0.09477959981946743, 'fraction_numerical': 0.057469535128629456, 'mean_word_length': 5.213084112149533, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '360912', 'license': 'MIT', 'n_tokens_mistral': 2528, 'n_tokens_neox': 2176, 'n_words': 708, 'path': 'Machine Learning/Model Selection and Boosting/Module 14 - Case Studies/Module-14 - Case Study 1.ipynb', 'repo_name': 'mohammedsaqlainattar/Python-for-Data-Science', 'size': '6663'}