十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
這篇文章主要介紹了在Python中畫圖(基于Jupyter notebook的魔法函數(shù)),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
先展示一段相關(guān)的代碼:
#we test the accuracy of knn and find the k which makes the biggest accuracy k_range=list(range(1,26))#[1,25] scores=[] for k in k_range: knn=KNeighborsClassifier(n_neighbors=k) knn.fit(X_train,y_train) y_pred=knn.predict(X_test) scores.append(metrics.accuracy_score(y_test,y_pred)) #------------ prepare the data we need to plot------------------- #we draw a graph to show the result import matplotlib.pyplot as plt #a magic function,which allows polts to appear whitin the notebook %matplotlib inline plt.plot(k_range,scores) plt.xlabel('Value of K for KNN') plt.ylabel('Testing Accuracy')