Split train and test
from sklearn.cross_validation import train_test_split x_train, x_test, y_train, y_test = train_test_split(customer.ix[:,0:customer.columns.size-1], customer.ix[:,customer.columns.size-1], test_size = 0.2) x_train, x_test, y_train, y_test = train_test_split(order.ix[:,0:order.columns.size-1], order.ix[:,order.columns.size-1], test_size = 0.2)Decision tree
使用信息熵作為劃分標(biāo)準(zhǔn),對(duì)決策樹進(jìn)行訓(xùn)練
from sklearn import tree clf = tree.DecisionTreeClassifier(criterion="entropy") print(clf) clf.fit(x_train, y_train)Predict
answer = pd.Series(clf.predict(x_test)) result = pd.DataFrame(np.c_[y_test, answer]) result["correct"] = np.where(result[0] == result[1], 1, 0) sum(result["correct"])/pd.count(result["correct"]) result.sum()/result.count() preds = clf.predict(x_test) result = pd.crosstab(y_test, preds, rownames=["actual"], colnames=["preds"]) res = result.div(result.sum(1).astype(float), axis=0) res res2 = res.drop(max(res) < 0.5, axis=1) res.to_csv("result.csv", index = True, header = True)
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://hztianpu.com/yun/44570.html
摘要:近日,針對(duì)泛化能力強(qiáng)大的深度神經(jīng)網(wǎng)絡(luò)無(wú)法解釋其具體決策的問(wèn)題,深度學(xué)習(xí)殿堂級(jí)人物等人發(fā)表論文提出軟決策樹。即使沒(méi)有使用無(wú)標(biāo)簽數(shù)據(jù),仍然有可能通過(guò)使用一種稱為蒸餾法,的技術(shù)和一種執(zhí)行軟決策的決策樹,將神經(jīng)網(wǎng)絡(luò)的泛化能力遷移到?jīng)Q策樹上。 近日,針對(duì)泛化能力強(qiáng)大的深度神經(jīng)網(wǎng)絡(luò)(DNN)無(wú)法解釋其具體決策的問(wèn)題,深度學(xué)習(xí)殿堂級(jí)人物 Geoffrey Hinton 等人發(fā)表 arXiv 論文提出「軟決...
當(dāng)涉及到機(jī)器學(xué)習(xí)和數(shù)據(jù)科學(xué)時(shí),決策樹是一種廣泛使用的算法。TensorFlow是一種流行的機(jī)器學(xué)習(xí)框架,它可以用于訓(xùn)練和部署決策樹模型。在本文中,我們將探討如何使用TensorFlow實(shí)現(xiàn)決策樹算法。 首先,讓我們了解一下決策樹算法的工作原理。決策樹是一種基于樹形結(jié)構(gòu)的分類算法,它將數(shù)據(jù)集分成不同的類別或標(biāo)簽。決策樹的每個(gè)節(jié)點(diǎn)表示一個(gè)特征,每個(gè)分支表示該特征的一個(gè)可能取值,而每個(gè)葉節(jié)點(diǎn)表示一個(gè)類...
閱讀 656·2023-04-25 21:29
閱讀 1216·2023-04-25 21:27
閱讀 1178·2021-11-25 09:43
閱讀 1190·2021-09-29 09:43
閱讀 3724·2021-09-03 10:30
閱讀 2943·2019-08-29 15:26
閱讀 2970·2019-08-29 12:52
閱讀 1841·2019-08-29 11:10