資源簡介
此資源主要是python代碼 涵蓋了人臉識別,深度學習,卷積神經網絡等一些列的算法程序

代碼片段和文件信息
#?-*-?coding:?utf-8?-*-
“““
Created?on?Fri?Jul?10?22:04:33?2015
@author:?wepon
“““
import?numpy?as?np
class?DecisionTree:
????“““決策樹使用方法:
????
????????-?生成實例:?clf?=?DecisionTrees().?參數mode可選,ID3或C4.5,默認C4.5
????????
????????-?訓練,調用fit方法:?clf.fit(Xy).??Xy均為np.ndarray類型
????????????????????????????
????????-?預測,調用predict方法:?clf.predict(X).?X為np.ndarray類型
?????????????????????????????????
????????-?可視化決策樹,調用showTree方法?
????
????“““
????def?__init__(selfmode=‘C4.5‘):
????????self._tree?=?None
????????
????????if?mode?==?‘C4.5‘?or?mode?==?‘ID3‘:
????????????self._mode?=?mode
????????else:
????????????raise?Exception(‘mode?should?be?C4.5?or?ID3‘)
????????
????????????
????
????def?_calcEntropy(selfy):
????????“““
????????函數功能:計算熵
????????參數y:數據集的標簽
????????“““
????????num?=?y.shape[0]
????????#統計y中不同label值的個數,并用字典labelCounts存儲
????????labelCounts?=?{}
????????for?label?in?y:
????????????if?label?not?in?labelCounts.keys():?labelCounts[label]?=?0
????????????labelCounts[label]?+=?1
????????#計算熵
????????entropy?=?0.0
????????for?key?in?labelCounts:
????????????prob?=?float(labelCounts[key])/num
????????????entropy?-=?prob?*?np.log2(prob)
????????return?entropy
????
????
????
????def?_splitDataSet(selfXyindexvalue):
????????“““
????????函數功能:返回數據集中特征下標為index,特征值等于value的子數據集
????????“““
????????ret?=?[]
????????featVec?=?X[:index]
????????X?=?X[:[i?for?i?in?range(X.shape[1])?if?i!=index]]
????????for?i?in?range(len(featVec)):
????????????if?featVec[i]==value:
????????????????ret.append(i)
????????return?X[ret:]y[ret]
????
????
????def?_chooseBestFeatureToSplit_ID3(selfXy):
????????“““ID3
????????函數功能:對輸入的數據集,選擇最佳分割特征
????????參數dataSet:數據集,最后一列為label
????????主要變量說明:
????????????????numFeatures:特征個數
????????????????oldEntropy:原始數據集的熵
????????????????newEntropy:按某個特征分割數據集后的熵
????????????????infoGain:信息增益
????????????????bestInfoGain:記錄最大的信息增益
????????????????bestFeatureIndex:信息增益最大時,所選擇的分割特征的下標
????????“““
????????numFeatures?=?X.shape[1]
????????oldEntropy?=?self._calcEntropy(y)
????????bestInfoGain?=?0.0
????????bestFeatureIndex?=?-1
????????#對每個特征都計算一下infoGain,并用bestInfoGain記錄最大的那個
????????for?i?in?range(numFeatures):????????
????????????featList?=?X[:i]
????????????uniqueVals?=?set(featList)
????????????newEntropy?=?0.0
????????????#對第i個特征的各個value,得到各個子數據集,計算各個子數據集的熵,
????????????#進一步地可以計算得到根據第i個特征分割原始數據集后的熵newEntropy
????????????for?value?in?uniqueVals:
????????????????sub_Xsub_y?=?self._splitDataSet(Xyivalue)
????????????????prob?=?len(sub_y)/float(len(y))
????????????????newEntropy?+=?prob?*?self._calcEntropy(sub_y)??
????????????#計算信息增益,根據信息增益選擇最佳分割特征
????????????infoGain?=?oldEntropy?-?newEntropy
????????????if?(infoGain?>?bestInfoGain):
????????????????bestInfoGain?=?infoGain
????????????????bestFeatureIndex?=?i
????????return?bestFeatureIndex
????????
????def?_chooseBestFeatureToSplit_C45(selfXy):
????????“““C4.5
????????????ID3算法計算的是信息增益,C4.5算法計算的是信息增益比,對上面ID3版本的函數稍作修改即可
????????“““
????????numFeatures?=?X.shape[1]
????????ol
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-07-28?09:44??MachineLearning-master\
?????文件?????????180??2017-07-28?09:44??MachineLearning-master\.gitignore
?????目錄???????????0??2017-07-28?09:44??MachineLearning-master\DecisionTree\
?????文件????????9244??2017-07-28?09:44??MachineLearning-master\DecisionTree\id3_c45.py
?????文件????????1304??2017-07-28?09:44??MachineLearning-master\DecisionTree\readme.md
?????文件????????3283??2017-07-28?09:44??MachineLearning-master\DecisionTree\treePlotter.py
?????目錄???????????0??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\
?????目錄???????????0??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\cnn_LeNet\
?????文件???????12645??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\cnn_LeNet\convolutional_mlp.py
?????文件???????20706??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\cnn_LeNet\convolutional_mlp_commentate.py
?????目錄???????????0??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\dive_into_keras\
?????文件????????2197??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\dive_into_keras\cnn-svm.py
?????文件????????2550??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\dive_into_keras\cnn.py
?????文件?????????756??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\dive_into_keras\data.py
?????文件????????1432??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\dive_into_keras\get_feature_map.py
?????文件????????3300??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\dive_into_keras\README.md
?????目錄???????????0??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\FaceRecognition_CNN(olivettifaces)\
?????文件?????1182905??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\FaceRecognition_CNN(olivettifaces)\olivettifaces.gif
?????文件???????15554??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\FaceRecognition_CNN(olivettifaces)\train_CNN_olivettifaces.py
?????文件????????7042??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\FaceRecognition_CNN(olivettifaces)\use_CNN_olivettifaces.py
?????目錄???????????0??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\keras_usage\
?????文件????????5233??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\keras_usage\cnn.py
?????文件?????????764??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\keras_usage\data.py
?????文件????????9005??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\keras_usage\README.md
?????目錄???????????0??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\mlp\
?????文件???????14181??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\mlp\mlp.py
?????文件???????17794??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\mlp\mlp_with_commentate.py
?????文件?????????527??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\readme.md
?????目錄???????????0??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\Softmax_sgd(or?logistic_sgd)\
?????文件????????9456??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\Softmax_sgd(or?logistic_sgd)\logistic_sgd.py
?????文件???????19117??2017-07-28?09:44??MachineLearning-master\DeepLearning?Tutorials\Softmax_sgd(or?logistic_sgd)\logistic_sgd_commentate.py
............此處省略613個文件信息
評論
共有 條評論