国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁(yè) > news >正文

營(yíng)銷網(wǎng)站制作哪家有名晉城seo

營(yíng)銷網(wǎng)站制作哪家有名,晉城seo,聊城網(wǎng)站建設(shè)工作室,阜寧網(wǎng)站建設(shè)找哪家好文章目錄 機(jī)器學(xué)習(xí)基礎(chǔ)機(jī)器學(xué)習(xí)的關(guān)鍵術(shù)語(yǔ) k-近鄰算法(KNN)準(zhǔn)備:使用python導(dǎo)入數(shù)據(jù)實(shí)施kNN分類算法示例:使用kNN改進(jìn)約會(huì)網(wǎng)站的配對(duì)效果準(zhǔn)備數(shù)據(jù):從文本文件中解析數(shù)據(jù)分析數(shù)據(jù)準(zhǔn)備數(shù)據(jù):歸一化數(shù)值測(cè)試算法…

文章目錄

  • 機(jī)器學(xué)習(xí)基礎(chǔ)
    • 機(jī)器學(xué)習(xí)的關(guān)鍵術(shù)語(yǔ)
  • k-近鄰算法(KNN)
    • 準(zhǔn)備:使用python導(dǎo)入數(shù)據(jù)
    • 實(shí)施kNN分類算法
    • 示例:使用kNN改進(jìn)約會(huì)網(wǎng)站的配對(duì)效果
      • 準(zhǔn)備數(shù)據(jù):從文本文件中解析數(shù)據(jù)
      • 分析數(shù)據(jù)
      • 準(zhǔn)備數(shù)據(jù):歸一化數(shù)值
      • 測(cè)試算法:作為完整程序驗(yàn)證分類器
    • 手寫識(shí)別系統(tǒng)

機(jī)器學(xué)習(xí)基礎(chǔ)

機(jī)器學(xué)習(xí)的關(guān)鍵術(shù)語(yǔ)

1、屬性:將一種事務(wù)分類的特征值稱為屬性,例如我們?cè)谧鲽B類分類時(shí),我們可以將體重、翼展、腳蹼、后背顏色作為特征,特征通常時(shí)訓(xùn)練樣本的列,它們是獨(dú)立測(cè)量得到的結(jié)果,多個(gè)特征聯(lián)系在一起共同組成一個(gè)訓(xùn)練樣本
2、目標(biāo)變量:就是我們要分類的那個(gè)結(jié)果
3、訓(xùn)練集和測(cè)試集:訓(xùn)練集作為算法的輸入,用于訓(xùn)練模型,測(cè)試集用于檢驗(yàn)訓(xùn)練的效果

k-近鄰算法(KNN)

主要思想:我們先將已知標(biāo)簽的數(shù)據(jù)以及對(duì)應(yīng)的標(biāo)簽輸入,當(dāng)輸入未知標(biāo)簽的數(shù)據(jù)時(shí),我們希望根據(jù)輸入的特征值來(lái)判斷該數(shù)據(jù)的特征值,我們先計(jì)算該數(shù)據(jù)與我們已知標(biāo)簽的數(shù)據(jù)的距離,并將距離排序,取前k個(gè)數(shù)據(jù),根據(jù)前k個(gè)數(shù)據(jù)中出現(xiàn)次數(shù)最多的數(shù)據(jù)的標(biāo)簽作為新數(shù)據(jù)標(biāo)簽的分類

kNN算法主要是用于分類的一種算法

屏幕截圖 2023-08-04 174500.png

準(zhǔn)備:使用python導(dǎo)入數(shù)據(jù)

from numpy import *
# kNN排序時(shí)將使用這個(gè)模塊提供好的函數(shù)
import operatordef createDataSet():group = array([[1.0, 1.1], [1.0, 1.0], [0, 0], [0, 0.1]])labels = ['A', 'A', 'B', 'B']return group, labels

實(shí)施kNN分類算法

1.png

def classify0(inX, dataSet, labels, k):dataSetSize = dataSet.shape[0]diffMat = tile(inX, (dataSetSize, 1) - dataSet)sqDiffMat = diffMat ** 2sqDistances = sqDiffMat.sum(axis = 1)distances = sqDistances ** 0.5sortedDistIndicies = distances.argsort()classCount = {}for i in range(k):voteIlabel = labels[sortedDistIndicies[i]]classCount[voteIlabel] = classCount.get(voteIlabel, 0) + 1sortedClassCount = sorted(classCount.items(),key = operator.itemgetter(1), reverse= True)return sortedClassCount[0][0]

這里先說(shuō)一下shape函數(shù),只做簡(jiǎn)單說(shuō)明,shape函數(shù)用于確定array的維度比如

group = array([[1.0, 1.1], [1.0, 1.0], [0, 0], [0, 0.1]])
print(group.shape)

這里輸出的結(jié)果是(4,2)

也就是說(shuō)返回的是矩陣或者數(shù)組每一維的長(zhǎng)度,返回的結(jié)果是一個(gè)元組(tuple),元組和例表的區(qū)別不能忘記,元組不可修改,列表可以修改

tile()函數(shù),tile是numpy模塊中的一個(gè)函數(shù),用于矩陣的復(fù)制,tile(A, reps), A表示我們要操作的矩陣,reps是我們復(fù)制的參數(shù),可以是一個(gè)數(shù)也可以是一個(gè)矩陣(4, 2),tile(A, (4, 2))表示將A矩陣的列復(fù)制4次,行復(fù)制兩次

argsort()方法,對(duì)數(shù)組進(jìn)行排序,這里返回的是排序后的下標(biāo)這和C++中的sort()方法不同

argsort()實(shí)現(xiàn)倒序排序

group = array([2, 3, 5, 4])
x = argsort(-group)
print(x)

字典中的get()方法

python中對(duì)于非數(shù)值型數(shù)據(jù)進(jìn)行排序,例如字典

sorted(iterable, cmp=None, key=None, reverse=False)

iterable是一個(gè)迭代器,
cmp是比較的函數(shù),這個(gè)具有兩個(gè)參數(shù),參數(shù)的值都是從可迭代對(duì)象中取出,此函數(shù)必須遵守的規(guī)則為,大于則返回1,小于則返回-1,等于則返回0。
key – 主要是用來(lái)進(jìn)行比較的元素,只有一個(gè)參數(shù),具體的函數(shù)的參數(shù)就是取自于可迭代對(duì)象中,指定可迭代對(duì)象中的一個(gè)元素來(lái)進(jìn)行排序。
reverse – 排序規(guī)則,reverse = True 降序 , reverse = False 升序(默認(rèn))。

 sortedClassCount = sorted(classCount.iteritems(),key = operator.itemgetter(1), reverse= True)

python中的items()返回的是一個(gè)列表,iteritems()返回一個(gè)迭代器, itemgetter()方法可用于指定關(guān)鍵字排序,operator.itemgetter(1)是按字典中的值進(jìn)行排序,reverse= True按降序排序,python3已經(jīng)不支持iteritems(),這里用items()即可。

字典中的get()方法

dict_name.get(key, default = None)

key是我們要查找字典中的key,如果存在則返回對(duì)應(yīng)的值,如果不存在就返回第二個(gè)我們?cè)O(shè)置的參數(shù),當(dāng)我們沒設(shè)置時(shí),默認(rèn)返回None

示例:使用kNN改進(jìn)約會(huì)網(wǎng)站的配對(duì)效果

2.png

準(zhǔn)備數(shù)據(jù):從文本文件中解析數(shù)據(jù)

from numpy import *def file2matrix(filename):fr = open(filename)arrarOLines = fr.readlines()numberOfLines = len(arrarOLines)returnMat = zeros((numberOfLines, 3))classLabelVector = []index = 0for line in arrarOLines:line = line.strip()listFromLine = line.split('\t')# 將數(shù)據(jù)的前三行直接存入特征矩陣returnMat[index,:] = listFromLine[0:3]# 將字符串映射成數(shù)字if listFromLine[-1] == 'didntLike':classLabelVector.append(1)elif listFromLine[-1] == 'smallDoses':classLabelVector.append(2)elif listFromLine[-1] == 'largeDoses':classLabelVector.append(3)index += 1return returnMat, classLabelVector

分析數(shù)據(jù)

from numpy import *
# kNN排序時(shí)將使用這個(gè)模塊提供好的函數(shù)
import operator
import matplotlib
import matplotlib.pyplot as pltdef createDataSet():group = array([[1.0, 1.1], [1.0, 1.0], [0, 0], [0, 0.1]])labels = ['A', 'A', 'B', 'B']return group, labelsdef classify0(inX, dataSet, labels, k):dataSetSize = dataSet.shape[0]diffMat = tile(inX, (dataSetSize, 1)) - dataSetsqDiffMat = diffMat ** 2sqDistances = sqDiffMat.sum(axis = 1)distances = sqDistances ** 0.5sortedDistIndicies = distances.argsort()classCount = {}for i in range(k):voteIlabel = labels[sortedDistIndicies[i]]classCount[voteIlabel] = classCount.get(voteIlabel, 0) + 1sortedClassCount = sorted(classCount.items(),key = operator.itemgetter(1), reverse= True)return sortedClassCount[0][0]# [group, labels] = createDataSet()
# m = classify0([0, 0], group, labels, 2)
# print(m)def file2matrix(filename):fr = open(filename)arrarOLines = fr.readlines()numberOfLines = len(arrarOLines)returnMat = zeros((numberOfLines, 3))classLabelVector = []index = 0for line in arrarOLines:line = line.strip()listFromLine = line.split('\t')# 將數(shù)據(jù)的前三行直接存入特征矩陣returnMat[index,:] = listFromLine[0:3]# 將字符串映射成數(shù)字if listFromLine[-1] == 'didntLike':classLabelVector.append(1)elif listFromLine[-1] == 'smallDoses':classLabelVector.append(2)elif listFromLine[-1] == 'largeDoses':classLabelVector.append(3)index += 1return returnMat, classLabelVectordatingDataMat, datingLabels = file2matrix('C:/Users/cxy/OneDrive/桌面/datingTestSet.txt')fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(datingDataMat[:, 1], datingDataMat[:, 2], 15.0*array(datingLabels), 15.0*array(datingLabels))
plt.show()

結(jié)果截圖:
3.png

add_subplot(x)中參數(shù)的含義:
這里前兩個(gè)表示幾*幾的網(wǎng)格,最后一個(gè)表示第幾子圖
可能說(shuō)的有點(diǎn)繞口,下面上程序作圖一看說(shuō)明就明白

import matplotlib.pyplot as plt
fig = plt.figure(figsize = (5,5)) 
ax = fig.add_subplot(221)
ax = fig.add_subplot(222)
ax = fig.add_subplot(223)
ax = fig.add_subplot(224)

4.png

scatter()方法
matplotlib.pyplot.scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, *, edgecolors=None, plotnonfinite=False, data=None, **kwargs)
x,y:長(zhǎng)度相同的數(shù)組,也就是我們即將繪制散點(diǎn)圖的數(shù)據(jù)點(diǎn),輸入數(shù)據(jù)。
s:點(diǎn)的大小,默認(rèn) 20,也可以是個(gè)數(shù)組,數(shù)組每個(gè)參數(shù)為對(duì)應(yīng)點(diǎn)的大小。
c:點(diǎn)的顏色,默認(rèn)藍(lán)色 ‘b’,也可以是個(gè) RGB 或 RGBA 二維行數(shù)組。
marker:點(diǎn)的樣式,默認(rèn)小圓圈 ‘o’。
cmap:Colormap,默認(rèn) None,標(biāo)量或者是一個(gè) colormap 的名字,只有 c 是一個(gè)浮點(diǎn)數(shù)數(shù)組的時(shí)才使用。如果沒有申明就是 image.cmap。
norm:Normalize,默認(rèn) None,數(shù)據(jù)亮度在 0-1 之間,只有 c 是一個(gè)浮點(diǎn)數(shù)的數(shù)組的時(shí)才使用。
vmin,vmax::亮度設(shè)置,在 norm 參數(shù)存在時(shí)會(huì)忽略。
alpha::透明度設(shè)置,0-1 之間,默認(rèn) None,即不透明。
linewidths::標(biāo)記點(diǎn)的長(zhǎng)度。
edgecolors::顏色或顏色序列,默認(rèn)為 ‘face’,可選值有 ‘face’, ‘none’, None。
plotnonfinite::布爾值,設(shè)置是否使用非限定的 c ( inf, -inf 或 nan) 繪制點(diǎn)。
**kwargs::其他參數(shù)。
我們主要用到的是前四個(gè)參數(shù),第一個(gè)參數(shù)是我們要畫散點(diǎn)圖的橫坐標(biāo),第二個(gè)是縱坐標(biāo),第三個(gè)散點(diǎn)圖中點(diǎn)的顏色,第四個(gè)散點(diǎn)圖中點(diǎn)的大小

準(zhǔn)備數(shù)據(jù):歸一化數(shù)值

def autoNorm(dataSet):minVals = dataSet.min(0)maxVals = dataSet.max(0)ranges = maxVals - minValsnormDataSet = zeros(shape(dataSet))m = dataSet.shape[0]normDataSet = dataSet - tile(minVals, (m, 1))normDataSet = normDataSet / tile(ranges, (m, 1))return normDataSet, ranges, minValsnormMat, ranges, minVals = autoNorm(datingDataMat)
print(normMat)

min()、max()方法
minVals = dataSet.min(0) 返回dataSet中每一列中的最小值數(shù)組
minVals = dataSet.min(1) 返回dataSet中每一行中的最小值數(shù)組

測(cè)試算法:作為完整程序驗(yàn)證分類器

def datingClassTest():hoRatio = 0.10datingDataMat, datingLabels = file2matrix('C:/Users/cxy/OneDrive/桌面/datingTestSet.txt')normMat, ranges, minVals = autoNorm(datingDataMat)m = normMat.shape[0]numTestVecs = int(m*hoRatio)errorCount = 0.0for i in range(numTestVecs):classifierResult = classify0(normMat[i, :], normMat[numTestVecs:m, :], datingLabels[numTestVecs:m], 3)print(f"the classifier came back with: {classifierResult}, the real answer is : {datingLabels[i]}")if classifierResult != datingLabels[i]:errorCount += 1.0print(f"the total error rate is : {errorCount / float(numTestVecs)}")datingClassTest();

手寫識(shí)別系統(tǒng)

from numpy import *
# kNN排序時(shí)將使用這個(gè)模塊提供好的函數(shù)
import operator
import matplotlib
import matplotlib.pyplot as pltdef createDataSet():group = array([[1.0, 1.1], [1.0, 1.0], [0, 0], [0, 0.1]])labels = ['A', 'A', 'B', 'B']return group, labelsdef classify0(inX, dataSet, labels, k):dataSetSize = dataSet.shape[0]diffMat = tile(inX, (dataSetSize, 1)) - dataSetsqDiffMat = diffMat ** 2sqDistances = sqDiffMat.sum(axis = 1)distances = sqDistances ** 0.5sortedDistIndicies = distances.argsort()classCount = {}for i in range(k):voteIlabel = labels[sortedDistIndicies[i]]classCount[voteIlabel] = classCount.get(voteIlabel, 0) + 1sortedClassCount = sorted(classCount.items(),key = operator.itemgetter(1), reverse= True)return sortedClassCount[0][0]# [group, labels] = createDataSet()
# m = classify0([0, 0], group, labels, 2)
# print(m)def file2matrix(filename):fr = open(filename)arrarOLines = fr.readlines()numberOfLines = len(arrarOLines)returnMat = zeros((numberOfLines, 3))classLabelVector = []index = 0for line in arrarOLines:line = line.strip()listFromLine = line.split('\t')# 將數(shù)據(jù)的前三行直接存入特征矩陣returnMat[index,:] = listFromLine[0:3]# 將字符串映射成數(shù)字if listFromLine[-1] == 'didntLike':classLabelVector.append(1)elif listFromLine[-1] == 'smallDoses':classLabelVector.append(2)elif listFromLine[-1] == 'largeDoses':classLabelVector.append(3)index += 1return returnMat, classLabelVector# datingDataMat, datingLabels = file2matrix('C:/Users/cxy/OneDrive/桌面/datingTestSet.txt')
# print(datingDataMat)
# fig = plt.figure()
# ax = fig.add_subplot(111)
# ax.scatter(datingDataMat[:, 1], datingDataMat[:, 2], 15.0*array(datingLabels), 15.0*array(datingLabels))
# plt.show()def autoNorm(dataSet):minVals = dataSet.min(0)maxVals = dataSet.max(0)ranges = maxVals - minValsnormDataSet = zeros(shape(dataSet))m = dataSet.shape[0]normDataSet = dataSet - tile(minVals, (m, 1))normDataSet = normDataSet / tile(ranges, (m, 1))return normDataSet, ranges, minVals# normMat, ranges, minVals = autoNorm(datingDataMat)
# print(normMat)# def datingClassTest():
#     hoRatio = 0.10
#     datingDataMat, datingLabels = file2matrix('C:/Users/cxy/OneDrive/桌面/datingTestSet.txt')
#     normMat, ranges, minVals = autoNorm(datingDataMat)
#     m = normMat.shape[0]
#     numTestVecs = int(m*hoRatio)
#     errorCount = 0.0
#     for i in range(numTestVecs):
#         classifierResult = classify0(normMat[i, :], normMat[numTestVecs:m, :], datingLabels[numTestVecs:m], 3)
#         print(f"the classifier came back with: {classifierResult}, the real answer is : {datingLabels[i]}")
#         if classifierResult != datingLabels[i]:
#             errorCount += 1.0
#     print(f"the total error rate is : {errorCount / float(numTestVecs)}")
#
# datingClassTest();def classifyPerson():resultList = ['not at all', 'in small doses', 'in large doses']percentTats = float(input("percentage of time spent playing video games?"))ffMiles = float(input("frequent flier miles earned per year?"))iceCream = float(input("liters of ice cream consumed per year?"))datingDataMat, datingLabels = file2matrix('C:/Users/cxy/OneDrive/桌面/datingTestSet.txt')normMat, ranges, minVals = autoNorm(datingDataMat)inArr = array([ffMiles, percentTats, iceCream])classifierResult = classify0((inArr - minVals) / ranges, normMat, datingLabels, 3)print(f"You will probably like this person: {resultList[classifierResult - 1]}")classifyPerson()

5.png

http://aloenet.com.cn/news/32287.html

相關(guān)文章:

  • 社區(qū)網(wǎng)站建設(shè)策劃方案如何推廣一個(gè)平臺(tái)
  • 做臨時(shí)網(wǎng)站優(yōu)化一個(gè)網(wǎng)站需要多少錢
  • 如何通過(guò)網(wǎng)站自己做網(wǎng)站谷歌優(yōu)化seo
  • 做美容美發(fā)的網(wǎng)站有哪些關(guān)于進(jìn)一步優(yōu)化 廣州
  • 中網(wǎng)可信網(wǎng)站是真的嗎教育機(jī)構(gòu)培訓(xùn)
  • 安陽(yáng)做網(wǎng)站推廣網(wǎng)站排名優(yōu)化怎樣做
  • 產(chǎn)品經(jīng)理如何做p2p網(wǎng)站改版短視頻矩陣seo系統(tǒng)源碼
  • 長(zhǎng)沙手機(jī)網(wǎng)站設(shè)計(jì)公司百度瀏覽官網(wǎng)
  • 最簡(jiǎn)單的網(wǎng)站制作360指數(shù)官網(wǎng)
  • 做網(wǎng)站文章要一篇一篇的寫嗎獲客
  • wordpress全站登陸可見教育培訓(xùn)機(jī)構(gòu)加盟十大排名
  • 防止網(wǎng)站流量被刷seo數(shù)據(jù)是什么
  • 微信小程序代運(yùn)營(yíng)長(zhǎng)沙排名優(yōu)化公司
  • 橙色網(wǎng)站欣賞百度一下百度搜索
  • 網(wǎng)站布局如何修改重慶網(wǎng)站制作公司
  • 2015做啥網(wǎng)站能致富百度官方網(wǎng)頁(yè)
  • 做一手房用什么網(wǎng)站百度競(jìng)價(jià)開戶需要多少錢
  • 南通網(wǎng)站建設(shè)優(yōu)化公司網(wǎng)站優(yōu)化排名公司
  • 網(wǎng)站建設(shè)頁(yè)面設(shè)計(jì)規(guī)格全國(guó)31省市疫情最新消息今天
  • 正規(guī)網(wǎng)站建設(shè)定制學(xué)電商出來(lái)一般干什么工作
  • 莒縣網(wǎng)站設(shè)計(jì)免費(fèi)百度seo引流
  • 微信登錄界面相城seo網(wǎng)站優(yōu)化軟件
  • 青海省高速公路建設(shè)管理局網(wǎng)站百度知道網(wǎng)頁(yè)版入口
  • 外包項(xiàng)目刷seo快速排名
  • 品牌網(wǎng)站建設(shè)有哪兩種模式百度問(wèn)問(wèn)
  • 網(wǎng)頁(yè)設(shè)計(jì)作業(yè)報(bào)告范文成都網(wǎng)站優(yōu)化
  • 設(shè)計(jì)培訓(xùn)網(wǎng)頁(yè)版草根seo視頻大全網(wǎng)站
  • 黃石企業(yè)網(wǎng)站建設(shè)開發(fā)阿里云com域名注冊(cè)
  • 龍華哪有做網(wǎng)站設(shè)計(jì)網(wǎng)站關(guān)鍵詞優(yōu)化排名推薦
  • 蘭州關(guān)鍵詞優(yōu)化效果西安seo服務(wù)培訓(xùn)