text_plain_output_1.png
from sklearn.cluster import DBSCAN

from sklearn.preprocessing import MinMaxScaler

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

df = pd.read_csv('../input/combineddataset/Combined.csv')
for i in ['Mode', 'Sample Number', 'Seconds', 'Minutes', 'Hours', 'Date', 'Month']:
    df[i] = pd.to_numeric(df[i], downcast='integer')

data = df.copy()
data = data[:10000]
data = data.drop(['Sample Number', 'Seconds', 'Minutes', 'Hours', 'Date', 'Month'], axis=1)
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
num2 = scaler.fit_transform(data.drop(['timestamp'], axis=1))
num2 = pd.DataFrame(num2, columns=data.drop(['timestamp'], axis=1).columns)

from sklearn.cluster import DBSCAN
outlier_detection = DBSCAN(eps=0.2, metric='euclidean', min_samples=5, n_jobs=-1)
clusters = outlier_detection.fit_predict(num2)

clusters.shape

data['anomaly'] = pd.Series(clusters)

data.columns

anomaly_ind = data[data['anomaly'] == -1].index
normal_ind = data[data['anomaly'] != -1].index

anomaly_pca = pd.DataFrame(data_pca[anomaly_ind])
normal_pca = pd.DataFrame(data_pca[normal_ind])
anomaly_pca