在Python中画图(基于Jupyternotebook的魔法函数)-创新互联-古蔺大橙子建站
RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
在Python中画图(基于Jupyternotebook的魔法函数)-创新互联

这篇文章主要介绍了在Python中画图(基于Jupyter notebook的魔法函数),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

成都创新互联公司是一家专业提供天等企业网站建设,专注与网站设计制作、成都网站制作、H5响应式网站、小程序制作等业务。10年已为天等众多企业、政府机构等服务。创新互联专业网站制作公司优惠进行中。

先展示一段相关的代码:

#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')

当前文章:在Python中画图(基于Jupyternotebook的魔法函数)-创新互联
链接地址:http://scgulin.cn/article/doiodi.html