<jupyter_start><jupyter_text><jupyter_code>from sklearn.cluster import KMeans
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
from sklearn.model_selection import train_test_split



import seaborn as sns

from mpl_toolkits.mplot3d import axes3d    

pd.set_option('precision', 2)
from google.colab import drive
path = '/content/Plume_reno.csv'
df = pd.read_csv(path)

df = pd.read_csv('/content/Plume_reno.csv',header=0)


df['time'] = df['time'].astype(str)+ df['loc'].astype(str)
df['time'] = df['time'].astype(int)
df.drop('loc', inplace=True, axis=1)
df = df.groupby((['time','pol']), as_index=False)['conc'].mean()
#(['col5','col2'])
df['conc'].fillna(0, inplace=True)
df


df1 = df.pivot(index='time', columns='pol', values='conc')
df
df['pol'].replace({'Atenolol': 1, 'Atrazin': 2, 'Azithromycin':3,	'Benzotriazol':4,	'Bezafibrat':5,	'Carbamazepin':6, 'Carbendazim':7,	'Chloridazon':8,	'Ciprofloxacin':9,	'Clarithromycin':10,	'Clindamycin':11,	'Clofibric acid':12, 'Diclofenac':13, 'Diuron':14,	'Gabapentin':15,	'Gemfibrocil':16,	'Iopamidol':17,	'IPBC':18,	'Irgarol':19,	'Isoproturon':20, 'Ketoprofen':21,	'Mecoprop':22,	'Mefenamic acid':23,	'Methylbenzotriazol':24,	'Metoprolol':25,	'Metronidazol':26,	'Naproxen':27,	'Norfloxacin':28,	'Ofloxacin':29,	'Paracetamol':30,	'Primidon':31,'Propiconazol':32,	'Propranolol':33,	'Simvastatin':34,	'Sotalol':35,	'Sulfamethoxazol':36,	'Terbutryn':37,	'Trimethoprim':38}, inplace=True)
df['pol'] = df['pol'].astype(float)
km = KMeans(n_clusters=2)
y_predicted = km.fit_predict(df)
df['cluster']=y_predicted
x,y = df()
x_train, x_test, y_train, y_test = train_test_split(x, y)

# Silhouette Score for K means
# Import ElbowVisualizer




from yellowbrick.classifier import ClassificationReport
from sklearn.linear_model import LogisticRegression

model = LogisticRegression()
visualizer = ClassificationReport(model)

visualizer.fit(X_train, y_train)
visualizer.score(X_test, y_test)
visualizer.show()





from yellowbrick.cluster import KElbowVisualizer
model = KMeans()

X,y = df()

# k is range of number of clusters.
visualizer = KElbowVisualizer(model, k=(2,5),metric='silhouette', timings= True)
visualizer.fit(X)        # Fit the data to the visualizer
visualizer.show()        # Finalize and render the figure<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16456759026028547, 'fraction_numerical': 0.03316540722082284, 'mean_word_length': 7.541218637992832, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '307674', 'license': 'MIT', 'n_tokens_mistral': 1037, 'n_tokens_neox': 946, 'n_words': 180, 'path': 'Project_3_reno.ipynb', 'repo_name': 'DuaneHsa/2022_ML_Earth_Env_Sci', 'size': '2382'}