74
74
from sklearn import cluster , covariance , manifold
75
75
76
76
77
- ## #############################################################################
77
+ # #############################################################################
78
78
# Retrieve the data from Internet
79
79
80
80
def quotes_historical_google (symbol , date1 , date2 ):
@@ -189,7 +189,7 @@ def quotes_historical_google(symbol, date1, date2):
189
189
variation = close_prices - open_prices
190
190
191
191
192
- ## #############################################################################
192
+ # #############################################################################
193
193
# Learn a graphical structure from the correlations
194
194
edge_model = covariance .GraphLassoCV ()
195
195
@@ -199,7 +199,7 @@ def quotes_historical_google(symbol, date1, date2):
199
199
X /= X .std (axis = 0 )
200
200
edge_model .fit (X )
201
201
202
- ## #############################################################################
202
+ # #############################################################################
203
203
# Cluster using affinity propagation
204
204
205
205
_ , labels = cluster .affinity_propagation (edge_model .covariance_ )
@@ -208,7 +208,7 @@ def quotes_historical_google(symbol, date1, date2):
208
208
for i in range (n_labels + 1 ):
209
209
print ('Cluster %i: %s' % ((i + 1 ), ', ' .join (names [labels == i ])))
210
210
211
- ## #############################################################################
211
+ # #############################################################################
212
212
# Find a low-dimension embedding for visualization: find the best position of
213
213
# the nodes (the stocks) on a 2D plane
214
214
@@ -220,7 +220,7 @@ def quotes_historical_google(symbol, date1, date2):
220
220
221
221
embedding = node_position_model .fit_transform (X .T ).T
222
222
223
- ## #############################################################################
223
+ # #############################################################################
224
224
# Visualization
225
225
plt .figure (1 , facecolor = 'w' , figsize = (10 , 8 ))
226
226
plt .clf ()
0 commit comments