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

資訊專欄INFORMATION COLUMN

基于Sklearn機器學習實戰---基于Sklearn模塊的鏈路預測

BlackFlagBin / 2761人閱讀

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

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

??sklearn是Scipy的擴展,建立在NumPy和matplotlib庫的基礎上。利用這幾大模塊的優勢,可以大大提高機器學習的效率。
??sklearn擁有著完善的文檔,上手容易,具有著豐富的API,在學術界頗受歡迎。sklearn已經封裝了大量的機器學習算法,包括LIBSVM和LIBINEAR。同時sklearn內置了大量數據集,節省了獲取和整理數據集的時間。

項目簡介
鏈路預測是通過歷史連接信息預測未來可能產生的連接,即通過當前網絡中的連邊信息預測將來可能產生的連邊信息。

項目源碼

from sklearn.model_selection import train_test_split # 分割數據模塊
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

定義計算共同鄰居指標的方法 define some functions to calculate some baseline index 計算Jaccard相似性指標

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
定義計算Salton指標的方法

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相似性矩陣的行數和列數

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相似性矩陣的行數和列數

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相似性矩陣的行數和列數

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相似性矩陣的行數和列數

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相似性矩陣的行數和列數

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相似性矩陣的行數和列數

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
獲取鄰接矩陣的行數和列數

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
獲取鄰接矩陣的行數和列數

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
獲取鄰接矩陣的行數和列數

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))

項目詳細了解

如需詳細本項目信息,可發送郵件至18770918982@gmail.com

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://m.specialneedsforspecialkids.com/yun/43556.html

相關文章

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

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

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

    摘要:隨著時代的到來及物聯網概念的日益受到人們的關注,機器學習正逐步應用于科技生活生產各個領域。今天我們就為介紹機器學習中常用到的一個第三庫,它是屬于的第三方庫,今天的講解也是基于來進行講解的。 隨著AI時代的到來及物聯網概念的日益受到人們的關注,機器學習正逐步應用于科技、生活生產各個領域。今天我們就為介紹機器學習中常用到的一個第三庫Sklearn,它是屬于python的第三方庫,今天的講解...

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

    摘要:隨著時代的到來及物聯網概念的日益受到人們的關注,機器學習正逐步應用于科技生活生產各個領域。今天我們就為介紹機器學習中常用到的一個第三庫,它是屬于的第三方庫,今天的講解也是基于來進行講解的。 隨著AI時代的到來及物聯網概念的日益受到人們的關注,機器學習正逐步應用于科技、生活生產各個領域。今天我們就為介紹機器學習中常用到的一個第三庫Sklearn,它是屬于python的第三方庫,今天的講解...

    miracledan 評論0 收藏0

發表評論

0條評論

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