Machine-Learning-for-Asset-Managers icon indicating copy to clipboard operation
Machine-Learning-for-Asset-Managers copied to clipboard

AttributeError: 'NoneType' object has no attribute 'labels_'

Open adriana2903 opened this issue 4 years ago • 1 comments

When I run the script called 'ch7_portfolio_construction' I get the following error:

AttributeError Traceback (most recent call last) in 39 cov1 = pd.DataFrame(cov1, index=cols, columns=cols) 40 corr1 = mp.cov2corr(cov1) ---> 41 corr1, clstrs, silh = oc.clusterKMeansBase(pd.DataFrame(corr0)) 42 43 # # code snippet 7.4 - intracluster optimal allocations

D:\User\Desktop\ch4_optimal_clustering.py in clusterKMeansBase(corr0, maxNumClusters, n_init, debug) 56 print("********") 57 ---> 58 newIdx = np.argsort(kmeans.labels_) 59 #print(newIdx) 60

AttributeError: 'NoneType' object has no attribute 'labels_'

Can you please help me to fix this bug? Thank you!

adriana2903 avatar May 04 '21 08:05 adriana2903

This is because min number of clusters was set to 4 in ch4_optimal_clustering.py in clusterKMeansBase, but it should be 2. I have updated this in this commit: https://github.com/emoen/Machine-Learning-for-Asset-Managers/commit/5acb8a56799439db2f026c18fa5cad1aed6be7d2

emoen avatar Jul 26 '21 20:07 emoen