第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

代碼運行后,沒有屬性'iteritems'怎么破?

代碼運行后,沒有屬性'iteritems'怎么破?

瑞RUI0206 2017-05-22 13:07:16
import?numpy?as?np? import?pylab?as?pl? from?sklearn?import?svm? from?sklearn?import?linear_model? from?sklearn?import?tree? import?pandas?as?pd? ?? ?? def?plot_results_with_hyperplane(clf,?clf_name,?df,?plt_nmbr):? ????x_min,?x_max?=?df.x.min()?-?.5,?df.x.max()?+?.5? ????y_min,?y_max?=?df.y.min()?-?.5,?df.y.max()?+?.5? ?? ????#?step?between?points.?i.e.?[0,?0.02,?0.04,?...]? ????step?=?.02? ????#?to?plot?the?boundary,?we're?going?to?create?a?matrix?of?every?possible?point? ????#?then?label?each?point?as?a?wolf?or?cow?using?our?classifier? ????xx,?yy?=?np.meshgrid(np.arange(x_min,?x_max,?step), np.arange(y_min,?y_max,?step))? ????Z?=?clf.predict(np.c_[xx.ravel(),?yy.ravel()])? ????#?this?gets?our?predictions?back?into?a?matrix? ????ZZ?=?Z.reshape(xx.shape)? ?? ????#?create?a?subplot?(we're?going?to?have?more?than?1?plot?on?a?given?image)? ????pl.subplot(2,?2,?plt_nmbr)? ????#?plot?the?boundaries? ????pl.pcolormesh(xx,?yy,?Z,?cmap=pl.cm.Paired)? ?? ????#?plot?the?wolves?and?cows? ????for?animal?in?df.animal.unique():? ????????pl.scatter(df[df.animal==animal].x,? ???????????????????df[df.animal==animal].y,? ???????????????????marker=animal,? ???????????????????label="cows"?if?animal=="x"?else?"wolves",? ???????????????????color='black',? ???????????????????c=df.animal_type,?cmap=pl.cm.Paired)? ????pl.title(clf_name)? ????pl.legend(loc="best")? ?? ?? data?=?open("cows_and_wolves.txt").read()? data?=?[row.split('\t')?for?row?in?data.strip().split('\n')]? ?? animals?=?[]? for?y,?row?in?enumerate(data):? ????for?x,?item?in?enumerate(row):? ????????#?x's?are?cows,?o's?are?wolves? ????????if?item?in?['o',?'x']:? ????????????animals.append([x,?y,?item])? ?? df?=?pd.DataFrame(animals,?columns=["x",?"y",?"animal"])? df['animal_type']?=?df.animal.apply(lambda?x:?0?if?x=="x"?else?1)? ?? #?train?using?the?x?and?y?position?coordiantes? train_cols?=?["x",?"y"]? ?? clfs?=?{? ????"SVM":?svm.SVC(),? ????"Logistic"?:?linear_model.LogisticRegression(),? ????"Decision?Tree":?tree.DecisionTreeClassifier(),? }? ?? plt_nmbr?=?1? for?clf_name,?clf?in?clfs.iteritems():? ????clf.fit(df[train_cols],?df.animal_type)? ????plot_results_with_hyperplane(clf,?clf_name,?df,?plt_nmbr)? ????plt_nmbr?+=?1? pl.show()
查看完整描述

1 回答

?
孤獨的小豬

TA貢獻232條經(jīng)驗 獲得超302個贊

你的Python版本應該是Python3,在Python3中,已經(jīng)取消了iteritems()方法,用items()方法代替,替換一下即可?;蛘吣阌胮ython2跑你的程序,應該也可以。

查看完整回答
1 反對 回復 2017-05-23
  • 1 回答
  • 0 關注
  • 2178 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號