亚洲精品久久久久久第一页-人妻少妇精彩视品一区二区三区-91国产自拍免费视频-免费一级a在线播放视频正片-少妇天天日天天射天天爽-国产大屁股喷水视频在线观看-操美女骚穴抽插性爱视频-亚洲 欧美 中文字幕 丝袜-成人免费无码片在线观看

python的實(shí)驗(yàn)報(bào)告參考文獻(xiàn) python參考文獻(xiàn)有哪些( 四 )


簡(jiǎn)單地說(shuō),成本復(fù)雜性是一個(gè)閾值 。只有當(dāng)模型的整體不純度改善了一個(gè)大于該閾值的值時(shí),該模型才會(huì)將一個(gè)節(jié)點(diǎn)進(jìn)一步拆分為其子節(jié)點(diǎn),否則將停止 。
當(dāng)CCP值較低時(shí),即使不純度減少不多,該模型也會(huì)將一個(gè)節(jié)點(diǎn)分割成子節(jié)點(diǎn) 。隨著樹的深度增加,這一點(diǎn)很明顯,也就是說(shuō),當(dāng)我們沿著決策樹往下走時(shí),我們會(huì)發(fā)現(xiàn)分割對(duì)模型整體不純度的變化沒(méi)有太大貢獻(xiàn) 。然而,更高的分割保證了類的正確分類,即準(zhǔn)確度更高 。
當(dāng)CCP值較低時(shí),會(huì)創(chuàng)建更多的節(jié)點(diǎn) 。節(jié)點(diǎn)越高,樹的深度也越高 。
下面的代碼(Scikit Learn)說(shuō)明了如何對(duì)alpha進(jìn)行調(diào)整,以獲得更高精度分?jǐn)?shù)的模型 。
path = model_gini.cost_complexity_pruning_path(X_train, y_train)ccp_alphas, impurities = path.ccp_alphas, path.impuritiesfig, ax = plt.subplots(figsize=(16,8));ax.plot(ccp_alphas[:-1], impurities[:-1], marker='o', drawstyle="steps-post");ax.set_xlabel("effective alpha");ax.set_ylabel("total impurity of leaves");ax.set_title("Total Impurity vs effective alpha for training set");讓我們了解隨著alpha的變化深度和節(jié)點(diǎn)數(shù)的變化 。
clfs = clfs[:-1]ccp_alphas = ccp_alphas[:-1]node_counts = [clf.tree_.node_count for clf in clfs]depth = [clf.tree_.max_depth for clf in clfs]fig, ax = plt.subplots(2, 1,figsize=(16,8))ax[0].plot(ccp_alphas, node_counts, marker='o', drawstyle="steps-post")ax[0].set_xlabel("alpha")ax[0].set_ylabel("number of nodes")ax[0].set_title("Number of nodes vs alpha")ax[1].plot(ccp_alphas, depth, marker='o', drawstyle="steps-post")ax[1].set_xlabel("alpha")ax[1].set_ylabel("depth of tree")ax[1].set_title("Depth vs alpha")fig.tight_layout()了解α增加時(shí)精度的變化 。
fig, ax = plt.subplots(figsize=(16,8)); #設(shè)置大小train_scores = [clf.score(X_train, y_train) for clf in clfs]test_scores = [clf.score(X_test, y_test) for clf in clfs]ax.set_xlabel("alpha")ax.set_ylabel("accuracy")ax.set_title("Accuracy vs alpha for training and testing sets")ax.plot(ccp_alphas, train_scores, marker='o', label="train",drawstyle="steps-post")ax.plot(ccp_alphas, test_scores, marker='o', label="test",drawstyle="steps-post")ax.legend()plt.show()i = np.arange(len(ccp_alphas))ccp = pd.DataFrame({'Depth': pd.Series(depth,index=i),'Node' : pd.Series(node_counts, index=i),'ccp' : pd.Series(ccp_alphas, index = i),'train_scores' : pd.Series(train_scores, index = i),'test_scores' : pd.Series(test_scores, index = i)})ccp.tail()ccp[ccp['test_scores']==ccp['test_scores'].max()]上面的代碼提供了在測(cè)試數(shù)據(jù)中產(chǎn)生最高精度的成本計(jì)算剪枝值 。


以上關(guān)于本文的內(nèi)容,僅作參考!溫馨提示:如遇健康、疾病相關(guān)的問(wèn)題,請(qǐng)您及時(shí)就醫(yī)或請(qǐng)專業(yè)人士給予相關(guān)指導(dǎo)!

「愛(ài)刨根生活網(wǎng)」www.malaban59.cn小編還為您精選了以下內(nèi)容,希望對(duì)您有所幫助: