当前位置: 首页 > news >正文

深圳高端网站建设网页设计网站一键收录

深圳高端网站建设网页设计,网站一键收录,盘锦威旺做网站建设公司,个人网站怎么做的模板机器学习 一、机器学习 1.定义 让计算机在数据中学习规律并根据得到的规律对未来进行预测。 2.发展史 19世纪50年代:图灵测试提出、塞缪尔开发的西洋跳棋程序,标志着机器学习正式进入发展期 19世纪80年代:神经网络反向传播(…

机器学习

一、机器学习

1.定义

让计算机在数据中学习规律并根据得到的规律对未来进行预测。

2.发展史

19世纪50年代:图灵测试提出、塞缪尔开发的西洋跳棋程序,标志着机器学习正式进入发展期

19世纪80年代:神经网络反向传播(BP)算法训练的多参数线性规划(MLP),复兴时代

19世纪90年代:决策树(ID3)算法,支持向量机(SVM),由知识驱动转变为数据驱动

21世纪初:Hinton提出深度学习(Deep Learning),蓬勃发展时期

2012年:算力提升和海量训练样本的支持,深度学习成为机器学习研究热点

3.分类

按学习模式不同:

监督学习:给结果去学习模型,然后对给定的新数据利用模型去进行预测。主要用于回归和分类。

半监督学习:利用少量标注数据和大量无标注数据进行学习,侧重于在有监督的分类算法中加入无标记样本来实现半监督分类。

无监督学习:没有结果,给数据找出规律。主要用于关联分析、聚类和降维。对抗神经网络。

强化学习:类似于监督学习,但未使用样本数据进行训练,通过不断试错进行学习的模式。两个可交互对象:智能体和环境,四个核心要素:策略、回报函数(收益信号)、价值函数、环境模型(可选)。常用于机器人避障、棋牌类游戏、广告和推荐等应用场景。

4.机器学习项目开发步骤

1.收集数据

2.准备数据

3.训练模型

4.评估模型

5.提高性能

二、scikit-learn工具

1.安装

windows+r输入cmd,进入命令提示符

激活conda:conda activate

创建sklearn虚拟环境:conda create -n sklearn python=3.9

激活sklearn环境:activate sklearn

pip install --index https://pypi.mirrors.ustc.edu.cn/simple/ numpy

pip install --index https://pypi.mirrors.ustc.edu.cn/simple/ scipy

pip install --index Verifying - USTC Mirrors matplotlib

pip install --index Verifying - USTC Mirrors pandas

pip install --index Verifying - USTC Mirrors scikit-learn

参考以下安装教程:https://www.sklearncn.cn/62/

安装报错参考:pip 安装 scikit-learn失败解决教程_failed to build scikit-learn-CSDN博客

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple scikit-learn

VScode安装

环境选择-测试是否可以正常使用

2.scikit-learn包含内容

分类

回归

聚类

降低维度

模型选择

特征预处理

三、数据集

1.sklearn玩具数据集

数据在sklearn库的本地,数据量小

函数返回
load_boston(*[,return_X_y])加载并返回波士顿房价数据集(回归)
load_iris(*[,return_X_y,as_frame])加载并返回鸢尾花数据集(分类)
load_diabetes(*[,return_X_y,as_frame])加载并返回糖尿病数据集(回归)
load_digits(*[,n_class,return_X_y,as_frame])加载并返回数字数据集(分类)
load_linnerud(*[,return_X_y,as_frame])加载并返回linnerud物理锻炼数据集
load_wine(*[,return_X_y,as_frame])加载并返回葡萄酒数据集(分类)
load_breast_cancer(*[,return_X_y,as_frame])加载并返回威斯康星州乳腺癌数据集(分类)

2.sklearn现实世界数据集

通过网络获取,数据量大

函数说明
fetch_olivetti_faces(*[,data_home,...])从AT&T(分类)中加载Olivetti人脸数据集
fetch_20newsgroups(*[,data_home,subset,...])从20个新闻组数据集中加载文件名和数据(分类)
fetch_20newsgroups_vectorized(*[,subset,...])加载20个新闻组数据集并将其矢量化为令牌计数(分类)
fetch_lfw_people(*[,data_home,funneled...])将标签的面孔加载到Wild(LFW)人数据集中(分类)
fetch_lfw_pairs(*[,subset,data_home,...])在“Wild(LFW)”对数据集中加载标签的面部(分类)
fetch_covtype(*[,data_home,...])加载covertype(植被型数据集)数据集(分类)
fetch_rcv1(*[,data_home,subset,...])加载RCV1多标签数据集(分类)
fetch_kddcup99(*[,subset,data_home,...])加载kddcup99(网络入侵检测)数据集(分类)
fetch_california_housing(*[,data_home,...])加载加利福尼亚住房数据集(回归)

3.sklearn加载玩具数据集

eg1:加载鸢尾花数据
from sklearn.datasets import load_iris#加载玩具数据(鸢尾花数据集)
iris = load_iris()
print(iris.data)#数据(特征数据)
print(iris.data.shape)
print(iris.feature_names)#特征名称
print(iris.target)#标签(目标)
print(iris.target.shape)
print(iris.target_names)#目标描述
print(iris.filename) #iris.csv 保存后的文件名
print(iris.DESCR)#数据集的描述

特征有:

花萼长 sepal length

花萼宽sepal width

花瓣长 petal length

花瓣宽 petal width

三分类:

0-Setosa山鸢尾

1-Versicolour变色鸢尾

2-Virginica维吉尼亚鸢尾

用pandas把特征和目标一起显示出来:

from sklearn.datasets import load_iris
import pandas as pd
import numpy as np
def loadiris1():iris = load_iris()#加载鸢尾花数据(去本地加载了一个csv文件)# print(iris.data)#特征数据# print(iris.feature_names)# print(iris.target)# print(iris.target_names)# print(iris.DESCR)# print(iris.filename)# print("data什么类型的数据",type(iris.data),iris.data.dtype)# print("target什么类型的数据",type(iris.target),iris.target.dtype)x = iris.data# print(x.shape,x.dtype)y = iris.target.reshape(x.shape[0],1).astype(np.float64)#把一维数组转化为2维数组(待会可以和x堆叠) 再把保存的数据的类型转化为跟x一样data=np.hstack([x,y])# print(data,data.shape)# print(data[80][4])# print(iris.target_names[int(data[80][4])])# print(iris.feature_names.append("target"))iris.feature_names.append("target")dataf=pd.DataFrame(data=data,columns=iris.feature_names)print(dataf)
loadiris1()
​

4.sklearn获取现实世界数据集

1.联网下载后,保存到home目录

from sklearn import datasets
datasets.get_data_home()  #查看数据集默认存放的位置
eg2.获取20分类新闻数据

sklearn.datasets.fetch_20newsgroups(data_home,subset)

data_home:

subset:train:只下载训练集;test:只下载测试集;all:训练集和测试集

return_X_y:决定返回值的情况,False:默认

当参数return_X_y值为False时, 函数返回Bunch对象,Bunch对象中有以下属性 *data:特征数据集, 长度为18846的列表list, 每一个元素就是一篇新闻内容, 共有18846篇 *target:目标数据集,长度为18846的数组ndarray, 第一个元素是一个整数,整数值为[0,20) *target_names:目标描述,长度为20的list *filenames:长度为18846的ndarray, 元素为字符串,代表新闻的数据位置的路径 当参数return_X_y值为True时,函数返回值为元组,元组长度为2, 第一个元素值为特征数据集,第二个元素值为目标数据集

from sklearn.datasets import fetch_20newsgroups
​
data=fetch_20newsgroups(data_home="./src",subset="test")
​
print(data.data[1])
​
print(data.target_names)

5.加载本地自己的数据集

1.csv文件

①:txt,数据之间用英文逗号隔开,保存后缀名改为csv

②:excel,填写数据,以csv后缀保存文件

2.pandas加载csv
pd.read_csv("./src/ss.csv")

数据为DataFrame形式

import pandas as pd
# 作业("" "./" "../"  "/" 是什么意思 而且举例说明)
#. (点) 表示当前目录,从当前工作目录开始的相对路径
#.. (两个点) 表示上一级目录,引用位于当前目录父目录中的文件
#/路径分隔符,用于分隔目录名和文件名
data=pd.read_csv('src/ss.csv')
print(data)
import pandas as pd
data=pd.read_excel("src/ss.xlsx")
print(data)

6.数据集的划分

1.函数

sklearn.model_selection.train_test_split(*arrays,**options)

*array :用于接收1到多个"列表、numpy数组、稀疏矩阵或padas中的DataFrame"。

**options, 重要的关键字参数有: test_size 值为0.0到1.0的小数,表示划分后测试集占的比例 random_state 值为任意整数,表示随机种子,使用相同的随机种子对相同的数据集多次划分结果是相同的。否则多半不同 shuffle:布尔值。默认为True,在分割之前是否对数据进行洗牌 stratify:分层划分,默认是y,按照 y 中类别的比例进行分层抽样,确保训练集和测试集中各类别样本的比例相同。 返回值说明:返回值为列表list, 列表长度与形参array接收到的参数数量相关联, 形参array接收到的是什么类型,list中对应被划分出来的两部分就是什么类型

2.示例

复习:

arr2=[100,200]
x,y=arr2
print(x,y)
def m(*a, **b):print(a)       #('hello', 123)print(b)       #{'name': '小王', 'age': 30, 'sex': '男'}   m("hello", 123,  name="小王", age=30, sex="男")
​
def m2(a,b,c):pass
dic={"a":123,"b":12,"c":123}   
print(dic) #{'a': 123, 'b': 12, 'c': 123}
#m2(**dic)相当于m2(a=dic["a"],b=dic["b"],c=dic["c"])
①.列表数据集划分
from sklearn.model_selection import train_test_split
data1 = [1,    2,    3,    4,    5]
data2 = ["1a", "2a","3a", "4a",  "5a"]
a, b = train_test_split(data1, test_size=0.4, random_state=22)
print(a, b) #[4, 1, 5]  [2, 3]
​
a, b = train_test_split(data2, test_size=0.4, random_state=22)
print(a, b) #['4a', '1a', '5a'] ['2a', '3a']
​
a, b, c, d  = train_test_split(data1, data2,  test_size=0.4, random_state=22)
print(a,b,c,d) #['4a', '1a', '5a'] ['2a', '3a']
②.ndarray数据集划分

划分前和划分后的数据类型是相同的

from sklearn.model_selection import train_test_split
import numpy as np
data1 = [1,    2,    3,    4,    5]
data2 = np.array(["1a", "2a","3a", "4a",  "5a"]) 
a, b, c, d  = train_test_split(data1, data2,  test_size=0.4, random_state=22)
print(a, b, c, d)  #[4, 1, 5] [2, 3] ['4a' '1a' '5a'] ['2a' '3a']
print(type(a), type(b), type(c), type(d)) #<class 'list'> <class 'list'> <class 'numpy.ndarray'> <class 'numpy.ndarray'>
# ndarray的数据集划分
from sklearn.model_selection import train_test_split
import numpy as np
x=np.arange(100).reshape(50,2)
# print(x)#这个x数据集中有几个数据(50个) 每一个数据有2个特征
x_train,x_test=train_test_split(x,test_size=11,random_state=42)
print(x_train.shape)
print(x_test.shape)
​
print(type(x_train))
print(type(x_test))

③.二维数组数据集划分

train_test_split只划分第一维度,第二维度保持不变

from sklearn.model_selection import train_test_split
import numpy as np
data1 = np.arange(1, 16, 1)
data1.shape=(5,3)
print(data1)
a, b = train_test_split(data1,  test_size=0.4, random_state=22)
print("a=\n", a)
print("b=\n", b)
[[ 1  2  3][ 4  5  6][ 7  8  9][10 11 12][13 14 15]]
a=[[10 11 12][ 1  2  3][13 14 15]]
b=[[4 5 6][7 8 9]]

eg3
from sklearn.model_selection import train_test_split
arr1=[1,23,2,231,25,36,23,32,22,34,123,12,3,2,3]
x_train,x_test=train_test_split(arr1,train_size=0.8)
print(arr1)
print(x_train,x_test)
#[1, 23, 2, 231, 25, 36, 23, 32, 22, 34, 123, 12, 3, 2, 3]
[34, 2, 123, 12, 3, 1, 2, 231, 32, 36, 22, 23] [23, 25, 3]
from sklearn.model_selection import train_test_split
arr1=[1111,23,2,231,25,36,23,32,22,34,123,12,3,33333,3]
arr2=[9999,1,1,1,1,1,2,2,2,2,3,3,3,66666,3]
x_train,x_test,y_train,y_test=train_test_split(arr1,arr2,train_size=0.8)#arrays
print(arr1)
print(x_train,x_test)
print(y_train,y_test)
#[1111, 23, 2, 231, 25, 36, 23, 32, 22, 34, 123, 12, 3, 33333, 3]
#[9999, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 66666, 3]
#[34, 3, 1111, 22, 33333, 25, 123, 32, 23, 12, 2, 3] [36, 23, 231]
#[2, 3, 9999, 2, 66666, 1, 3, 2, 2, 3, 1, 3] [1, 1, 1]
#将arr1和对应的arr2打乱,再划分成训练集和测试集
from sklearn.model_selection import train_test_split
x=[[11,2,3,31,111],[12,2,3,32,112],[1,23,3,33,113],[14,2,3,34,114],[15,2,3,35,115],[16,2,3,36,116],[1,23,3,36,117],[1,23,3,316,118],[1,23,3,326,119],[1,23,3,336,120]]
y=[1,1,1,1,1,2,2,2,2,2]
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.3,stratify=y,random_state=40)#stratify=y,按y进行分层
print("x_train:\n",x_train)
print("x_test:\n",x_test)
print("y_train:\n",y_train)
print("y_test:\n",y_test)
print(type(x_test))
④.DataFrame数据集划分
# dataFrame的数据集划分
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
# 数据集的划分
data=np.arange(1,100).reshape(33,3)
data=pd.DataFrame(data,columns=['a','b','c'])
# print(data)
train,test=train_test_split(data,train_size=0.7,shuffle=True,random_state=4)
print(train.shape)  
print(test.shape)   
⑤.字典数据集划分

可以划分非稀疏矩阵

用于将字典列表转换为特征向量。这个转换器主要用于处理类别数据和数值数据的混合型数据集

# 字典的特征提取和数据划分
from sklearn.feature_extraction import DictVectorizer
from  sklearn.model_selection import train_test_split
arr=[{"name":"重庆","count":2000,"tempreture":41},{"name":"成都","count":2300,"tempreture":28},{"name":"北京","count":4900,"tempreture":20},{"name":"昆明","count":190,"tempreture":22},{"name":"昆明","count":290,"tempreture":22}]
model=DictVectorizer(sparse=False)#sparse=False表示返回一个完整的矩阵,sparse=True表示返回一个稀疏矩阵
data=model.fit_transform(arr)#提取特征
print(data)
x_train,y_train=train_test_split(data,train_size=0.8,random_state=666)
print(x_train)
print(y_train)
⑥.鸢尾花数据集划分
# 鸢尾花数据集划分
from sklearn import datasets
from sklearn.model_selection import train_test_split
iris=datasets.load_iris()
X=iris.data
y=iris.target
X_train,X_test,y_train,y_test=train_test_split(X,y,train_size=0.8,random_state=4,stratify=y)
print(X)
print(y)
print(X_train.shape)
print(X_test.shape)
print(y_train.shape)
print(y_test.shape)
print(y_train)
print(iris.feature_names)
print(iris.target_names)

⑦.现实世界数据集划分
from sklearn.datasets import  fetch_20newsgroups
from sklearn.model_selection import train_test_split
import numpy as np
news=fetch_20newsgroups(data_home="./src",subset="train")
# print(news.data[0])
x_train,x_test,y_train,y_test=train_test_split(news.data,news.target,train_size=0.8,random_state=666)
print(np.array(x_train).shape)
print(np.array(x_test).shape)
print(x_train[0:5])
print(y_train)
print(news.target_names)

文章转载自:
http://dinncoratt.stkw.cn
http://dinncoeducatory.stkw.cn
http://dinncoknub.stkw.cn
http://dinncoautoantibody.stkw.cn
http://dinncopyroninophilic.stkw.cn
http://dinncoagreeable.stkw.cn
http://dinncoeburnean.stkw.cn
http://dinncowintry.stkw.cn
http://dinncohemiptera.stkw.cn
http://dinncocardioactive.stkw.cn
http://dinncoperipheric.stkw.cn
http://dinncoclaudication.stkw.cn
http://dinncomeeting.stkw.cn
http://dinncovolitive.stkw.cn
http://dinnconum.stkw.cn
http://dinncogrinder.stkw.cn
http://dinncosingaradja.stkw.cn
http://dinncosthenic.stkw.cn
http://dinncolifeward.stkw.cn
http://dinncopulseless.stkw.cn
http://dinncoshapable.stkw.cn
http://dinncodekaliter.stkw.cn
http://dinncotoluate.stkw.cn
http://dinncochlamydate.stkw.cn
http://dinncomidship.stkw.cn
http://dinncobaronetcy.stkw.cn
http://dinncofrontiersman.stkw.cn
http://dinncomural.stkw.cn
http://dinncoheliotropic.stkw.cn
http://dinncobaume.stkw.cn
http://dinncoodille.stkw.cn
http://dinncoexpound.stkw.cn
http://dinnconouadhibou.stkw.cn
http://dinncointelligentsia.stkw.cn
http://dinncoanteriorly.stkw.cn
http://dinncopiezometer.stkw.cn
http://dinncounisexual.stkw.cn
http://dinncoegoistically.stkw.cn
http://dinncosuperheat.stkw.cn
http://dinncowall.stkw.cn
http://dinncoberat.stkw.cn
http://dinncorebreathe.stkw.cn
http://dinncostoniness.stkw.cn
http://dinncopalship.stkw.cn
http://dinncologger.stkw.cn
http://dinncomoulin.stkw.cn
http://dinncogeegee.stkw.cn
http://dinncosquanderer.stkw.cn
http://dinncoquizzy.stkw.cn
http://dinncocumulation.stkw.cn
http://dinnconakedly.stkw.cn
http://dinncobout.stkw.cn
http://dinnconoonday.stkw.cn
http://dinncomousie.stkw.cn
http://dinncomonterrey.stkw.cn
http://dinncoscend.stkw.cn
http://dinncoimho.stkw.cn
http://dinncochoragus.stkw.cn
http://dinncoapyrous.stkw.cn
http://dinncounshaken.stkw.cn
http://dinncohebridean.stkw.cn
http://dinncopenurious.stkw.cn
http://dinncoimmanuel.stkw.cn
http://dinnconipponian.stkw.cn
http://dinncostinkstone.stkw.cn
http://dinncotrample.stkw.cn
http://dinncocataplastic.stkw.cn
http://dinncotux.stkw.cn
http://dinncopumpman.stkw.cn
http://dinncorectal.stkw.cn
http://dinncoentoretina.stkw.cn
http://dinncohaptic.stkw.cn
http://dinncohymenopterous.stkw.cn
http://dinncoplagioclimax.stkw.cn
http://dinncoexfoliation.stkw.cn
http://dinncowadna.stkw.cn
http://dinncolabor.stkw.cn
http://dinncoisomer.stkw.cn
http://dinncofirmament.stkw.cn
http://dinncobroccoli.stkw.cn
http://dinncoluftmensch.stkw.cn
http://dinncosoerakarta.stkw.cn
http://dinncoaqualung.stkw.cn
http://dinncotrijugous.stkw.cn
http://dinncoperpetration.stkw.cn
http://dinncobeedie.stkw.cn
http://dinncodictograph.stkw.cn
http://dinncoinformercial.stkw.cn
http://dinncoblockhead.stkw.cn
http://dinncohomonid.stkw.cn
http://dinncotherapeutics.stkw.cn
http://dinncoclonesome.stkw.cn
http://dinncoendocardium.stkw.cn
http://dinncounclothe.stkw.cn
http://dinncopantechnicon.stkw.cn
http://dinncosaza.stkw.cn
http://dinncoautogamous.stkw.cn
http://dinncocounterweight.stkw.cn
http://dinncocharisma.stkw.cn
http://dinncolinguister.stkw.cn
http://www.dinnco.com/news/110425.html

相关文章:

  • 做网站兼容性怎么设置网站排名查询软件
  • 国内网站建设联系电话百度主页
  • 做百度企业网站电脑培训班一般要学多久
  • 一级做a爱免费网站宁波关键词网站排名
  • 便捷的邢台做网站软件开发培训
  • 家居网站建设定位分析论文搜索引擎入口yandex
  • 网站真实性核验单游戏推广员是做什么的
  • wordpress 改域名台州百度推广优化
  • 做赌博彩票网站吗站长工具seo综合查询访问
  • 我要下载中国建设网站西安seo代理计费
  • 孝感 网站建设哈尔滨网站建设
  • 南通市通州建设局网站网站模板定制
  • 美橙网站建设怎么做微信营销是什么
  • 网站建设小技巧网站推广及seo方案
  • 奢侈品 网站建设方案关键词优化的作用
  • 宁波在线网外贸网站seo推广教程
  • 独立网站商城阿里云万网域名购买
  • 做网站的时候卖过假货而出过事自己怎么做网址
  • 网站初期推广百度知道合伙人答题兼职入口
  • 新疆建设工程培训网新乡seo公司
  • 必须在当地网站备案舆情通
  • 影楼网站怎么做网站推广是什么意思
  • 吉林省网站建设公司天津百度爱采购
  • 网站不支持php百度开户代理公司
  • 网页制作和网页制作设计做seo是什么意思
  • 网站维护的主要工作网站制作公司怎么找
  • 云主机 做网站深圳网站建设推广
  • 上海网站模板苏州seo门户网
  • 专业网站建设特点分析什么是白帽seo
  • 求做政府采购网站微信营销平台