首页 > 其他分享 >AI demo framework

AI demo framework

时间:2023-05-30 22:06:01浏览次数:35  
标签:knn plt score AI demo framework train test import

 

import pickle
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier  
from sklearn.model_selection import cross_val_score
from sklearn import metrics

iris = datasets.load_iris()  
X_train,X_test,y_train,y_test = train_test_split(iris.data, iris.target, test_size=0.3) 

k_range = range(1,31)
k_score = []
for k in k_range:
    knn = KNeighborsClassifier(n_neighbors=k)
    scores = cross_val_score(knn, X_train, y_train, cv=10, scoring='accuracy') 
    k_score.append(scores.mean())

plt.figure()
plt.plot(k_range, k_score)
plt.xlabel('Value of k for KNN')
plt.ylabel('CrossValidation accuracy')
plt.show() 

max_score = max(k_score)
print("max score:", max_score)
best_k = k_range[k_score.index(max_score)]
knn = KNeighborsClassifier(n_neighbors=best_k) 
knn.fit(X_train, y_train)
y_predict = knn.predict(X_test)  
print("test data accuracy:", metrics.accuracy_score(y_test, y_predict))
print("classification report:\n”, metrics.classification_report(y_test, y_predict))

with open("knn.pkl", "wb") as f:
    pickle.dump(knn, f)

 

标签:knn,plt,score,AI,demo,framework,train,test,import
From: https://blog.51cto.com/u_11908275/6382264

相关文章

  • Intel daal4py demo运行过程
    daal安装(记得先安装anaconda):gitclonehttps://github.com/IntelPython/daal4py.gitcddaal4pycondacreate-nDAAL4PY-cintel-cintel/label/test-cconda-forgepython=3.6mpichcnctbb-develdaaldaal-includecythonjinja2numpysourceactivateDAAL4PYexportC......
  • tflearn Training Step每次 We will run it for 10 epochs (t
    TrainingTFLearnprovidesamodelwrapper'DNN'thatcanautomaticallyperformsaneuralnetworkclassifiertasks,suchastraining,prediction,save/restore,etc...Wewillrunitfor10epochs(thenetworkwillseealldata10times)withabat......
  • 即时设计—小组项目原型示例(附AI功能)
    (官网:js.design)即时设计——可云端编辑的专业级设计工具更简单高级的功能,支持多人实时协作,颠覆传统软件的设计形态。特点简介:即时设计是中国版的Figma,适用于团队合作和远程协作。它具有强大的实时协作功能,多人可以同时编辑和评论设计文件。它还具有内置的原型设计功能,可以创......
  • go 执行ssh 报错ssh: handshake failed: read tcp xxx:->xxx:22: read: connection re
    需求:解决报错go执行ssh报错ssh:handshakefailed:readtcpxxx:->xxx:22:read:connectionresetbypeer 10个以内,没有问题。10以上就报错解决:我的远程(192.168.49.171)服务器ssh默认最大限制10解除限制,下面的操作都是在49.171上操作的。1.编辑sshd_confi......
  • install baidunetdisk-bin
    yay-Sbaidunetdisk-binAURExplicit(1):baidunetdisk-bin-4.17.7-1::(1/1)下载了PKGBUILD:baidunetdisk-bin1baidunetdisk-bin(构建文件已存在)==>清理哪些软件包的构建文件?==>[N]没有[A]全部[Ab]中止[I]已安装[No]未安装或(123,......
  • 聚焦AIGC--2023首届人工智能生成内容国际会议将于8月在上海举办
    2023年8月25-26日,首届人工智能生成内容国际会议(2023The1stInternationalConferenceonAI-generatedContent(AIGC2023))将在中国上海举行。本次会议得到了复旦大学、中国科技大学、同济大学、上海交通大学、上海人工智能实验室、香港中文大学等知名院校和研究机构的大力支......
  • 解决右键没有vscode打开选项的问题 AHAI AHAI
    问题点击鼠标右键没有‘使用vscode打开’的选项。原因在安装时没有勾选相关选项解决办法先声明亲测有效。1.新建文本文件夹2.输入以下文本WindowsRegistryEditorVersion5.00[HKEY_CLASSES_ROOT\*\shell\VSCode]@="OpenwithCode""Icon"="D:\\Mic......
  • Kali内置代理工具Proxychains的简单使用
    1.介绍Kali中内置了ProxyChains开源代理工具,通过使用这个工具,可以让我们隐藏真实ip实现攻击、代理上网等使用ProxyChains,用户可以在KaliLinux中配置不同类型的代理服务器,包括HTTP、SOCKS4和SOCKS5代理。此外,用户还可以为不同的目标指定不同的代理服务器,以确保他们的行为不被检......
  • AI入门纯干货系列课程目录
    第一课、AI导论 (已更)第二课、机器学习导论(已更)第三课、特征工程(已更)第四课、KNN最近邻算法(已更)第五课、朴素贝叶斯算法(已更)第六课、决策树/随机森林第七课、常用机器学习算法性能对比第八课、SVD分解及PCA第九课、集成学习第十课、深度学习导论第十一课、计......
  • leetcode 746. Min Cost Climbing Stairs
    Onastaircase,thei-thstephassomenon-negativecostcost[i]assigned(0indexed).Onceyoupaythecost,youcaneitherclimboneortwosteps.Youneedtofindminimumcosttoreachthetopofthefloor,andyoucaneitherstartfromthestepwithin......