首页 > 编程语言 >Python 机器学习工具 scikit-learn 的入门使用

Python 机器学习工具 scikit-learn 的入门使用

时间:2024-02-21 14:57:25浏览次数:33  
标签:woman Python s2 clf scikit learn s1 man

参考文档:https://www.scikitlearn.com.cn/

通过对已有多组数据的训练,从而实现对单个数据的结果预测

安装

pip install -U scikit-learn

Demo

通过使用sklearn包中的决策树DecisionTreeclassifier算法实现简单预测

import sklearn
from sklearn import tree
feature=[[178,1],[155,0],[177,0],[165,0],[169,11,[160,0]] # 训练数据
label=['man','woman','man','woman','man','woman'] # 性别分类
clf=tree.DecisionTreeclassifier() # 分类决策树的分类决策方法
clf=clf.fit(feature,label) # 拟合川训练数据,得到训练模型参数
s1=c1f.predict([[158,0]]) # 对测试点[158,0]进行预测
s2=c1f.pred1ct([[176,1]]) # 对测试点[176,1]进行预测
print('s1=',s1) # 输出预测结果值
print('s2=',s2) # 输出预测结果值

标签:woman,Python,s2,clf,scikit,learn,s1,man
From: https://www.cnblogs.com/phyger/p/18025185

相关文章

  • python 播放 yuv
    mp4toyuvffmpeg-ivideo1.mp4video1.yuv使用python直接播放yuvimportcv2importnumpyasnpdefplay_yuv(file_path,width,height):yuv_file=open(file_path,'rb')frame_size=int(width*height*3/2)whileTrue:frame_......
  • Machine Learning - A Forest of Trees
    BuildaRandomForestmodel.TaskYouwillbegivenafeaturematrixXandtargetarrayy.Yourtaskistosplitthedataintotrainingandtestsets,buildaRandomForestmodelwiththetrainingset,andmakepredictionsforthetestset.Givetherandom......
  • python实战:用requests+json抓取接口
    一,安装requests1,用pip安装(venv)liuhongdi@192news%pip3installrequests2,查看所安装库的版本:(venv)liuhongdi@192news%pip3showrequestsName:requestsVersion:2.31.0Summary:PythonHTTPforHumans.Home-page:https://requests.readthedocs.ioAu......
  • Python数据结构与算法05——插入排序 shell排序
    插入排序 definsrt_sort(aimlist):n=len(aimlist)forcurinrange(1,n):i=curwhilei>0:ifaimlist[i]<aimlist[i-1]:aimlist[i],aimlist[i-1]=aimlist[i-1],aimlist[i]i-=1e......
  • 当systemd停止父python脚本时,子进程退出
    KillMode参数contorl-group(默认)#当前控制组里所有的子进程都会被杀掉process:#只杀主进程mixed:#主进程将收到SIGTERM(终止进程)信号,子进程将收到SIGKILL(无条件终止)信号none:  #没有进程会被杀掉,只是执行服务的stop命令 解决办法将KillMode改成process或non......
  • 使用python进行自动化备份和部署
    1、代码文件deploy.pyimportosfromdatetimeimportdatetimeimportshutilimportsysimportwin32serviceutilimportwin32serviceimporttimeimporttkinterastk#fromtkinterimportfiledialogimportconfigparserimportloggingimportctypes#创建......
  • python更换国内镜像
    永久更改1.在python的命令提示符中运行以下语句,该条语句将pip的下载源永久更改为某个镜像站,这里以清华大学开源镜像站为例:pipconfigsetglobal.index-urlhttps://pypi.tuna.tsinghua.edu.cn/simple/2.windows环境下,在用户目录中创建一个文件夹,该文件夹的命名为pip;在该pip......
  • Python数据结构与算法04——栈与队列
    栈的实现:classStack(object):def__init__(self):self.__list=[]defpush(self,item):self.__list.append(item)defpop(self):returnself.__list.pop()defpeek(self):ifself.__list:returnself._......
  • Python数据结构与算法05——查找与排序
    冒泡排序:defbible_sort(aimlist):n=len(aimlist)j=len(aimlist)whilej>0:foriinrange(n-1):ifaimlist[i]>aimlist[i+1]:aimlist[i],aimlist[i+1]=aimlist[i+1],aimlist[i]n-=1j-=1r......
  • linux(Ubuntu)安装python2.7和pip2
    由于数据处理需要的软件有些老代码,需要安装python2,原服务器上已有python3,本想着使用源码包进行编译安装,奈何make时总是报如下错误,搞半天也没解决 或者  继续往下makeinstall后程序也无法正常执行,于是索性使用apt方式进行安装,过程如下:首先查看当前版本Ubuntu可支持的pyt......