-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patht_sne.py
118 lines (95 loc) · 3.42 KB
/
t_sne.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from sklearn.manifold import TSNE
from dataset.attributes import Attributes
from dataset.sampling import sample
from reduction_plot import DRType, dr_plot_2d, dr_plot_3d
attr = Attributes()
def t_sne_weather_plot(percentage, dim, perplexity=30):
df = sample(percentage)
# Weather
dff = df[attr.get_weather_attributes()]
data_size = dff.shape[0]
if dim == '2D':
tsne = TSNE(n_components=2, random_state=0, perplexity=perplexity)
proj = tsne.fit_transform(dff)
return dr_plot_2d(
df,
proj[:, 0],
proj[:, 1],
Attributes.temperature,
f"t-Distributed Stochastic Neighbor Embedding | Size {data_size} | Perplexity {perplexity}",
attr.get_hover_data_for_weather(),
DRType.TSNE
)
elif dim == '3D':
tsne = TSNE(n_components=3, random_state=0, perplexity=perplexity)
proj = tsne.fit_transform(dff)
return dr_plot_3d(
df,
proj[:, 0],
proj[:, 1],
proj[:, 2],
Attributes.temperature,
f"t-Distributed Stochastic Neighbor Embedding | Size {data_size} | Perplexity {perplexity}",
attr.get_hover_data_for_weather(),
DRType.TSNE
)
def t_sne_electric_plot(percentage, dim, perplexity=30):
df = sample(percentage)
# Appliance
dff = df[attr.get_appliance_attributes()]
data_size = dff.shape[0]
if dim == '2D':
tsne = TSNE(n_components=2, random_state=0, perplexity=perplexity)
proj = tsne.fit_transform(dff)
return dr_plot_2d(
df,
proj[:, 0],
proj[:, 1],
Attributes.total_energy_consumption,
f"t-Distributed Stochastic Neighbor Embedding | Size {data_size} | Perplexity {perplexity}",
attr.get_hover_data_for_electric(),
DRType.TSNE
)
if dim == '3D':
tsne = TSNE(n_components=3, random_state=0, perplexity=perplexity)
proj = tsne.fit_transform(dff)
return dr_plot_3d(
df,
proj[:, 0],
proj[:, 1],
proj[:, 2],
Attributes.total_energy_consumption,
f"t-Distributed Stochastic Neighbor Embedding | Size {data_size} | Perplexity {perplexity}",
attr.get_hover_data_for_electric(),
DRType.TSNE
)
def t_sne_all_plot(percentage, dim, perplexity=30):
df = sample(percentage)
# All
dff = df[attr.all_attributes()]
data_size = dff.shape[0]
if dim == '2D':
tsne = TSNE(n_components=3, random_state=0, perplexity=perplexity)
proj = tsne.fit_transform(dff)
return dr_plot_2d(
df,
proj[:, 0],
proj[:, 1],
Attributes.temperature,
f"t-Distributed Stochastic Neighbor Embedding | Size {data_size} | Perplexity {perplexity}",
attr.get_hover_data_for_all(),
DRType.TSNE
)
if dim == '3D':
tsne = TSNE(n_components=3, random_state=0, perplexity=perplexity)
proj = tsne.fit_transform(dff)
return dr_plot_3d(
df,
proj[:, 0],
proj[:, 1],
proj[:, 2],
Attributes.total_energy_consumption,
f"t-Distributed Stochastic Neighbor Embedding | Size {data_size} | Perplexity {perplexity}",
attr.get_hover_data_for_all(),
DRType.TSNE
)