import plotly.io as pio
pio.renderers.default='notebook'
import pandas as pd
data_PCA = pd.read_csv('PCA.csv')
data_benign = data_PCA[data_PCA['label'] == 1]
data_anomalous = data_PCA[data_PCA['label'] == -1]
data_PCA.head()
PC1 | PC2 | label | |
---|---|---|---|
0 | 6.506169 | -3.201140 | 1 |
1 | -5.059782 | -3.096441 | 1 |
2 | -5.117938 | -2.545275 | -1 |
3 | -5.107139 | -2.778367 | 1 |
4 | -5.624349 | -3.097940 | 1 |
import plotly.express as px
fig = px.density_contour(data_PCA, x="PC1", y="PC2", color="label")
fig.show()
import plotly.graph_objects as go
fig = go.Figure()
trace1 = go.Histogram2d(x=data_benign.PC1,y=data_benign.PC2, opacity = 0.8, xbins = {'start':-8, 'end':8, 'size': 0.5}, ybins = {'start':-8, 'end':8, 'size': 0.5}, colorscale = 'Greens', showscale = False)
fig.add_trace(trace1)
trace2 = go.Histogram2d(x=data_anomalous.PC1,y=data_anomalous.PC2, opacity = 0.8, xbins = {'start':-8, 'end':8, 'size': 0.5}, ybins = {'start':-8, 'end':8, 'size': 0.5}, colorscale = 'Reds', showscale = False)
fig.add_trace(trace2)
fig = go.Figure()
trace1 = go.Histogram2dContour(x = data_benign['PC1'], y = data_benign['PC2'], opacity = 1, colorscale = 'Blues', xbins = {'start':-8, 'end':8, 'size': 1}, ybins = {'start':-8, 'end':8, 'size': 1}, showscale = False)
fig.add_trace(trace1)
trace2 = go.Histogram2dContour(x = data_anomalous['PC1'], y = data_anomalous['PC2'], opacity = 0.5, colorscale = 'Reds', xbins = {'start':-8, 'end':8, 'size': 1}, ybins = {'start':-8, 'end':8, 'size': 1}, showscale = False)
fig.add_trace(trace2)