成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

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

BlackFlagBin / 2762人閱讀

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

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

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

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

項(xiàng)目源碼

from sklearn.model_selection import train_test_split # 分割數(shù)據(jù)模塊
from sklearn.neighbors import KNeighborsClassifier # K最近鄰(kNN,k-NearestNeighbor)分類算法
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ā)送郵件至[email protected]

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

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/43556.html

相關(guān)文章

  • ApacheCN 人工智能知識樹 v1.0

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

    劉厚水 評論0 收藏0
  • Sklearn入門介紹

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

    superPershing 評論0 收藏0
  • Sklearn入門介紹

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

    miracledan 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<