国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專(zhuān)欄INFORMATION COLUMN

基于Sklearn機(jī)器學(xué)習(xí)實(shí)戰(zhàn)---基于Sklearn模塊的鏈路預(yù)測(cè)

BlackFlagBin / 2757人閱讀

摘要:簡(jiǎn)介自年發(fā)布以來(lái),已經(jīng)成為重要的機(jī)器學(xué)習(xí)庫(kù)了。簡(jiǎn)稱(chēng),支持包括分類(lèi)回歸降維和聚類(lèi)四大機(jī)器學(xué)習(xí)算法。利用這幾大模塊的優(yōu)勢(shì),可以大大提高機(jī)器學(xué)習(xí)的效率。已經(jīng)封裝了大量的機(jī)器學(xué)習(xí)算法,包括和。

Sklearn簡(jiǎn)介
自2007年發(fā)布以來(lái),scikit-learn已經(jīng)成為Python重要的機(jī)器學(xué)習(xí)庫(kù)了。scikit-learn簡(jiǎn)稱(chēng)sklearn,支持包括分類(lèi)、回歸、降維和聚類(lèi)四大機(jī)器學(xué)習(xí)算法。還包含了特征提取、數(shù)據(jù)處理和模型評(píng)估三大模塊。

??sklearn是Scipy的擴(kuò)展,建立在NumPy和matplotlib庫(kù)的基礎(chǔ)上。利用這幾大模塊的優(yōu)勢(shì),可以大大提高機(jī)器學(xué)習(xí)的效率。
??sklearn擁有著完善的文檔,上手容易,具有著豐富的API,在學(xué)術(shù)界頗受歡迎。sklearn已經(jīng)封裝了大量的機(jī)器學(xué)習(xí)算法,包括LIBSVM和LIBINEAR。同時(shí)sklearn內(nèi)置了大量數(shù)據(jù)集,節(jié)省了獲取和整理數(shù)據(jù)集的時(shí)間。

項(xiàng)目簡(jiǎn)介
鏈路預(yù)測(cè)是通過(guò)歷史連接信息預(yù)測(cè)未來(lái)可能產(chǎn)生的連接,即通過(guò)當(dāng)前網(wǎng)絡(luò)中的連邊信息預(yù)測(cè)將來(lái)可能產(chǎn)生的連邊信息。

項(xiàng)目源碼

from sklearn.model_selection import train_test_split # 分割數(shù)據(jù)模塊
from sklearn.neighbors import KNeighborsClassifier # K最近鄰(kNN,k-NearestNeighbor)分類(lèi)算法
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn import preprocessing
import matplotlib.pyplot as plt
from sklearn.svm import SVC
from math import isnan

定義計(jì)算共同鄰居指標(biāo)的方法 define some functions to calculate some baseline index 計(jì)算Jaccard相似性指標(biāo)

def Jaccavrd(MatrixAdjacency_Train):

Matrix_similarity = np.dot(MatrixAdjacency_Train,MatrixAdjacency_Train)

deg_row = sum(MatrixAdjacency_Train)
deg_row.shape = (deg_row.shape[0],1)
deg_row_T = deg_row.T
tempdeg = deg_row + deg_row_T
temp = tempdeg - Matrix_similarity

Matrix_similarity = Matrix_similarity / temp
return Matrix_similarity
定義計(jì)算Salton指標(biāo)的方法

def Salton_Cal(MatrixAdjacency_Train):

similarity = np.dot(MatrixAdjacency_Train,MatrixAdjacency_Train)

deg_row = sum(MatrixAdjacency_Train)
deg_row.shape = (deg_row.shape[0],1)
deg_row_T = deg_row.T
tempdeg = np.dot(deg_row,deg_row_T)
temp = np.sqrt(tempdeg)

np.seterr(divide="ignore", invalid="ignore")
Matrix_similarity = np.nan_to_num(similarity / temp)
Matrix_similarity = np.nan_to_num(Matrix_similarity)
return Matrix_similarity

def file2matrix(filepath):

f = open(filepath)
lines = f.readlines()
matrix = np.zeros((50, 50), dtype=float)
A_row = 0
for line in lines:
    list = line.strip("
").split(" ")
    matrix[A_row:] = list[0:50]
    A_row += 1
return matrix    

filepath = "3600/s0001.txt"
MatrixAdjacency = file2matrix(filepath)

similarity_matrix_Jaccavrd = Jaccavrd(MatrixAdjacency)
similarity_matrix_Salton = Salton_Cal(MatrixAdjacency)

filepath2 = "3600/s0002.txt"
MatrixAdjacency2 = file2matrix(filepath2)

similarity_matrix_Jaccavrd2 = Jaccavrd(MatrixAdjacency2)
similarity_matrix_Salton2 = Salton_Cal(MatrixAdjacency2)

filepath3 = "3600/s0003.txt"
MatrixAdjacency3 = file2matrix(filepath3)

similarity_matrix_Jaccavrd3 = Jaccavrd(MatrixAdjacency3)
similarity_matrix_Salton3 = Salton_Cal(MatrixAdjacency3)

獲取jaccard相似性矩陣的行數(shù)和列數(shù)

Jaccard_Row = similarity_matrix_Jaccavrd.shape[0]
Jaccard_Column = similarity_matrix_Jaccavrd.shape[1]
Jaccard_List = []
for i in range(Jaccard_Row):

for j in range(Jaccard_Column):
    if i
獲取Salton相似性矩陣的行數(shù)和列數(shù)

Salton_Row = similarity_matrix_Salton.shape[0]
Salton_Column = similarity_matrix_Salton.shape[1]
Salton_List = []
for i in range(Salton_Row):

for j in range(Salton_Column):
    if i
獲取jaccard相似性矩陣的行數(shù)和列數(shù)

Jaccard_Row2 = similarity_matrix_Jaccavrd2.shape[0]
Jaccard_Column2 = similarity_matrix_Jaccavrd2.shape[1]
Jaccard_List2 = []
for i in range(Jaccard_Row2):

for j in range(Jaccard_Column2):
    if i
獲取Salton相似性矩陣的行數(shù)和列數(shù)

Salton_Row2 = similarity_matrix_Salton2.shape[0]
Salton_Column2 = similarity_matrix_Salton2.shape[1]
Salton_List2 = []
for i in range(Salton_Row2):

for j in range(Salton_Column2):
    if i
獲取jaccard相似性矩陣的行數(shù)和列數(shù)

Jaccard_Row3 = similarity_matrix_Jaccavrd3.shape[0]
Jaccard_Column3 = similarity_matrix_Jaccavrd3.shape[1]
Jaccard_List3 = []
for i in range(Jaccard_Row3):

for j in range(Jaccard_Column3):
    if i
獲取Salton相似性矩陣的行數(shù)和列數(shù)

Salton_Row3 = similarity_matrix_Salton3.shape[0]
Salton_Column3 = similarity_matrix_Salton3.shape[1]
Salton_List3 = []
for i in range(Salton_Row3):

for j in range(Salton_Column3):
    if i
獲取鄰接矩陣的行數(shù)和列數(shù)

Adjacency_Row = MatrixAdjacency.shape[0]
Adjacency_Column = MatrixAdjacency.shape[1]
Adjacency = []
for i in range(Adjacency_Row):

for j in range(Adjacency_Column):
    if i
獲取鄰接矩陣的行數(shù)和列數(shù)

Adjacency_Row2 = MatrixAdjacency2.shape[0]
Adjacency_Column2 = MatrixAdjacency2.shape[1]
Adjacency2 = []
for i in range(Adjacency_Row2):

for j in range(Adjacency_Column2):
    if i
獲取鄰接矩陣的行數(shù)和列數(shù)

Adjacency_Row3 = MatrixAdjacency3.shape[0]
Adjacency_Column3 = MatrixAdjacency3.shape[1]
Adjacency3 = []
for i in range(Adjacency_Row3):

for j in range(Adjacency_Column3):
    if i

data = np.zeros((1225,3))
data2 = np.zeros((1225,3))
data3 = np.zeros((1225,3))

for i in range(1225):

data[i][0] =  Jaccard_List[i]
data[i][1] = Salton_List[i]
data[i][2] = Adjacency[i]

for j in range(1225):

data2[j][0] =  Jaccard_List2[j]
data2[j][1] = Salton_List2[j]
data2[j][2] = Adjacency2[j]

for k in range(1225):

data3[k][0] =  Jaccard_List3[k]
data3[k][1] = Salton_List3[k]
data3[k][2] = Adjacency3[k]

data_train_X = data[:,0:2]
data_train_y = data[:,2]

data_test_X = data2[:,0:2]
data_test_y = data2[:,2]

data_target_X = data3[:,0:2]
data_target_y = data3[:,2]

knn = KNeighborsClassifier()
knn.fit(data_train_X,data_train_y)

print(knn.predict(data_test_X))

print(data_test_y)

clf = SVC()
clf.fit(data_train_X,data_test_y)

print(clf.score(data_test_X,data_target_y))

項(xiàng)目詳細(xì)了解

如需詳細(xì)本項(xiàng)目信息,可發(fā)送郵件至18770918982@gmail.com

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/43556.html

相關(guān)文章

  • ApacheCN 人工智能知識(shí)樹(shù) v1.0

    摘要:貢獻(xiàn)者飛龍版本最近總是有人問(wèn)我,把這些資料看完一遍要用多長(zhǎng)時(shí)間,如果你一本書(shū)一本書(shū)看的話(huà),的確要用很長(zhǎng)時(shí)間。為了方便大家,我就把每本書(shū)的章節(jié)拆開(kāi),再按照知識(shí)點(diǎn)合并,手動(dòng)整理了這個(gè)知識(shí)樹(shù)。 Special Sponsors showImg(https://segmentfault.com/img/remote/1460000018907426?w=1760&h=200); 貢獻(xiàn)者:飛龍版...

    劉厚水 評(píng)論0 收藏0
  • Sklearn入門(mén)介紹

    摘要:隨著時(shí)代的到來(lái)及物聯(lián)網(wǎng)概念的日益受到人們的關(guān)注,機(jī)器學(xué)習(xí)正逐步應(yīng)用于科技生活生產(chǎn)各個(gè)領(lǐng)域。今天我們就為介紹機(jī)器學(xué)習(xí)中常用到的一個(gè)第三庫(kù),它是屬于的第三方庫(kù),今天的講解也是基于來(lái)進(jìn)行講解的。 隨著AI時(shí)代的到來(lái)及物聯(lián)網(wǎng)概念的日益受到人們的關(guān)注,機(jī)器學(xué)習(xí)正逐步應(yīng)用于科技、生活生產(chǎn)各個(gè)領(lǐng)域。今天我們就為介紹機(jī)器學(xué)習(xí)中常用到的一個(gè)第三庫(kù)Sklearn,它是屬于python的第三方庫(kù),今天的講解...

    superPershing 評(píng)論0 收藏0
  • Sklearn入門(mén)介紹

    摘要:隨著時(shí)代的到來(lái)及物聯(lián)網(wǎng)概念的日益受到人們的關(guān)注,機(jī)器學(xué)習(xí)正逐步應(yīng)用于科技生活生產(chǎn)各個(gè)領(lǐng)域。今天我們就為介紹機(jī)器學(xué)習(xí)中常用到的一個(gè)第三庫(kù),它是屬于的第三方庫(kù),今天的講解也是基于來(lái)進(jìn)行講解的。 隨著AI時(shí)代的到來(lái)及物聯(lián)網(wǎng)概念的日益受到人們的關(guān)注,機(jī)器學(xué)習(xí)正逐步應(yīng)用于科技、生活生產(chǎn)各個(gè)領(lǐng)域。今天我們就為介紹機(jī)器學(xué)習(xí)中常用到的一個(gè)第三庫(kù)Sklearn,它是屬于python的第三方庫(kù),今天的講解...

    miracledan 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<