資源簡介
機器學習算法,包含隨機森林,決策樹,SVM,CNN等十幾種算法的程序包

代碼片段和文件信息
#?coding:UTF-8
‘‘‘
Date:20160923
@author:?zhaozhiyong
‘‘‘
import?numpy?as?np
import?math
MinPts?=?5??#?定義半徑內的最少的數據點的個數
def?load_data(file_path):
????‘‘‘導入數據
????input:??file_path(string):文件名
????output:?data(mat):數據
????‘‘‘
????f?=?open(file_path)
????data?=?[]
????for?line?in?f.readlines():
????????data_tmp?=?[]
????????lines?=?line.strip().split(“\t“)
????????for?x?in?lines:
????????????data_tmp.append(float(x.strip()))
????????data.append(data_tmp)
????f.close()
????return?np.mat(data)
def?epsilon(data?MinPts):
????‘‘‘計算半徑
????input:??data(mat):訓練數據
????????????MinPts(int):半徑內的數據點的個數
????output:?eps(float):半徑
????‘‘‘
????m?n?=?np.shape(data)
????xMax?=?np.max(data?0)
????xMin?=?np.min(data?0)
????eps?=?((np.prod(xMax?-?xMin)?*?MinPts?*?math.gamma(0.5?*?n?+?1))?/?(m?*?math.sqrt(math.pi?**?n)))?**?(1.0?/?n)
????return?eps
????
def?distance(data):
????m?n?=?np.shape(data)
????dis?=?np.mat(np.zeros((m?m)))
????for?i?in?xrange(m):
????????for?j?in?xrange(i?m):
????????????#?計算i和j之間的歐式距離
????????????tmp?=?0
????????????for?k?in?xrange(n):
????????????????tmp?+=?(data[i?k]?-?data[j?k])?*?(data[i?k]?-?data[j?k])
????????????dis[i?j]?=?np.sqrt(tmp)
????????????dis[j?i]?=?dis[i?j]
????return?dis
def?find_eps(distance_D?eps):
????ind?=?[]
????n?=?np.shape(distance_D)[1]
????for?j?in?xrange(n):
????????if?distance_D[0?j]?<=?eps:
????????????ind.append(j)
????return?ind
def?dbscan(data?eps?MinPts):
????m?=?np.shape(data)[0]
????#?區分核心點1,邊界點0和噪音點-1
????types?=?np.mat(np.zeros((1?m)))
????sub_class?=?np.mat(np.zeros((1?m)))
????#?用于判斷該點是否處理過,0表示未處理過
????dealed?=?np.mat(np.zeros((m?1)))
????#?計算每個數據點之間的距離
????dis?=?distance(data)
????#?用于標記類別
????number?=?1
????
????#?對每一個點進行處理
????for?i?in?xrange(m):
????????#?找到未處理的點
????????if?dealed[i?0]?==?0:
????????????#?找到第i個點到其他所有點的距離
????????????D?=?dis[i?]
????????????#?找到半徑eps內的所有點
????????????ind?=?find_eps(D?eps)
????????????#?區分點的類型
????????????#?邊界點
????????????if?len(ind)?>?1?and?len(ind)?????????????????types[0?i]?=?0
????????????????sub_class[0?i]?=?0
????????????#?噪音點
????????????if?len(ind)?==?1:
????????????????types[0?i]?=?-1
????????????????sub_class[0?i]?=?-1
????????????????dealed[i?0]?=?1
????????????#?核心點
????????????if?len(ind)?>=?MinPts?+?1:
????????????????types[0?i]?=?1
????????????????for?x?in?ind:
????????????????????sub_class[0?x]?=?number
????????????????#?判斷核心點是否密度可達
????????????????while?len(ind)?>?0:
????????????????????dealed[ind[0]?0]?=?1
????????????????????D?=?dis[ind[0]?]
????????????????????tmp?=?ind[0]
????????????????????del?ind[0]
????????????????????ind_1?=?find_eps(D?eps)
????????????????????
????????????????????if?len(ind_1)?>?1:??#?處理非噪音點
????????????????????????for?x1?in?ind_1:
????????????????????????????sub_class[0?x1]?=?number
????????????????????????if?len(ind_1)?>=?MinPts?+?1:
????????????????????????????types[0?tmp]?=?1
????????????????????????else:
????????????????????????????types[0?tmp]?=?0
??????????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-04-16?23:33??機器學習算法Python-Machine-Learning-Algorithm-master\
?????目錄???????????0??2018-04-16?23:33??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter12_DBSCAN\
?????文件????????1520??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter12_DBSCAN\data.txt
?????文件????????4631??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter12_DBSCAN\dbscan.py
?????目錄???????????0??2018-04-16?23:33??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_1?Logistic?Regression\
?????文件??????????32??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_1?Logistic?Regression\README.md
?????文件????????7251??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_1?Logistic?Regression\data.txt
?????文件????????2420??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_1?Logistic?Regression\lr_test.py
?????文件????????2907??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_1?Logistic?Regression\lr_train.py
?????文件????????6851??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_1?Logistic?Regression\test_data
?????目錄???????????0??2018-04-16?23:33??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_10?KMeans\
?????文件????????4278??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_10?KMeans\KMeans.py
?????文件????????2746??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_10?KMeans\KMeanspp.py
?????文件????????2800??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_10?KMeans\data.txt
?????目錄???????????0??2018-04-16?23:33??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_11?MeanShift\
?????文件????????3001??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_11?MeanShift\data
?????文件????????5620??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_11?MeanShift\mean_shift.py
?????目錄???????????0??2018-04-16?23:33??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_13?LabelPropagation\
?????文件?????????131??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_13?LabelPropagation\cd_data.txt
?????文件????????4356??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_13?LabelPropagation\lb.py
?????目錄???????????0??2018-04-16?23:33??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_14?CollaborativeFiltering\
?????文件??????????50??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_14?CollaborativeFiltering\data.txt
?????文件????????2386??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_14?CollaborativeFiltering\item_ba
?????文件????????3737??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_14?CollaborativeFiltering\user_ba
?????目錄???????????0??2018-04-16?23:33??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_15?MatrixFactorization\
?????文件??????????50??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_15?MatrixFactorization\data.txt
?????文件????????4325??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_15?MatrixFactorization\mf.py
?????文件????????1720??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_15?MatrixFactorization\nmf.py
?????目錄???????????0??2018-04-16?23:33??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_16?PersonalRank\
?????文件??????????50??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_16?PersonalRank\data.txt
?????文件????????3262??2017-12-01?23:19??機器學習算法Python-Machine-Learning-Algorithm-master\Chapter_16?PersonalRank\personal_rank.py
............此處省略51個文件信息
評論
共有 條評論