国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

聚類分析——Kmeans

Scholer / 1807人閱讀

摘要:導(dǎo)入數(shù)據(jù)預(yù)處理計算值從到對應(yīng)的平均畸變程度用求解距離平均畸變程度用肘部法則來確定最佳的值建模

導(dǎo)入數(shù)據(jù)
cus_general = customer[["wm_poi_id","city_type","pre_book","aor_type","is_selfpick_poi","is_selfpick_trade_poi"]]
cus_ord = customer[["wm_poi_id","month_original_price","month_order_cnt","service_fee_30day","abnor_rate_30day"]]
cus = customer[["wm_poi_id","comment_1star","comment_5star","pic_comment_cnt"]]
cus = customer[["wm_poi_id","waybill_received_ratio","waybill_delivered_ratio","waybill_ontime_ratio","waybill_normal_arrived_delivery_total_interval_avg","waybill_normal_poi_push_interval_avg","waybill_normal_receive_interval_avg","waybill_normal_fetch_interval_avg","waybill_normal_delivery_interval_avg","waybill_delivery_ontime_ratio","loss_amt"]]
cus_all = customer[["wm_poi_id","c5","ol_time","primary_first_tag_id","city_level",
                    "month_original_price","month_order_cnt","service_fee_30day","abnor_cnt_30day",
                    "comment_1star","comment_5star","pic_comment_cnt",
                    "area_30day","waybill_grab_5mins_ratio","waybill_delivered_ratio","waybill_normal_arrived_delivery_total_interval_avg","waybill_normal_receive_interval_avg",
                    "call.call_cnt","call.call_cnt_ord","call.call_cnt_poi","call.call_cnt_oth"]]
預(yù)處理
from sklearn import preprocessing
cus = pd.DataFrame(preprocessing.scale(cus_general.iloc[:,1:6]))
cus = pd.DataFrame(preprocessing.scale(cus_ord.iloc[:,1:5]))
cus = pd.DataFrame(preprocessing.scale(cus_all.iloc[:,1:21]))
cus.columns = ["city_type","pre_book","aor_type","is_selfpick_poi","is_selfpick_trade_poi"]
cus.columns = ["month_original_price","month_order_cnt","service_fee_30day","abnor_rate_30day"]
cus.columns = ["comment_1star","comment_5star","pic_comment_cnt"]
cus.columns = ["waybill_push_ratio","waybill_delivered_ratio","waybill_ontime_ratio","waybill_normal_arrived_delivery_total_interval_avg","waybill_normal_poi_push_interval_avg","waybill_normal_receive_interval_avg","waybill_normal_fetch_interval_avg","waybill_normal_delivery_interval_avg","waybill_delivery_ontime_ratio","loss_amt"]
cus.columns = ["c5","ol_time","primary_first_tag_id","city_level",
               "month_original_price","month_order_cnt","service_fee_30day","abnor_cnt_30day",
               "comment_1star","comment_5star","pic_comment_cnt",
               "area_30day","waybill_grab_5mins_ratio","waybill_delivered_ratio","waybill_normal_arrived_delivery_total_interval_avg","waybill_normal_receive_interval_avg",
               "call.call_cnt","call.call_cnt_ord","call.call_cnt_poi","call.call_cnt_oth"]
計算K值從1到10對應(yīng)的平均畸變程度:用scipy求解距離
from sklearn.cluster import KMeans
from scipy.spatial.distance import cdist
K=range(1,15)
meandistortions=[]
for k in K:
    kmeans=KMeans(n_clusters=k)
    kmeans.fit(cus)
    meandistortions.append(sum(np.min(cdist(cus,kmeans.cluster_centers_,"euclidean"),axis=1)))
plt.plot(K,meandistortions,"bx-")
plt.xlabel("k")
plt.ylabel(u"平均畸變程度")
plt.title(u"用肘部法則來確定最佳的K值")
Kmean建模
from sklearn.cluster import KMeans
clf = KMeans(n_clusters=12)
clf.fit(cus)
pd.Series(pd.Series(clf.labels_).value_counts())

centres = pd.DataFrame(clf.cluster_centers_)
centres.columns = cus_all.iloc[:,1:21].columns
centres.plot(kind="bar", subplots=True, figsize=(6,15))
clf.inertia_

cus_general = pd.concat([cus_general, pd.DataFrame(clf.fit_predict(cus))], axis=0)
cus_general = cus_general.rename(columns={0:"general"})
cus_ord = pd.concat([cus_ord, pd.DataFrame(clf.fit_predict(cus))], axis=0)
cus_ord = cus_ord.rename(columns={0:"order"})
cus_all = pd.concat([cus_all, pd.DataFrame(clf.fit_predict(cus))], axis=0)
cus_all = cus_all.rename(columns={0:"cluster"})

centres = cus_all.groupby(["cluster"]).mean()

cus_all.to_csv("cluster.csv")

result = cus_all[cus_all["cluster"]==2]

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://specialneedsforspecialkids.com/yun/44576.html

相關(guān)文章

  • 用戶地理位置的聚類算法實現(xiàn)—基于DBSCAN和Kmeans的混合算法

    摘要:聚類算法簡介聚類的目標(biāo)是使同一類對象的相似度盡可能地大不同類對象之間的相似度盡可能地小。用戶地理位置信息的的聚類實現(xiàn)本實驗用實現(xiàn),依賴等科學(xué)計算。 1. 聚類算法簡介 聚類的目標(biāo)是使同一類對象的相似度盡可能地大;不同類對象之間的相似度盡可能地小。目前聚類的方法很多,根據(jù)基本思想的不同,大致可以將聚類算法分為五大類:層次聚類算法、分割聚類算法、基于約束的聚類算法、機器學(xué)習(xí)中的聚類算法和用...

    garfileo 評論0 收藏0
  • Python使用Numpy實現(xiàn)Kmeans算法

    摘要:如何確定最佳的值類別數(shù)本文選取手肘法手肘法對于每一個值,計算它的誤差平方和其中是點的個數(shù),是第個點,是對應(yīng)的中心。隨著聚類數(shù)的增大,樣本劃分會更加精細,每個簇的聚合程度會逐漸提高,那么誤差平方和自然會逐漸變小。 目錄 Kmeans聚類算法介紹: 1.聚類概念: 2.Kmeans算法: 定義...

    hankkin 評論0 收藏0
  • opencv python K-Means聚類

    摘要:指定最大迭代次數(shù)的整數(shù)要求的準確性重復(fù)試驗算法次數(shù),將會返回最好的一次結(jié)果該標(biāo)志用于指定初始中心的采用方式。第一列對應(yīng)于所有個人的高度,第二列對應(yīng)于它們的權(quán)重。類似地,剩余的行對應(yīng)于其他人的高度和重量。 K-Means Clustering in OpenCV cv2.kmeans(data, K, bestLabels, criteria, attempts, flags[, cen...

    superPershing 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<