Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #Plotting 3D graph
  2. q=0
  3. r=0
  4. s=0
  5. fig2, axes2 = plt.subplots(nrows=7, ncols=2, sharex=True)
  6.  
  7. for b in Brokers:
  8. Broker_Clusters=TimeSeriesData[TimeSeriesData.BrokerName == b][['Gross_Premium','Year','Month']]
  9.  
  10. n_cluster = range(1, 20)
  11.  
  12. kmeans = [KMeans(n_clusters=i).fit(Broker_Clusters) for i in n_cluster]
  13. scores = [kmeans[i].score(Broker_Clusters) for i in range(len(kmeans))]
  14. km = KMeans(n_clusters=broker_KMean[j])
  15. km.fit(Broker_Clusters)
  16. labels = km.labels_
  17.  
  18. s=s+1
  19.  
  20. if (q % 2) == 0:
  21. #a=df.plot(ax=axes[n,0],y=x,label="Observed")
  22. #pred_sarima.plot(ax=a,y=x,linestyle='--',label="Prediction")
  23. axes2[r,0]=Axes3D(fig2, rect=[0, 0, 0.95, 1], elev=48, azim=134)
  24. axes2[r,0].scatter(Broker_Clusters.iloc[:,0], Broker_Clusters.iloc[:,1],Broker_Clusters.iloc[:,2],c=labels.astype(np.float), edgecolor="k")
  25. axes2[r,0].set_xlabel("Gross Premium")
  26. axes2[r,0].set_ylabel("Year")
  27. axes2[r,0].set_zlabel("Month")
  28. q=q+1
  29. r = r
  30.  
  31. elif (q % 2) == 1:
  32. #a=df.plot(ax=axes[j,1],y=x,label="observed")
  33. #pred_sarima.plot(ax=a,y=x,linestyle='--',label="Prediction")
  34. axes2[r,1]=Axes3D(fig2, rect=[0, 0, 0.95, 1], elev=48, azim=134)
  35. axes2[r,1].scatter(Broker_Clusters.iloc[:,0], Broker_Clusters.iloc[:,1],Broker_Clusters.iloc[:,2],c=labels.astype(np.float), edgecolor="k")
  36. axes2[r,1].set_xlabel("Gross Premium")
  37. axes2[r,1].set_ylabel("Year")
  38. axes2[r,1].set_zlabel("Month")
  39. q=q+1
  40. r = r+1
  41. Broker_Clusters = Broker_Clusters.reset_index(drop=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement