├── AdaLineGD
├── AdaLineGD.py
├── AdalineGD_1.png
├── AdalineGD_2.png
├── MLPlot.py
├── README.md
├── img
│ ├── twitter_AdaLine_1-2_170718.png
│ ├── twitter_NN1_1_160825.png
│ ├── twitter_NN1_2_160825.png
│ ├── twitter_NN2-1_160826.png
│ ├── twitter_NN2-2_160826.png
│ ├── twitter_NN3'-1_160827.png
│ ├── twitter_NN4'-1_160829.png
│ ├── twitter_NN6-1_160829.png
│ ├── twitter_NN6-2_160829.png
│ ├── twitter_NN8-2''_160902.png
│ └── twitter_NN8-3''_160902.png
└── main.py
├── AdaLineSGD
├── AdaLineSGD.py
├── AdalineSGD_1.png
├── AdalineSGD_2.png
├── AdalineSGD_3.png
├── MLPlot.py
├── Plot2D.py
├── README.md
├── img
│ ├── twitter_AdaLine_1-2_170718.png
│ ├── twitter_AdaLine_2-2_170719.png
│ ├── twitter_NN1_1_160825.png
│ ├── twitter_NN1_2_160825.png
│ ├── twitter_NN2-1_160826.png
│ ├── twitter_NN2-2_160826.png
│ ├── twitter_NN3'-1_160827.png
│ ├── twitter_NN4'-1_160829.png
│ ├── twitter_NN6-1_160829.png
│ ├── twitter_NN6-2_160829.png
│ ├── twitter_NN8-2''_160902.png
│ └── twitter_NN8-3''_160902.png
└── main.py
├── ClusteringAnalysis_scikit-learn
├── ClutterringAnalysis_scikit-learn_1-1.png
├── ClutterringAnalysis_scikit-learn_1-2.png
├── ClutterringAnalysis_scikit-learn_1-3.png
├── ClutterringAnalysis_scikit-learn_2-1.png
├── EnsembleModelClassifier.py
├── MLPlot.py
├── MLPreProcess.py
├── README.md
├── clustering.py
├── img
│ ├── twitter_情報理論_情報と確率_9-3_170623.png
│ ├── twitter_情報理論_情報と確率_9-4_170623.png
│ ├── twitter_情報理論_情報と確率_9-5_170623.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-10_170701.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-6_170701.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-7'_170701.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-8_170701.png
│ └── twitter_情報理論_混合モデルとアンサンブル学習_11-9_170701.png
├── main1.py
└── main2.py
├── DataPreProcess_scikit-learn
├── DataPreProcess.py
├── DataPreProcess_scikit-learn_1'.png
├── DataPreProcess_scikit-learn_1.png
├── README.md
├── img
│ ├── twitter_機械学習_3-1_160924.png
│ ├── twitter_機械学習_3-2_160924.png
│ ├── twitter_機械学習_3-3_160924.png
│ ├── twitter_機械学習_3-4_170727.png
│ ├── twitter_機械学習_3-5_170810.png
│ ├── twitter_機械学習_3-6_170810.png
│ ├── twitter_機械学習_3-7_170810.png
│ └── twitter_機械学習_3-8_170810.png
└── main.py
├── DecisionTree_scikit-learn
├── DecisionTree.py
├── DecisionTree1.dot
├── DecisionTree2.dot
├── DecisionTree3.dot
├── DecisionTree_Graph1.png
├── DecisionTree_Graph2.png
├── DecisionTree_Graph3.png
├── DecisionTree_scikit-learn_1.png
├── DecisionTree_scikit-learn_2'.png
├── DecisionTree_scikit-learn_2.png
├── DecisionTree_scikit-learn_3'.png
├── DecisionTree_scikit-learn_3.png
├── MLPlot.py
├── README.md
├── img
│ ├── twitter_パターン認識21-12_170802.png
│ ├── twitter_パターン認識21-13_170802.png
│ ├── twitter_パターン認識21-14_170802.png
│ ├── twitter_パターン認識21-15_170802.png
│ ├── twitter_パターン認識21-1_170730.png
│ ├── twitter_パターン認識21-2_170730.png
│ ├── twitter_パターン認識21-3_170731.png
│ ├── twitter_パターン認識21-5_170731.png
│ ├── twitter_パターン認識21-6_170731.png
│ └── twitter_パターン認識21-7_170731.png
├── main1.py
└── main2.py
├── EnsembleLearning_scikit-learn
├── DataPreProcess.py
├── EnsembleLearning_scikit-learn_1'.png
├── EnsembleLearning_scikit-learn_1.png
├── EnsembleLearning_scikit-learn_2-1''.png
├── EnsembleLearning_scikit-learn_2-2''.png
├── EnsembleLearning_scikit-learn_3-1'.png
├── EnsembleLearning_scikit-learn_3-2'.png
├── EnsembleLearning_scikit-learn_4-1.png
├── EnsembleLearning_scikit-learn_4-2.png
├── EnsembleLearning_scikit-learn_5-1.png
├── EnsembleLearning_scikit-learn_6-1.png
├── EnsembleLearning_scikit-learn_7-1.png
├── EnsembleLearning_scikit-learn_naruto_1-1.png
├── EnsembleLearning_scikit-learn_naruto_1-2.png
├── EnsembleLearning_scikit-learn_naruto_1-3.png
├── EnsembleModelClassifier.py
├── Plot2D.py
├── README.md
├── data
│ └── naruto.csv
├── img
│ ├── twitter_パターン認識21-10_170801.png
│ ├── twitter_パターン認識21-11_170801.png
│ ├── twitter_パターン認識21-12_170802.png
│ ├── twitter_パターン認識21-13_170802.png
│ ├── twitter_パターン認識21-14_170802.png
│ ├── twitter_パターン認識21-15_170802.png
│ ├── twitter_パターン認識21-1_170730.png
│ ├── twitter_パターン認識21-2_170730.png
│ ├── twitter_パターン認識21-3_170731.png
│ ├── twitter_パターン認識21-5_170731.png
│ ├── twitter_パターン認識21-6_170731.png
│ ├── twitter_パターン認識21-7_170731.png
│ ├── twitter_パターン認識21-8_170801.png
│ ├── twitter_パターン認識21-9_170801.png
│ ├── twitter_パターン認識22-1_170802.png
│ ├── twitter_パターン認識22-2_170802.png
│ ├── twitter_パターン認識22-3_170802.png
│ ├── twitter_パターン認識22-4_170803.png
│ ├── twitter_パターン認識22-5_170803.png
│ ├── twitter_パターン認識22-6_170804.png
│ ├── twitter_パターン認識22-7_170804.png
│ ├── twitter_パターン認識22-8_170804.png
│ ├── twitter_パターン認識4-1_160918.png
│ ├── twitter_パターン認識5-2_160919.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-10_170701.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-11_170702.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-12_170703.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-13_170703.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-14_170704.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-15_170704.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-16_170705.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-17_170705.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-18_170705.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-19_170707.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-1_170626.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-2_170630.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-3_170630.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-4_170630.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-5_170630.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-6_170701.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-7'_170701.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-7_170701.png
│ ├── twitter_情報理論_混合モデルとアンサンブル学習_11-8_170701.png
│ └── twitter_情報理論_混合モデルとアンサンブル学習_11-9_170701.png
├── main1.py
├── main2.py
├── main3.py
├── main4.py
└── main5.py
├── LogisticRegression_scikit-learn
├── LogisticRegression.py
├── LogisticRegression_scikit-learn_1.png
├── LogisticRegression_scikit-learn_2.png
├── LogisticRegression_scikit-learn_3.png
├── LogisticRegression_scikit-learn_4'.png
├── LogisticRegression_scikit-learn_4.png
├── LogisticRegression_scikit-learn_5.png
├── MLPlot.py
├── README.md
├── img
│ ├── twitter_パターン認識18-10_170208.png
│ ├── twitter_パターン認識18-11'_170210.png
│ ├── twitter_パターン認識18-11_170209.png
│ ├── twitter_パターン認識18-12'_170210.png
│ ├── twitter_パターン認識18-12_170209.png
│ ├── twitter_パターン認識18-13_170210.png
│ ├── twitter_パターン認識18-14_170210.png
│ ├── twitter_パターン認識18-15_170210.png
│ ├── twitter_パターン認識18-16_170210.png
│ ├── twitter_パターン認識18-17_170726.png
│ ├── twitter_パターン認識18-18_170726.png
│ ├── twitter_パターン認識18-19_170727.png
│ ├── twitter_パターン認識18-1_161130.png
│ ├── twitter_パターン認識18-2_161130.png
│ ├── twitter_パターン認識18-3_161130.png
│ ├── twitter_パターン認識18-4_161130.png
│ ├── twitter_パターン認識18-5_161201.png
│ ├── twitter_パターン認識18-6'_170204.png
│ ├── twitter_パターン認識18-6_161201.png
│ ├── twitter_パターン認識18-7'_170204.png
│ ├── twitter_パターン認識18-7_161201.png
│ ├── twitter_パターン認識18-8_170204.png
│ ├── twitter_パターン認識18-9_170208.png
│ ├── twitter_機械学習_3-1_160924.png
│ ├── twitter_機械学習_3-2_160924.png
│ ├── twitter_機械学習_3-3_160924.png
│ ├── twitter_機械学習_3-4_170727.png
│ ├── twitter_機械学習_3-5_170810.png
│ ├── twitter_機械学習_3-6_170810.png
│ ├── twitter_機械学習_3-7_170810.png
│ └── twitter_機械学習_3-8_170810.png
└── main.py
├── MachineLearningPipeline_scikit-learn
├── DataPreProcess.py
├── MachineLearningPipeline_scikit-learn_1.png
├── MachineLearningPipeline_scikit-learn_2.png
├── MachineLearningPipeline_scikit-learn_3.png
├── MachineLearningPipeline_scikit-learn_4.png
├── MachineLearningPipeline_scikit-learn_5.png
├── MachineLearningPipeline_scikit-learn_5_1'.png
├── MachineLearningPipeline_scikit-learn_5_1.png
├── MachineLearningPipeline_scikit-learn_5_2'.png
├── MachineLearningPipeline_scikit-learn_5_2.png
├── MachineLearningPipeline_scikit-learn_5_3'.png
├── MachineLearningPipeline_scikit-learn_5_4'.png
├── Plot2D.py
├── README.md
├── img
│ ├── twitter_パターン認識10-1_161005.png
│ ├── twitter_パターン認識10-2_161005.png
│ ├── twitter_パターン認識10-3_161005.png
│ ├── twitter_パターン認識11-1_161005.png
│ ├── twitter_パターン認識11-3_161005.png
│ ├── twitter_パターン認識12-1_161004.png
│ ├── twitter_パターン認識13-10_170102.png
│ ├── twitter_パターン認識13-1_161227.png
│ ├── twitter_パターン認識13-2_161227.png
│ ├── twitter_パターン認識13-3_161229.png
│ ├── twitter_パターン認識13-5_170101.png
│ ├── twitter_パターン認識13-8_170102.png
│ ├── twitter_パターン認識13-9_170102.png
│ ├── twitter_パターン認識20-1_170108.png
│ ├── twitter_パターン認識4-1_160918.png
│ ├── twitter_パターン認識5-1_160918.png
│ ├── twitter_パターン認識5-2_160919.png
│ ├── twitter_パターン認識5-3_160922.png
│ ├── twitter_情報理論_情報と確率_10-1_170625.png
│ ├── twitter_情報理論_情報と確率_10-2_170625.png
│ ├── twitter_機械学習_3-1_160924.png
│ ├── twitter_機械学習_3-2_160924.png
│ └── twitter_機械学習_3-3_160924.png
├── main1.py
├── main2.py
├── main3.py
├── main4.py
└── main5.py
├── PCA_scikit-learn
├── DataPreProcess.py
├── PCA_scikit-learn_1.png
├── PCA_scikit-learn_2.png
├── PCA_scikit-learn_3.png
├── PCA_scikit-learn_4.png
├── PCA_scikit-learn_5.png
├── Plot2D.py
├── README.md
├── img
│ ├── twitter_PCA_1-1_170812.png
│ ├── twitter_PCA_1-2_170812.png
│ ├── twitter_PCA_1-3_170813.png
│ ├── twitter_多変量解析_主成分分析1-10_161209.png
│ ├── twitter_多変量解析_主成分分析1-1_161209.png
│ ├── twitter_多変量解析_主成分分析1-2_161209.png
│ ├── twitter_多変量解析_主成分分析1-3_161209.png
│ ├── twitter_多変量解析_主成分分析1-4_161209.png
│ ├── twitter_多変量解析_主成分分析1-5_161209.png
│ ├── twitter_多変量解析_主成分分析1-6_161209.png
│ ├── twitter_多変量解析_主成分分析1-7_161209.png
│ ├── twitter_多変量解析_主成分分析1-8_161209.png
│ ├── twitter_多変量解析_主成分分析1-9_161209.png
│ └── twitter_特徴抽出と次元削減_1-1_170812.png
├── main1.py
└── main2.py
├── Perceptron
├── MLPlot.py
├── Perceptron.py
├── Perceptron_1.png
├── README.md
├── img
│ ├── twitter_NN1_1_160825.png
│ ├── twitter_NN1_2_160825.png
│ ├── twitter_NN2-1_160826.png
│ ├── twitter_NN2-2_160826.png
│ ├── twitter_NN3'-1_160827.png
│ ├── twitter_NN4'-1_160829.png
│ ├── twitter_NN6-1_160829.png
│ ├── twitter_NN6-2_160829.png
│ ├── twitter_NN8-2''_160902.png
│ ├── twitter_NN8-3''_160902.png
│ └── twitter_パーセプトロン_1_2_170718.png
└── main.py
├── Perceptron_scikit-learn
├── MLPlot.py
├── Perceptron_scikit-learn_1.png
├── Perceptron_scikit-learn_2.png
├── README.md
├── img
│ ├── twitter_NN1_1_160825.png
│ ├── twitter_NN1_2_160825.png
│ ├── twitter_NN2-1_160826.png
│ ├── twitter_NN2-2_160826.png
│ ├── twitter_NN3'-1_160827.png
│ ├── twitter_NN4'-1_160829.png
│ ├── twitter_NN6-1_160829.png
│ ├── twitter_NN6-2_160829.png
│ ├── twitter_NN8-2''_160902.png
│ ├── twitter_NN8-3''_160902.png
│ └── twitter_python_scikit-learn_1_1_170719.png
└── main.py
├── README.md
├── RandomForests_scikit-learn
├── Plot2D.py
├── README.md
├── RamdomForest_scikit-learn_2'.png
├── RamdomForest_scikit-learn_2.png
├── RamdomForest_scikit-learn_3'.png
├── RamdomForest_scikit-learn_3.png
├── RamdomForest_scikit-learn_4'.png
├── RamdomForest_scikit-learn_4.png
├── RandomForest_scikit-learn_1'.png
├── RandomForest_scikit-learn_1.png
├── img
│ ├── twitter_パターン認識22-1_170802.png
│ ├── twitter_パターン認識22-2_170802.png
│ ├── twitter_パターン認識22-3_170802.png
│ ├── twitter_パターン認識22-6_170804.png
│ ├── twitter_パターン認識22-7_170804.png
│ └── twitter_パターン認識22-8_170804.png
├── main1.py
├── main2.py
├── main3.py
├── twitter_パターン認識22-4_170803.png
└── twitter_パターン認識22-5_170803.png
├── SVM_scikit-learn
├── MLPlot.py
├── MLPreProcess.py
├── README.md
├── SVM_scikit-learn_1'.png
├── SVM_scikit-learn_1.png
├── SVM_scikit-learn_2'.png
├── SVM_scikit-learn_2.png
├── SVM_scikit-learn_3'.png
├── SVM_scikit-learn_3.png
├── SVM_scikit-learn_4.png
├── SVM_scikit-learn_5'.png
├── SVM_scikit-learn_5.png
├── SVM_scikit-learn_6'.png
├── SVM_scikit-learn_6.png
├── img
│ ├── twitter_SVM_1-1_170211.png
│ ├── twitter_SVM_1-2_170211.png
│ ├── twitter_SVM_2-1_170212.png
│ ├── twitter_SVM_2-2_170212.png
│ ├── twitter_SVM_3-1_170214.png
│ ├── twitter_SVM_3-2_170214.png
│ ├── twitter_SVM_3-3_170214.png
│ ├── twitter_SVM_3-4_170214.png
│ ├── twitter_SVM_3-5_170216.png
│ ├── twitter_SVM_4-1_170216.png
│ ├── twitter_SVM_4-2_170217.png
│ ├── twitter_SVM_4-3_170217.png
│ ├── twitter_SVM_4-4_170218.png
│ ├── twitter_SVM_4-5_170218.png
│ ├── twitter_SVM_5-1_170219.png
│ ├── twitter_SVM_5-2_170220.png
│ ├── twitter_SVM_5-2_170225.png
│ ├── twitter_SVM_5-3_170222.png
│ ├── twitter_SVM_5-4_170225.png
│ ├── twitter_SVM_5-5_170303.png
│ ├── twitter_SVM_5-6_170303.png
│ ├── twitter_SVM_5-7_170305.png
│ ├── twitter_SVM_6-1_170728.png
│ ├── twitter_SVM_6-2'_170728.png
│ ├── twitter_SVM_6-3_170729.png
│ └── twitter_SVM_6-4_170729.png
├── main1.py
├── main2.py
├── main3.py
└── main4.py
├── dataset.md
├── kNN_scikit-learn
├── MLPlot.py
├── README.md
├── img
│ ├── twitter_パターン認識14-1_161007.png
│ ├── twitter_パターン認識14-2_161007.png
│ ├── twitter_パターン認識14-3_161008.png
│ ├── twitter_パターン認識14-4_161009.png
│ ├── twitter_パターン認識14-5_161010.png
│ ├── twitter_パターン認識16-1_161011.png
│ ├── twitter_パターン認識16-2_161012.png
│ ├── twitter_パターン認識16-5_161112.png
│ └── twitter_パターン認識16-6_161112.png
├── kNN_scikit-learn_1'.png
├── kNN_scikit-learn_1.png
├── kNN_scikit-learn_2'.png
├── kNN_scikit-learn_2.png
└── main.py
└── kernelPCA_scikit-learn
├── DataPreProcess.py
├── Plot2D.py
├── README.md
├── img
├── twitter_PCA_2-1_170815.png
├── twitter_PCA_2-2_170815.png
├── twitter_PCA_2-3_170815.png
└── twitter_PCA_2-4_170815.png
├── kernelPCA_scikit-learn_1'.png
├── kernelPCA_scikit-learn_1.png
├── kernelPCA_scikit-learn_2'.png
├── kernelPCA_scikit-learn_2.png
├── kernelPCA_scikit-learn_3.png
├── kernelPCA_scikit-learn_4'.png
├── kernelPCA_scikit-learn_5'.png
└── main1.py
/AdaLineGD/AdaLineGD.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | import numpy
3 |
4 | class AdaLineGD(object):
5 | """ADAptive Liner of classifier(分類器)by gradient descent(最急降下法)
6 |
7 | [インスタンス変数]
8 | pulic : publicな変数には便宜上 _ をつける
9 | weights_ : numpy.ndarray
10 | トレーニング後の重みベクトル
11 | [numpy.ndarray]
12 | 最初の属性 dtype は配列の要素の型
13 | 二番目の属性 ndim は,次元数
14 | 三番目の属性 shape は,各次元ごとの配列の大きさをまとめたタプルで指定
15 | cost_ : list
16 | 各エポックでのコスト関数(最小二乗誤差)
17 | Sum-of-squares cost function value in each epoch.
18 |
19 | private :
20 | lRate : float
21 | learning rate (0.0~1.0)
22 | numIter : int
23 | トレーニングデータの繰り返し回数のイテレータ数
24 | """
25 | def __init__(self, lRate=0.01, numIter=50):
26 | self.lRate = lRate
27 | self.numIter = numIter
28 |
29 | def fit(self, X_train, y_train):
30 | """
31 | ADALineを更新(学習)
32 | [Input]
33 | X_train : numpy.ndarray.shape = [numSamples, numFeatures]
34 | 学習データの行列
35 |
36 | y_train : numpy.ndarray.shape = [numSamples]
37 | ラベルのベクトル
38 |
39 | *numpy.ndarray
40 | 最初の属性 dtype は配列の要素の型
41 | 二番目の属性 ndim は,次元数
42 | 三番目の属性 shape は,スカラーや,タプルによって配列の各次元の長さを表したものです.
43 | 大きさが 5 のベクトルはスカラー 5 によって, 2×3 の行列はタプル (2, 3) によって表現します.
44 | [Output]
45 | self : 自身のオブジェクト
46 |
47 | """
48 | self.weights_ = numpy.zeros(1 + X_train.shape[1]) # numFeatures+1 個の全要素 0 の配列
49 | self.cost_ = []
50 |
51 | for i in range(self.numIter):
52 | # 活性化関数 [Activation Function] の出力の計算 Φ(w^T*x)=w^T*x
53 | output = self.calcNetInput(X_train)
54 |
55 | # 誤差 (y-Φ(w^T*x))の計算
56 | errors = (y_train - output)
57 |
58 | # 全ての重みの更新
59 | # ? Δw=η*∑( y-Φ(w^T*x) ) (j=1,2,...,m)
60 | self.weights_[1:] += self.lRate * X_train.T.dot(errors) # X_train.T : X_trainの転置行列
61 | # w0 の更新 Δw0=η*∑( y_train-output )
62 | self.weights_[0] += self.lRate * errors.sum()
63 |
64 | # コスト関数の計算 J(w)= (1/2)*∑( y-Φ(w^T*x) )^2
65 | cost = (1 / 2) * (errors ** 2).sum()
66 | self.cost_.append(cost)
67 |
68 | return self
69 |
70 |
71 | def calcNetInput(self, X_train):
72 | """
73 | AdaLineを構成する入力層から出力層への入力を計算
74 |
75 | """
76 | numInputLayer = numpy.dot(X_train, self.weights_[1:]) + self.weights_[0]
77 | return numInputLayer
78 |
79 | def calcActivationFunction(self, X_train):
80 | return self.calcNetInput(X_train)
81 |
82 | def predict(self, X_train):
83 | return numpy.where(self.calcActivationFunction(X_train) > 0.0 , 1, -1)
--------------------------------------------------------------------------------
/AdaLineGD/AdalineGD_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineGD/AdalineGD_1.png
--------------------------------------------------------------------------------
/AdaLineGD/AdalineGD_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineGD/AdalineGD_2.png
--------------------------------------------------------------------------------
/AdaLineGD/README.md:
--------------------------------------------------------------------------------
1 | ## AdaLineGD(Adaptive Liner ニューロン勾配降下法) [Adaptive Liner Gradient descent]
2 |
3 | 分かりやすいように main.py ファイル毎に1つの完結したコードにしています。
4 |
5 | ### 項目 [Contents]
6 |
7 | 1. [使用するライブラリ](#ID_1)
8 | 1. [使用するデータセット](#ID_2)
9 | 1. [コードの実行結果](#ID_3)
10 | 1. [AdaLine によるアヤメデータの識別 : `main1.py`](#ID_3-1)
11 | 1. [背景理論](#ID_4)
12 | 1. [ニューラルネットワークの概要](#ID_4-1)
13 | 1. [活性化関数](#ID_4-2)
14 | 1. [単純パーセプトロン](#ID_4-3)
15 | 1. [パーセプトロンによる論理演算](#ID_4-4)
16 | 1. [最急降下法による学習](#ID_4-5)
17 |
18 |
19 |
20 |
21 | ### 使用するライブラリ
22 |
23 |
24 |
25 |
26 | ### 使用するデータセット
27 |
28 | > Iris データセット : csv フォーマット
29 | https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data
30 |
31 |
32 |
33 |
34 | ## コードの実行結果
35 |
36 |
37 |
38 | ## AdaLine によるアヤメデータの識別 : `main.py`
39 |
40 | - Iris データセットを使用
41 | - 特徴行列 `X_features` は、特徴数 2 個( Sepal Width, Petal length)× サンプル数 100 個 : `X_features = df_Iris.iloc[0:100, [0,2]].values`
42 | - サンプル数 100 個の内、品種 "setosa" が 50 個、"virginica" が 50 個。
43 | - 教師データ `y_labels` は、サンプル数 100 個 : `y_labels = df_Iris.iloc[0:100,4].values`
44 | - カテゴリーデータを -1 or 1 に変換 : `y_labels = numpy.where( y_labels == "Iris-setosa", -1, 1)`
45 | - 正規化処理を実施しないケースと実施したケースの双方で検証する。
46 | - 正規化処理 :
47 | `X_features_std = numpy.copy( X_features ) # ディープコピー`
48 | `X_features_std[:,0] = ( X_features[:,0] - X_features[:,0].mean() ) / X_features[:,0].std() `
49 | `X_features_std[:,1] = ( X_features[:,1] - X_features[:,1].mean() ) / X_features[:,1].std()`
50 | - 自作クラス `AdaLineGD` を用いて、学習データでの fitting 処理(重みベクトルの更新処理)を行う。 `AdaLineGD.fit( X_features, y_labels )`
51 |
52 |
53 |
54 | > アヤメデータをAdaLine&最急降下法(コスト関数)でのバッチ学習で識別結果。(重みの更新:Δw=η*∑( y-Φ(w^T*x) ) (j=1,2,...,m), コスト関数:J(w)= (1/2)*∑( y-Φ(w^T*x) )^2)
55 | 
56 |
57 |
58 |
59 | ---
60 |
61 |
62 |
63 | ## 背景理論
64 |
65 |
66 |
67 | ## ニューラルネットワークの概要
68 | 
69 | 
70 | 
71 |
72 |
73 |
74 | ## 活性化関数
75 | 
76 | 
77 |
78 |
79 |
80 | # 単純パーセプトロン
81 | 
82 |
83 |
84 |
85 | # パーセプトロンによる論理演算
86 | 
87 | 
88 |
89 |
90 |
91 | # 最急降下法による学習
92 | 
93 |
94 |
95 |
96 | ##### 最急降下法の単層パーセプトロンでの適用
97 | 
98 | 
99 |
100 |
101 |
102 | ##### 最急降下法の多層パーセプトロンでの適用
103 | 
104 | 
105 | 
106 |
--------------------------------------------------------------------------------
/AdaLineGD/img/twitter_AdaLine_1-2_170718.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineGD/img/twitter_AdaLine_1-2_170718.png
--------------------------------------------------------------------------------
/AdaLineGD/img/twitter_NN1_1_160825.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineGD/img/twitter_NN1_1_160825.png
--------------------------------------------------------------------------------
/AdaLineGD/img/twitter_NN1_2_160825.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineGD/img/twitter_NN1_2_160825.png
--------------------------------------------------------------------------------
/AdaLineGD/img/twitter_NN2-1_160826.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineGD/img/twitter_NN2-1_160826.png
--------------------------------------------------------------------------------
/AdaLineGD/img/twitter_NN2-2_160826.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineGD/img/twitter_NN2-2_160826.png
--------------------------------------------------------------------------------
/AdaLineGD/img/twitter_NN3'-1_160827.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineGD/img/twitter_NN3'-1_160827.png
--------------------------------------------------------------------------------
/AdaLineGD/img/twitter_NN4'-1_160829.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineGD/img/twitter_NN4'-1_160829.png
--------------------------------------------------------------------------------
/AdaLineGD/img/twitter_NN6-1_160829.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineGD/img/twitter_NN6-1_160829.png
--------------------------------------------------------------------------------
/AdaLineGD/img/twitter_NN6-2_160829.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineGD/img/twitter_NN6-2_160829.png
--------------------------------------------------------------------------------
/AdaLineGD/img/twitter_NN8-2''_160902.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineGD/img/twitter_NN8-2''_160902.png
--------------------------------------------------------------------------------
/AdaLineGD/img/twitter_NN8-3''_160902.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineGD/img/twitter_NN8-3''_160902.png
--------------------------------------------------------------------------------
/AdaLineSGD/AdalineSGD_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineSGD/AdalineSGD_1.png
--------------------------------------------------------------------------------
/AdaLineSGD/AdalineSGD_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineSGD/AdalineSGD_2.png
--------------------------------------------------------------------------------
/AdaLineSGD/AdalineSGD_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineSGD/AdalineSGD_3.png
--------------------------------------------------------------------------------
/AdaLineSGD/Plot2D.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import matplotlib.pyplot as plt
4 | import numpy
5 | from matplotlib.colors import ListedColormap
6 |
7 |
8 | class Plot2D(object):
9 | """
10 | description of class
11 | """
12 |
13 | def __init__( self ):
14 | self.mainTitle = ""
15 |
16 | def drawDiscriminantRegions( dat_X, dat_y, classifier, resolusion= 0.02 ):
17 | # 識別クラス数に対応したMAPの作成(最大5クラス対応)
18 | tuple_makers = ( "s","x","o","^","v" ) # タプル(定数リスト)
19 | tuple_colors = ( "red","blue","lightgreen", "gray", "cyan" ) # 塗りつぶす色を表すタプル(定数リスト)
20 | numClass = len( numpy.unique(dat_y) ) # numpy.unique() : 指定したarray変数の要素の重複をなくしたものを返す,更にlen() でユニークな値の数取得
21 | cmap = ListedColormap( tuple_colors[0:numClass] ) # plt.scatter() の引数で使用
22 |
23 | # plot the decision surface
24 | x1_min = dat_X[:, 0].min() - 1
25 | x1_max = dat_X[:, 0].max() + 1
26 | x2_min = dat_X[:, 1].min() - 1
27 | x2_max = dat_X[:, 1].max() + 1
28 |
29 | meshgrids = numpy.meshgrid( # マス目を作る ( 戻り値:numpy.ndarray )
30 | numpy.arange( x1_min, x1_max, resolusion ), # numpy.arang(): min~max by resolution
31 | numpy.arange( x2_min, x2_max, resolusion )
32 | )
33 | # 入力データ datX のx1軸、x2軸の値の全ての組み合わせ
34 | xx1 = meshgrids[0]
35 | xx2 = meshgrids[1]
36 |
37 | # ? 値の全ての組み合わせを1次元配列に変換 numpy.array( [xx1.ravel(), xx2.ravel()] ) し、
38 | # classifierに設定されている predict(予想)を実行
39 | Z = classifier.predict(
40 | numpy.array( [xx1.ravel(), xx2.ravel()] ).T
41 | )
42 | # ? 予測結果を元のグリッドポイントサイズに変換
43 | Z = Z.reshape( xx1.shape ) # numpy.ndarray の属性 shape は,各次元ごとの配列の大きさをまとめたタプルで指定
44 |
45 | # 等高線plotで識別領域を塗りつぶす
46 | plt.contourf( xx1, xx2, Z, alpha=0.4, cmap=cmap )
47 |
48 | # 図の軸の範囲指定
49 | plt.xlim( xx1.min(), xx1.max() )
50 | plt.ylim( xx2.min(), xx2.max() )
51 |
52 | # 識別クラス毎に、入力データ dat_X, dat_y の散布図 plot
53 | for (idx, cl) in enumerate( numpy.unique(dat_y) ): # enumerate():idx と共に clもloop
54 | plt.scatter(
55 | x = dat_X[dat_y == cl, 0],
56 | y = dat_X[dat_y == cl, 1],
57 | alpha = 0.8,
58 | c = cmap(idx),
59 | edgecolor = 'black',
60 | marker = tuple_makers[idx],
61 | label = cl
62 | )
63 |
--------------------------------------------------------------------------------
/AdaLineSGD/README.md:
--------------------------------------------------------------------------------
1 | ## AdaLineSGD(Adaptive Liner ニューロン確率的勾配降下法) [Adaptive Liner stomatic Gradient descent]
2 |
3 | 分かりやすいように main.py ファイル毎に1つの完結したコードにしています。
4 |
5 | ### 項目 [Contents]
6 |
7 | 1. [使用するライブラリ](#ID_1)
8 | 1. [使用するデータセット](#ID_2)
9 | 1. [コードの実行結果](#ID_3)
10 | 1. [AdaLineSGD によるアヤメデータの識別と、重みベクトルの更新処理 : `main.py`](#ID_3-1)
11 | 1. [背景理論](#ID_1)
12 | 1. [ニューラルネットワークの概要](#ID_4-1)
13 | 1. [活性化関数](#ID_4-2)
14 | 1. [単純パーセプトロン](#ID_4-3)
15 | 1. [パーセプトロンによる論理演算](#ID_4-4)
16 | 1. [最急降下法による学習](#ID_4-5)
17 |
18 |
19 |
20 |
21 | ### 使用するライブラリ
22 |
23 |
24 |
25 |
26 | ### 使用するデータセット
27 |
28 | > Iris データセット : csv フォーマット
29 | https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data
30 |
31 |
32 |
33 |
34 | ## コードの実行結果
35 |
36 |
37 |
38 | ## AdaLineSGD によるアヤメデータの識別と、重みベクトルの更新処理 : `main.py`
39 |
40 | - Iris データセットを使用
41 | - 特徴行列 `X_features` は、特徴数 2 個( Sepal Width, Petal length)× サンプル数 100 個 : `X_features = df_Iris.iloc[0:100, [0,2]].values`
42 | - サンプル数 100 個の内、品種 "setosa" が 50 個、"virginica" が 50 個。
43 | - 教師データ `y_labels` は、サンプル数 100 個 : `y_labels = df_Iris.iloc[0:100,4].values`
44 | - カテゴリーデータを -1 or 1 に変換 : `y_labels = numpy.where( y_labels == "Iris-setosa", -1, 1)`
45 | - 正規化処理を実施する。
46 | - 正規化処理 :
47 | `X_features_std = numpy.copy( X_features ) # ディープコピー`
48 | `X_features_std[:,0] = ( X_features[:,0] - X_features[:,0].mean() ) / X_features[:,0].std() `
49 | `X_features_std[:,1] = ( X_features[:,1] - X_features[:,1].mean() ) / X_features[:,1].std()`
50 | - 自作クラス `AdaLineSGD` を用いて、学習データでの fitting 処理(重みベクトルの更新処理)を行う。 `AdaLineSGD.fit( X_features, y_labels )`
51 | - 自作クラス `AdaLineSGD` の `online_fit()` 関数を用いて、"擬似的な"ストリーミングデータで、"擬似的な"オンライン学習する。
52 | ```
53 | # ストリーミングデータ (5 ~ 10) でオンライン学習
54 | for smIndex in range(5,100):
55 | print(smIndex)
56 | ada2.online_fit(
57 | X_train = X_features_std[0:smIndex, :],
58 | y_train = y_labels[0:smIndex]
59 | )
60 | ```
61 |
62 |
63 |
64 | > アヤメデータをAdaLine&確率的最急降下法(コスト関数)、及びオンライン学習で識別結果。(重みの更新:Δw=η*( y_i - Φ(w^T*x_i) ), J=(1/2)*( y_i - Φ(w^T*x_i) )^2, i:ランダム)
65 | 
66 |
67 |
68 |
69 | ---
70 |
71 |
72 |
73 | ## 背景理論
74 |
75 |
76 |
77 | ## ニューラルネットワークの概要
78 | 
79 | 
80 | 
81 |
82 |
83 |
84 | ## 活性化関数
85 | 
86 | 
87 |
88 |
89 |
90 | # 単純パーセプトロン
91 | 
92 |
93 |
94 |
95 | # パーセプトロンによる論理演算
96 | 
97 | 
98 |
99 |
100 |
101 | # 最急降下法による学習
102 | 
103 |
104 |
105 |
106 | ##### 最急降下法の単層パーセプトロンでの適用
107 | 
108 | 
109 |
110 |
111 |
112 | ##### 最急降下法の多層パーセプトロンでの適用
113 | 
114 | 
115 | 
--------------------------------------------------------------------------------
/AdaLineSGD/img/twitter_AdaLine_1-2_170718.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineSGD/img/twitter_AdaLine_1-2_170718.png
--------------------------------------------------------------------------------
/AdaLineSGD/img/twitter_AdaLine_2-2_170719.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineSGD/img/twitter_AdaLine_2-2_170719.png
--------------------------------------------------------------------------------
/AdaLineSGD/img/twitter_NN1_1_160825.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineSGD/img/twitter_NN1_1_160825.png
--------------------------------------------------------------------------------
/AdaLineSGD/img/twitter_NN1_2_160825.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineSGD/img/twitter_NN1_2_160825.png
--------------------------------------------------------------------------------
/AdaLineSGD/img/twitter_NN2-1_160826.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineSGD/img/twitter_NN2-1_160826.png
--------------------------------------------------------------------------------
/AdaLineSGD/img/twitter_NN2-2_160826.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineSGD/img/twitter_NN2-2_160826.png
--------------------------------------------------------------------------------
/AdaLineSGD/img/twitter_NN3'-1_160827.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineSGD/img/twitter_NN3'-1_160827.png
--------------------------------------------------------------------------------
/AdaLineSGD/img/twitter_NN4'-1_160829.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineSGD/img/twitter_NN4'-1_160829.png
--------------------------------------------------------------------------------
/AdaLineSGD/img/twitter_NN6-1_160829.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineSGD/img/twitter_NN6-1_160829.png
--------------------------------------------------------------------------------
/AdaLineSGD/img/twitter_NN6-2_160829.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineSGD/img/twitter_NN6-2_160829.png
--------------------------------------------------------------------------------
/AdaLineSGD/img/twitter_NN8-2''_160902.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineSGD/img/twitter_NN8-2''_160902.png
--------------------------------------------------------------------------------
/AdaLineSGD/img/twitter_NN8-3''_160902.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/AdaLineSGD/img/twitter_NN8-3''_160902.png
--------------------------------------------------------------------------------
/ClusteringAnalysis_scikit-learn/ClutterringAnalysis_scikit-learn_1-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/ClusteringAnalysis_scikit-learn/ClutterringAnalysis_scikit-learn_1-1.png
--------------------------------------------------------------------------------
/ClusteringAnalysis_scikit-learn/ClutterringAnalysis_scikit-learn_1-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/ClusteringAnalysis_scikit-learn/ClutterringAnalysis_scikit-learn_1-2.png
--------------------------------------------------------------------------------
/ClusteringAnalysis_scikit-learn/ClutterringAnalysis_scikit-learn_1-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/ClusteringAnalysis_scikit-learn/ClutterringAnalysis_scikit-learn_1-3.png
--------------------------------------------------------------------------------
/ClusteringAnalysis_scikit-learn/ClutterringAnalysis_scikit-learn_2-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/ClusteringAnalysis_scikit-learn/ClutterringAnalysis_scikit-learn_2-1.png
--------------------------------------------------------------------------------
/ClusteringAnalysis_scikit-learn/README.md:
--------------------------------------------------------------------------------
1 | ## クラスター分析 [Clustering Analysis]
2 |
3 | ### 項目 [Contents]
4 |
5 | 1. [使用するライブラリ](#使用するライブラリ)
6 | 1. [使用するデータセット](#使用するデータセット)
7 | 1. [コードの実行結果](#コードの実行結果)
8 | 1. [k-mean 法によるクラスタリング](#クラスタリング)
9 | 1. [エルボー法を用いた最適なクラスター数](#エルボー法を用いた最適なクラスター数)
10 | 1. [シルエット図を用いたクラスタリング性能の数値化](#シルエット図を用いたクラスタリング性能の数値化)
11 | 1. [背景理論](#背景理論)
12 | 1. [ベクトル量子化](#ベクトル量子化)
13 | 1. [k-mean 法](#k-mean法)
14 | 1. [学習ベクトル量子化](#学習ベクトル量子化)
15 | 1. [ウォード法](#ウォード法)
16 | 1. [EMアルゴリズム](#EMアルゴリズム)
17 |
18 |
19 |
20 |
21 |
22 | ### 使用するライブラリ:
23 |
24 | > scikit-learn ライブラリ
25 | >> データセット Dataset loading utilities : `sklearn.datasets`
26 | >> http://scikit-learn.org/stable/datasets/index.html
27 | >>> ガウス分布に従った各クラスター生成 : `sklearn.datasets.make_blobs()` :
28 | http://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_blobs.html#sklearn.datasets.make_blobs
29 |
30 | >> クラスタリング : `sklearn.cluster`
31 | http://scikit-learn.org/stable/modules/clustering.html#clustering
32 | >>> k-means 法 : `sklearn.cluster.KMeans`
33 | http://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html
34 |
35 | > その他ライブラリ
36 | >>
37 |
38 |
39 |
40 |
41 |
42 | ### 使用するデータセット
43 |
44 | > ガウス分布に従った各クラスター生成 : `sklearn.datasets.make_blobs()`
45 |
46 |
47 |
48 |
49 |
50 | ## コードの実行結果
51 |
52 |
53 |
54 | ## k-mean 法によるクラスタリング : `main1.py`
55 |
56 | ### ① ガウス分布に従った各クラスターの散布図
57 |
58 | - ガウス分布に従った各クラスターを `sklearn.datasets.make_blobs()` 関数を使用して生成
59 | - クラスター数 5 個 : `centers = 5`
60 | - 各クラスターのサンプル数 100 個(合計 500 個) `n_samples = 500`
61 | - 特徴量 2 個 : `n_features = 2`
62 |
63 | > ガウス分布に従った各クラスターの散布図
64 | 
65 |
66 |
67 | ### ② k-means法でのセントロイドと各クラスターの散布図
68 |
69 | - k-meas 法として `sklearn.cluster.KMeans` クラスを使用
70 | - クラスター数 5 個 : `n_clusters = 5`
71 | - クラスターの個数(5個)の都度、異なるランダムな初期値を使用して, k-means 法によるクラスタリングを 10 回行う : `n_init = 10`
72 | - 1回の k-means 法の最大イテレーション回数 300 回 : `max_iter = 300`
73 | - k-means 法において、収束と判定する為の相対的な許容誤差値 0.0001 : `tol = 1e-04`
74 | - fitting 処理 `sklearn.cluster.KMeans.fit()` する特徴行列 `X_features` は、
75 | - 各クラスターのサンプル数 100 個(合計 500 個) `X_features[0:500,:]`
76 | - 特徴量 2 個 : `X_features[:,0], X_features[:,1]`
77 |
78 |
79 |
80 | > k-means 法でのセントロイドと各クラスターの散布図
81 | >> セントロイドをまとめて描写した散布図
82 | 
83 |
84 | >> セントロイドを個別に描写した散布図
85 | 
86 |
87 |
88 |
89 |
90 |
91 | ## エルボー法を用いた、最適なクラスター数 : `main2.py`
92 |
93 | |クラスター数|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|
94 | |---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
95 | |Distortion (SSE)小数点以下切り捨て|13693|3694|1535|676|**238**値が急速に低下(エルボー)|218|201|185|168|153|141|129|120|110|
96 |
97 | > kmeans ++ 法による、クラスター数と SSE 値の関係図(エルボー法)。図より、クラスター数が、5 個のときみエルボー(肘)部分となっており、最適なクラスター数は 5 個であることが分かる。
98 | 
99 |
100 |
101 |
102 |
103 |
104 |
105 | ## シルエット図を用いた、クラスタリング性能の数値化 : `main3.py`
106 |
107 | > コード実装中...
108 |
109 |
110 |
111 | ---
112 |
113 |
114 |
115 | ## 背景理論
116 |
117 |
118 |
119 | ## ベクトル量子化
120 |
121 | 
122 |
123 |
124 |
125 | ## k-mean 法
126 |
127 | 
128 |
129 |
130 |
131 | ## 学習ベクトル量子化 [LQV]
132 |
133 | 
134 |
135 |
136 |
137 | ## ウォード法
138 |
139 |
140 |
141 | ## EM アルゴリズム
142 |
143 | 
144 | 
145 | 
146 | 
147 | 
148 |
--------------------------------------------------------------------------------
/ClusteringAnalysis_scikit-learn/img/twitter_情報理論_情報と確率_9-3_170623.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/ClusteringAnalysis_scikit-learn/img/twitter_情報理論_情報と確率_9-3_170623.png
--------------------------------------------------------------------------------
/ClusteringAnalysis_scikit-learn/img/twitter_情報理論_情報と確率_9-4_170623.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/ClusteringAnalysis_scikit-learn/img/twitter_情報理論_情報と確率_9-4_170623.png
--------------------------------------------------------------------------------
/ClusteringAnalysis_scikit-learn/img/twitter_情報理論_情報と確率_9-5_170623.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/ClusteringAnalysis_scikit-learn/img/twitter_情報理論_情報と確率_9-5_170623.png
--------------------------------------------------------------------------------
/ClusteringAnalysis_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-10_170701.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/ClusteringAnalysis_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-10_170701.png
--------------------------------------------------------------------------------
/ClusteringAnalysis_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-6_170701.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/ClusteringAnalysis_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-6_170701.png
--------------------------------------------------------------------------------
/ClusteringAnalysis_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-7'_170701.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/ClusteringAnalysis_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-7'_170701.png
--------------------------------------------------------------------------------
/ClusteringAnalysis_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-8_170701.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/ClusteringAnalysis_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-8_170701.png
--------------------------------------------------------------------------------
/ClusteringAnalysis_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-9_170701.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/ClusteringAnalysis_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-9_170701.png
--------------------------------------------------------------------------------
/ClusteringAnalysis_scikit-learn/main1.py:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 | # Anaconda 4.3.0 環境
3 |
4 | import numpy
5 | import pandas
6 | import matplotlib.pyplot as plt
7 |
8 | # scikit-learn ライブラリ関連
9 | from sklearn import datasets
10 | from sklearn.datasets import make_blobs # クラスタリングのためのガウス分布を生成
11 |
12 | from sklearn.cluster import KMeans #
13 |
14 | # 自作クラス
15 | from EnsembleModelClassifier import EnsembleModelClassifier
16 | from MLPreProcess import MLPreProcess
17 | from MLPlot import MLPlot
18 |
19 | def main():
20 | """
21 | クラスター分析.
22 | k-mean 法によるクラスタリング
23 | """
24 | print("Enter main()")
25 |
26 | #---------------------------------------------------------------
27 | # データの読み込み
28 | #---------------------------------------------------------------
29 | # make_blobs() 関数でクラスタリングのためのガウス分布を生成
30 | X_features, y_labels = make_blobs(
31 | n_samples = 500, # サンプル数
32 | n_features = 2, # 特徴数
33 | centers = 5, # クラスターの個数
34 | cluster_std = 0.5, # クラスター内での標準偏差
35 | shuffle = True, # サンプルをシャッフルするか否か
36 | random_state = 0 # 乱数生成器の状態 ( If int, random_state is the seed used by the random number generator )
37 | )
38 |
39 | #print( "X_features : \n", X_features )
40 | #print( "y_labels : \n", y_labels )
41 |
42 | # k-means
43 | kmeans = KMeans(
44 | n_clusters = 5, # cluster の個数(= centroid の個数)
45 | init = 'random', # centroid の初期値をランダムに設定
46 | n_init = 10, # 異なるセントロイドの seed を使用した, k-means アルゴリズムの実行回数
47 | # cluster の個数の都度, 異なるランダムな初期値を使用して, k-means 法によるクラスタリングを 10 回行う.
48 | # The final results will be the best output of n_init consecutive runs in terms of inertia.
49 | max_iter = 300, # 1回の k-means アルゴリズム内部の最大イテレーション回数
50 | tol = 1e-04, # 収束と判定する為の相対的な許容誤差値
51 | random_state = 0, # セントロイドの初期化に用いる乱数生成器の状態
52 | n_jobs = 1 # CPU の並列処理数
53 | )
54 |
55 | # 指定した特徴行列 X_features のクラスターのセントロイドの計算&各サンプルのインデックスを予想して返す.
56 | y_kmeans = kmeans.fit_predict( X_features )
57 |
58 | print( "kmeans.cluster_centers_ :\n", kmeans.cluster_centers_ )
59 | print( "kmeans.labels_ :\n", kmeans.labels_ )
60 | print( "y_kmeans :\n", y_kmeans )
61 |
62 | #---------------------------------------------------------------
63 | # クラスター図の描写
64 | #---------------------------------------------------------------
65 | # clusters の散布図を plot
66 | MLPlot.drawClustersScatter( X_features, y_labels )
67 |
68 | MLPlot.saveFigure( fileName = 'ClutterringAnalysis_scikit-learn_1-1.png' )
69 | plt.show()
70 |
71 | # k-means の結果を plot
72 | # セントロイドをまとめて plot
73 | MLPlot.drawClustersAndCentroidsScatter(
74 | X_features, y_labels,
75 | X_cluster_centors = kmeans.cluster_centers_,
76 | drawCentroidsIndividually = False
77 | )
78 |
79 | MLPlot.saveFigure( fileName = 'ClutterringAnalysis_scikit-learn_1-2.png' )
80 | plt.show()
81 |
82 | # セントロイドを個別に plot
83 | MLPlot.drawClustersAndCentroidsScatter(
84 | X_features, y_labels,
85 | X_cluster_centors = kmeans.cluster_centers_,
86 | drawCentroidsIndividually = True,
87 | cluster_centroid_map = [ 2, 0, 4, 1, 3 ]
88 | )
89 |
90 | MLPlot.saveFigure( fileName = 'ClutterringAnalysis_scikit-learn_1-3.png' )
91 | plt.show()
92 |
93 |
94 | print("Finish main()")
95 | return
96 |
97 | if __name__ == '__main__':
98 | main()
--------------------------------------------------------------------------------
/ClusteringAnalysis_scikit-learn/main2.py:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 | # Anaconda 4.3.0 環境
3 |
4 | import numpy
5 | import pandas
6 | import matplotlib.pyplot as plt
7 |
8 | # scikit-learn ライブラリ関連
9 | from sklearn import datasets
10 | from sklearn.datasets import make_blobs # クラスタリングのためのガウス分布を生成
11 |
12 | from sklearn.cluster import KMeans #
13 |
14 |
15 | # 自作クラス
16 | from EnsembleModelClassifier import EnsembleModelClassifier
17 | from MLPreProcess import MLPreProcess
18 | from MLPlot import MLPlot
19 |
20 | def main():
21 | """
22 | クラスター分析.
23 | k-mean 法とエルボー法を用いた最適なクラスター数
24 | """
25 | print("Enter main()")
26 |
27 | #---------------------------------------------------------------
28 | # データの読み込み
29 | #---------------------------------------------------------------
30 | # make_blobs() 関数でクラスタリングのためのガウス分布を生成
31 | X_features, y_labels = make_blobs(
32 | n_samples = 500, # サンプル数
33 | n_features = 2, # 特徴数
34 | centers = 5, # クラスターの個数
35 | cluster_std = 0.5, # クラスター内での標準偏差
36 | shuffle = True, # サンプルをシャッフルするか否か
37 | random_state = 0 # 乱数生成器の状態 ( If int, random_state is the seed used by the random number generator )
38 | )
39 |
40 | #print( "X_features : \n", X_features )
41 | #print( "y_labels : \n", y_labels )
42 |
43 | # k-means
44 | kmeans = KMeans(
45 | n_clusters = 5, # cluster の個数(= centroid の個数)
46 | init = 'random', # centroid の初期値をランダムに設定
47 | n_init = 10, # ? 異なるセントロイドの seed を使用した, k-means アルゴリズムの実行回数
48 | # cluster の個数の都度, 異なるランダムな初期値を使用して, k-means 法によるクラスタリングを 10 回行う.
49 | # The final results will be the best output of n_init consecutive runs in terms of inertia.
50 | max_iter = 300, # 1回の k-means アルゴリズム内部の最大イテレーション回数
51 | tol = 1e-04, # 収束と判定する為の相対的な許容誤差値
52 | random_state = 0, # セントロイドの初期化に用いる乱数生成器の状態
53 | n_jobs = 1 # CPU の並列処理数
54 | )
55 |
56 | # 指定した特徴行列 X_features のクラスターのセントロイドの計算&各サンプルのインデックスを予想して返す.
57 | y_kmeans = kmeans.fit_predict( X_features )
58 |
59 | print( "kmeans.cluster_centers_ :\n", kmeans.cluster_centers_ )
60 | print( "kmeans.labels_ :\n", kmeans.labels_ )
61 | print( "y_kmeans :\n", y_kmeans )
62 | print( "Distortion (SSE) : %.2f" % kmeans.inertia_)
63 |
64 | #---------------------------------------------------------------
65 | # エルボー図の描写
66 | #---------------------------------------------------------------
67 | n_max_clusters = 15 # 確認するクラスター数の最大数
68 | distortions = [] # SSE
69 |
70 | # クラスター数 1 ~ n_max_clusters でループ
71 | for idx in range(1, n_max_clusters):
72 | kmeans_pp = KMeans(
73 | n_clusters = idx, # cluster の個数(= centroid の個数)
74 | init = 'k-means++', # k-means++ 法を使用
75 | n_init = 10, # 異なるセントロイドの seed を使用した, k-means アルゴリズムの実行回数
76 | # cluster の個数の都度, 異なるランダムな初期値を使用して, k-means 法によるクラスタリングを 10 回行う.
77 | max_iter = 300, # 1 回の k-means アルゴリズム内部の最大イテレーション回数
78 | random_state = 0 # 最適なクラスタ数を調べたいので, 乱数化しない
79 | )
80 |
81 | kmeans_pp.fit( X_features ) # 特徴行列で fitting
82 | distortions.append( kmeans_pp.inertia_ ) # SSE のリストの最後尾に追加
83 | print( kmeans_pp.inertia_ )
84 |
85 | # distortions [SSE] のリストを描写
86 | plt.plot(
87 | range(1, n_max_clusters), distortions,
88 | marker = 'o'
89 | )
90 |
91 | plt.title( "elbow method" )
92 | plt.xlabel( "Number of clusters" )
93 | plt.ylabel( "Distortion [SSE]" )
94 | plt.tight_layout()
95 |
96 | MLPlot.saveFigure( fileName = 'ClutterringAnalysis_scikit-learn_2-1.png' )
97 | plt.show()
98 |
99 | print("Finish main()")
100 | return
101 |
102 | if __name__ == '__main__':
103 | main()
--------------------------------------------------------------------------------
/DataPreProcess_scikit-learn/DataPreProcess_scikit-learn_1'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DataPreProcess_scikit-learn/DataPreProcess_scikit-learn_1'.png
--------------------------------------------------------------------------------
/DataPreProcess_scikit-learn/DataPreProcess_scikit-learn_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DataPreProcess_scikit-learn/DataPreProcess_scikit-learn_1.png
--------------------------------------------------------------------------------
/DataPreProcess_scikit-learn/img/twitter_機械学習_3-1_160924.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DataPreProcess_scikit-learn/img/twitter_機械学習_3-1_160924.png
--------------------------------------------------------------------------------
/DataPreProcess_scikit-learn/img/twitter_機械学習_3-2_160924.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DataPreProcess_scikit-learn/img/twitter_機械学習_3-2_160924.png
--------------------------------------------------------------------------------
/DataPreProcess_scikit-learn/img/twitter_機械学習_3-3_160924.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DataPreProcess_scikit-learn/img/twitter_機械学習_3-3_160924.png
--------------------------------------------------------------------------------
/DataPreProcess_scikit-learn/img/twitter_機械学習_3-4_170727.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DataPreProcess_scikit-learn/img/twitter_機械学習_3-4_170727.png
--------------------------------------------------------------------------------
/DataPreProcess_scikit-learn/img/twitter_機械学習_3-5_170810.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DataPreProcess_scikit-learn/img/twitter_機械学習_3-5_170810.png
--------------------------------------------------------------------------------
/DataPreProcess_scikit-learn/img/twitter_機械学習_3-6_170810.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DataPreProcess_scikit-learn/img/twitter_機械学習_3-6_170810.png
--------------------------------------------------------------------------------
/DataPreProcess_scikit-learn/img/twitter_機械学習_3-7_170810.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DataPreProcess_scikit-learn/img/twitter_機械学習_3-7_170810.png
--------------------------------------------------------------------------------
/DataPreProcess_scikit-learn/img/twitter_機械学習_3-8_170810.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DataPreProcess_scikit-learn/img/twitter_機械学習_3-8_170810.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/DecisionTree.py:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 | # Anaconda 4.3.0 環境
3 |
4 | import numpy
5 | import matplotlib.pyplot as plt
6 |
7 | from sklearn.tree import DecisionTreeClassifier
8 |
9 | from sklearn.tree import export_graphviz
10 | #import pydotplus
11 | #from IPython.display import Image
12 | #from IPython.display import display
13 |
14 |
15 | class DecisionTree(object):
16 | """
17 | 決定木 [DecisionTree] を表すクラス
18 | scikit-learn ライブラリの sklearn.tree モジュールにある DecisionTreeClassifier クラスのラッパークラス
19 |
20 | [public]
21 | tree_ : DecisionTreeClassifier クラスのオブジェクト
22 | """
23 | def __init__( self, purity = 'gini', max_depth = 3, random_state = 0 ):
24 | self.tree_ = DecisionTreeClassifier(
25 | criterion = purity,
26 | max_depth = max_depth,
27 | random_state = random_state
28 | )
29 |
30 | return
31 |
32 | @staticmethod
33 | def clacNodeError( p ):
34 | """
35 | ノードの誤り率を計算する.
36 | [Input]
37 | p : float
38 | 確率値(0~1)
39 | [Output]
40 | 入力 p に対する計算結果
41 | """
42 | value = 1 - numpy.max( [p, 1-p] )
43 | return value
44 |
45 | @staticmethod
46 | def clacGineIndex( p ):
47 | value = p * (1 - p) + (1 - p) * ( 1 - (1 - p) )
48 | return value
49 |
50 | @staticmethod
51 | def calcCrossEntropy( p ):
52 | # 2クラスのバイナリーなのでlog の底が 2
53 | value = - p * numpy.log2(p) - (1 - p) * numpy.log2( (1 - p) )
54 |
55 | return value
56 |
57 |
58 | def plotNodeErrorFunction( self, figure, axis, x = numpy.arange( 0.0, 1.0, 0.01 ) ):
59 | """
60 | ノードの誤り率を表す関数を描写
61 | [Input]
62 | figure : Figure クラスのオブジェクト
63 | plt.figure() で作成されるオブジェクト
64 | axis : Axis クラスのオブジェクト
65 | figure.subplot() で作成されるオブジェクト
66 | x : darry
67 | 確率の値 0~1 からなる配列(x軸の値に相当)
68 | """
69 | # 配列 x の値を元にノードの誤り率を計算し, errors リストに格納
70 | errors = []
71 | for p in x:
72 | error = self.clacNodeError( p )
73 | errors.append( error )
74 |
75 | # 図の作図
76 | axis.plot(
77 | x, errors,
78 | label = "Misclassification Error",
79 | linestyle = "-.",
80 | lw = 2,
81 | color = "cyan"
82 | )
83 |
84 | #
85 | axis.axvline( x = 0.5, linewidth = 0.5, color = 'k', linestyle = '--' )
86 | axis.axhline( y = 0.5, linewidth = 0.5, color = 'k', linestyle = '--' )
87 | axis.axhline( y = 1.0, linewidth = 0.5, color = 'k', linestyle = '--' )
88 |
89 | plt.ylim( [0, 1.1] )
90 | plt.xlabel( "p (i=1)" )
91 | plt.ylabel( "green" )
92 |
93 | return
94 |
95 | def plotCrossEntropyFunction( self, figure, axis, x = numpy.arange( 0.0, 1.0, 0.01 ) ):
96 | # 配列 x の値を元にノードの交差エントロピーを計算し, リストに格納
97 | ents = []
98 | for p in x:
99 | if ( p == 0.01 ):
100 | ents.append( None )
101 | else:
102 | ent = self.calcCrossEntropy( p )
103 | #print("p,ent", p, ent)
104 | ents.append( ent )
105 |
106 | # 図の作図
107 | axis.plot(
108 | x, ents,
109 | label = "Cross Entropy",
110 | linestyle = "--",
111 | lw = 2,
112 | color = "blue"
113 | )
114 |
115 | #
116 | axis.axvline( x = 0.5, linewidth = 0.5, color = 'k', linestyle = '--' )
117 | axis.axhline( y = 0.5, linewidth = 0.5, color = 'k', linestyle = '--' )
118 | axis.axhline( y = 1.0, linewidth = 0.5, color = 'k', linestyle = '--' )
119 |
120 | plt.ylim( [0, 1.1] )
121 | plt.xlabel( "p (i=1)" )
122 | plt.ylabel( "Purity" )
123 |
124 | return
125 |
126 | def plotGiniIndexFunction( self, figure, axis, x = numpy.arange( 0.0, 1.0, 0.01 ) ):
127 | # 配列 x の値を元にジニ係数を計算し, リストに格納
128 | gines = []
129 | for p in x:
130 | gine = self.clacGineIndex( p )
131 | gines.append( gine )
132 |
133 | # 図の作図
134 | axis.plot(
135 | x, gines,
136 | label = "Gini Index",
137 | linestyle = "-",
138 | lw = 2,
139 | color = "red"
140 | )
141 |
142 | #
143 | axis.axvline( x = 0.5, linewidth = 0.5, color = 'k', linestyle = '--' )
144 | axis.axhline( y = 0.5, linewidth = 0.5, color = 'k', linestyle = '--' )
145 | axis.axhline( y = 1.0, linewidth = 0.5, color = 'k', linestyle = '--' )
146 |
147 | plt.ylim( [0, 1.1] )
148 | plt.xlabel( "p (i=1)" )
149 | plt.ylabel( "Purity" )
150 |
151 | return
152 |
153 | def exportDecisionTreeDotFile( self, fileName = "DecisionTree.dot", feature_names = ["feature1","feature2"] ):
154 |
155 | # dot ファイルを出力
156 | # 出力した dot ファイルは、GraphViz で dot -Tpng DecisionTree.dot -o DecisionTreeGraph.png で png ファイル化できる.
157 | export_graphviz(
158 | self.tree_,
159 | out_file = fileName,
160 | feature_names = feature_names
161 | )
162 |
163 | return
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/DecisionTree1.dot:
--------------------------------------------------------------------------------
1 | digraph Tree {
2 | node [shape=box] ;
3 | 0 [label="petal width <= -0.6129\ngini = 0.6643\nsamples = 105\nvalue = [34, 32, 39]"] ;
4 | 1 [label="gini = 0.0\nsamples = 34\nvalue = [34, 0, 0]"] ;
5 | 0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ;
6 | 2 [label="petal length <= 0.6244\ngini = 0.4951\nsamples = 71\nvalue = [0, 32, 39]"] ;
7 | 0 -> 2 [labeldistance=2.5, labelangle=-45, headlabel="False"] ;
8 | 3 [label="gini = 0.1609\nsamples = 34\nvalue = [0, 31, 3]"] ;
9 | 2 -> 3 ;
10 | 4 [label="gini = 0.0526\nsamples = 37\nvalue = [0, 1, 36]"] ;
11 | 2 -> 4 ;
12 | }
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/DecisionTree2.dot:
--------------------------------------------------------------------------------
1 | digraph Tree {
2 | node [shape=box] ;
3 | 0 [label="petal width <= -0.6129\ngini = 0.6643\nsamples = 105\nvalue = [34, 32, 39]"] ;
4 | 1 [label="gini = 0.0\nsamples = 34\nvalue = [34, 0, 0]"] ;
5 | 0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ;
6 | 2 [label="petal length <= 0.6244\ngini = 0.4951\nsamples = 71\nvalue = [0, 32, 39]"] ;
7 | 0 -> 2 [labeldistance=2.5, labelangle=-45, headlabel="False"] ;
8 | 3 [label="petal width <= 0.5443\ngini = 0.1609\nsamples = 34\nvalue = [0, 31, 3]"] ;
9 | 2 -> 3 ;
10 | 4 [label="gini = 0.0\nsamples = 30\nvalue = [0, 30, 0]"] ;
11 | 3 -> 4 ;
12 | 5 [label="gini = 0.375\nsamples = 4\nvalue = [0, 1, 3]"] ;
13 | 3 -> 5 ;
14 | 6 [label="petal length <= 0.6801\ngini = 0.0526\nsamples = 37\nvalue = [0, 1, 36]"] ;
15 | 2 -> 6 ;
16 | 7 [label="gini = 0.375\nsamples = 4\nvalue = [0, 1, 3]"] ;
17 | 6 -> 7 ;
18 | 8 [label="gini = 0.0\nsamples = 33\nvalue = [0, 0, 33]"] ;
19 | 6 -> 8 ;
20 | }
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/DecisionTree3.dot:
--------------------------------------------------------------------------------
1 | digraph Tree {
2 | node [shape=box] ;
3 | 0 [label="petal width <= -0.6129\ngini = 0.6643\nsamples = 105\nvalue = [34, 32, 39]"] ;
4 | 1 [label="gini = 0.0\nsamples = 34\nvalue = [34, 0, 0]"] ;
5 | 0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ;
6 | 2 [label="petal length <= 0.6244\ngini = 0.4951\nsamples = 71\nvalue = [0, 32, 39]"] ;
7 | 0 -> 2 [labeldistance=2.5, labelangle=-45, headlabel="False"] ;
8 | 3 [label="petal width <= 0.5443\ngini = 0.1609\nsamples = 34\nvalue = [0, 31, 3]"] ;
9 | 2 -> 3 ;
10 | 4 [label="gini = 0.0\nsamples = 30\nvalue = [0, 30, 0]"] ;
11 | 3 -> 4 ;
12 | 5 [label="petal length <= 0.4574\ngini = 0.375\nsamples = 4\nvalue = [0, 1, 3]"] ;
13 | 3 -> 5 ;
14 | 6 [label="gini = 0.0\nsamples = 1\nvalue = [0, 0, 1]"] ;
15 | 5 -> 6 ;
16 | 7 [label="petal length <= 0.5687\ngini = 0.4444\nsamples = 3\nvalue = [0, 1, 2]"] ;
17 | 5 -> 7 ;
18 | 8 [label="gini = 0.5\nsamples = 2\nvalue = [0, 1, 1]"] ;
19 | 7 -> 8 ;
20 | 9 [label="gini = 0.0\nsamples = 1\nvalue = [0, 0, 1]"] ;
21 | 7 -> 9 ;
22 | 10 [label="petal width <= 0.6729\ngini = 0.0526\nsamples = 37\nvalue = [0, 1, 36]"] ;
23 | 2 -> 10 ;
24 | 11 [label="petal width <= 0.5443\ngini = 0.375\nsamples = 4\nvalue = [0, 1, 3]"] ;
25 | 10 -> 11 ;
26 | 12 [label="gini = 0.0\nsamples = 3\nvalue = [0, 0, 3]"] ;
27 | 11 -> 12 ;
28 | 13 [label="gini = 0.0\nsamples = 1\nvalue = [0, 1, 0]"] ;
29 | 11 -> 13 ;
30 | 14 [label="gini = 0.0\nsamples = 33\nvalue = [0, 0, 33]"] ;
31 | 10 -> 14 ;
32 | }
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/DecisionTree_Graph1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DecisionTree_scikit-learn/DecisionTree_Graph1.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/DecisionTree_Graph2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DecisionTree_scikit-learn/DecisionTree_Graph2.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/DecisionTree_Graph3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DecisionTree_scikit-learn/DecisionTree_Graph3.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/DecisionTree_scikit-learn_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DecisionTree_scikit-learn/DecisionTree_scikit-learn_1.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/DecisionTree_scikit-learn_2'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DecisionTree_scikit-learn/DecisionTree_scikit-learn_2'.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/DecisionTree_scikit-learn_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DecisionTree_scikit-learn/DecisionTree_scikit-learn_2.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/DecisionTree_scikit-learn_3'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DecisionTree_scikit-learn/DecisionTree_scikit-learn_3'.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/DecisionTree_scikit-learn_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DecisionTree_scikit-learn/DecisionTree_scikit-learn_3.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/img/twitter_パターン認識21-12_170802.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DecisionTree_scikit-learn/img/twitter_パターン認識21-12_170802.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/img/twitter_パターン認識21-13_170802.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DecisionTree_scikit-learn/img/twitter_パターン認識21-13_170802.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/img/twitter_パターン認識21-14_170802.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DecisionTree_scikit-learn/img/twitter_パターン認識21-14_170802.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/img/twitter_パターン認識21-15_170802.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DecisionTree_scikit-learn/img/twitter_パターン認識21-15_170802.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/img/twitter_パターン認識21-1_170730.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DecisionTree_scikit-learn/img/twitter_パターン認識21-1_170730.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/img/twitter_パターン認識21-2_170730.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DecisionTree_scikit-learn/img/twitter_パターン認識21-2_170730.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/img/twitter_パターン認識21-3_170731.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DecisionTree_scikit-learn/img/twitter_パターン認識21-3_170731.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/img/twitter_パターン認識21-5_170731.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DecisionTree_scikit-learn/img/twitter_パターン認識21-5_170731.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/img/twitter_パターン認識21-6_170731.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DecisionTree_scikit-learn/img/twitter_パターン認識21-6_170731.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/img/twitter_パターン認識21-7_170731.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/DecisionTree_scikit-learn/img/twitter_パターン認識21-7_170731.png
--------------------------------------------------------------------------------
/DecisionTree_scikit-learn/main1.py:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 | # Anaconda 4.3.0 環境
3 |
4 | import numpy
5 | import matplotlib.pyplot as plt
6 |
7 | # scikit-learn ライブラリ関連
8 | from sklearn import datasets #
9 | #from sklearn.cross_validation import train_test_split # scikit-learn の train_test_split関数の old-version
10 | from sklearn.model_selection import train_test_split # scikit-learn の train_test_split関数の new-version
11 | from sklearn.preprocessing import StandardScaler # scikit-learn の preprocessing モジュールの StandardScaler クラス
12 | from sklearn.metrics import accuracy_score #
13 |
14 | # 自作クラス
15 | from MLPlot import MLPlot # 機械学習用の図の描写をサポートする関数群からなるクラス
16 | import DecisionTree
17 |
18 | def main():
19 | print("Enter main()")
20 | #==========================================================================================
21 | # 決定木 [DecisionTree] の不純度 [purity] を表す関数の作図
22 | # ノードの誤り率 [eror rate], 交差エントロピー関数 [cross-entropy], ジニ係数 [Gini index]
23 | #==========================================================================================
24 | tree = DecisionTree.DecisionTree()
25 |
26 | #-------------------------------
27 | # 不純度を表す関数群の plot
28 | #-------------------------------
29 | figure = plt.figure()
30 | axis = plt.subplot(1,1,1)
31 | plt.grid(linestyle='-')
32 |
33 | tree.plotNodeErrorFunction( figure, axis )
34 | tree.plotCrossEntropyFunction( figure, axis )
35 | tree.plotGiniIndexFunction( figure, axis )
36 |
37 | plt.title("purity functions (i=1)") # title
38 | plt.legend(loc = "upper left") # 凡例
39 | plt.tight_layout() # グラフ同士のラベルが重ならない程度にグラフを小さくする。
40 |
41 | # 図の保存&表示
42 | plt.savefig("./DecisionTree_scikit-learn_1.png", dpi=300)
43 | plt.show()
44 |
45 | print("Finish main()")
46 | return
47 |
48 |
49 | if __name__ == '__main__':
50 | main()
51 |
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_1'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_1'.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_1.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_2-1''.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_2-1''.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_2-2''.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_2-2''.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_3-1'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_3-1'.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_3-2'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_3-2'.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_4-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_4-1.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_4-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_4-2.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_5-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_5-1.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_6-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_6-1.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_7-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_7-1.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_naruto_1-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_naruto_1-1.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_naruto_1-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_naruto_1-2.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_naruto_1-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/EnsembleLearning_scikit-learn_naruto_1-3.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-10_170801.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-10_170801.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-11_170801.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-11_170801.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-12_170802.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-12_170802.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-13_170802.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-13_170802.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-14_170802.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-14_170802.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-15_170802.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-15_170802.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-1_170730.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-1_170730.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-2_170730.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-2_170730.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-3_170731.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-3_170731.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-5_170731.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-5_170731.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-6_170731.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-6_170731.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-7_170731.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-7_170731.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-8_170801.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-8_170801.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-9_170801.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識21-9_170801.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識22-1_170802.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識22-1_170802.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識22-2_170802.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識22-2_170802.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識22-3_170802.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識22-3_170802.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識22-4_170803.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識22-4_170803.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識22-5_170803.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識22-5_170803.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識22-6_170804.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識22-6_170804.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識22-7_170804.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識22-7_170804.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識22-8_170804.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識22-8_170804.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識4-1_160918.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識4-1_160918.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_パターン認識5-2_160919.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_パターン認識5-2_160919.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-10_170701.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-10_170701.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-11_170702.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-11_170702.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-12_170703.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-12_170703.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-13_170703.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-13_170703.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-14_170704.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-14_170704.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-15_170704.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-15_170704.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-16_170705.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-16_170705.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-17_170705.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-17_170705.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-18_170705.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-18_170705.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-19_170707.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-19_170707.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-1_170626.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-1_170626.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-2_170630.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-2_170630.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-3_170630.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-3_170630.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-4_170630.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-4_170630.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-5_170630.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-5_170630.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-6_170701.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-6_170701.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-7'_170701.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-7'_170701.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-7_170701.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-7_170701.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-8_170701.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-8_170701.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-9_170701.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/EnsembleLearning_scikit-learn/img/twitter_情報理論_混合モデルとアンサンブル学習_11-9_170701.png
--------------------------------------------------------------------------------
/EnsembleLearning_scikit-learn/main1.py:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 | # Anaconda 4.3.0 環境
3 |
4 | import numpy
5 | import pandas
6 | import matplotlib.pyplot as plt
7 |
8 | # scikit-learn ライブラリ関連
9 |
10 |
11 | # 自作クラス
12 | import EnsembleModelClassifier
13 | import DataPreProcess
14 | import Plot2D
15 |
16 | def main():
17 | """
18 | アンサンブル学習.
19 | 多数決方式のアンサンブル法と、単体での分類器での誤分類率.
20 | 及び多数決方式のアンサンブル法における分類器の個数に応じた比較.
21 |
22 | """
23 | print("Enter main()")
24 |
25 | ensemble_clf1 = EnsembleModelClassifier.EnsembleModelClassifier( classifiers = range(1,2) )
26 | ensemble_clf2 = EnsembleModelClassifier.EnsembleModelClassifier( classifiers = range(1,4) )
27 | ensemble_clf3 = EnsembleModelClassifier.EnsembleModelClassifier( classifiers = range(1,5) )
28 | ensemble_clf4 = EnsembleModelClassifier.EnsembleModelClassifier( classifiers = range(1,11) )
29 |
30 | # データの読み込み
31 |
32 | #===========================================
33 | # 汎化性能の確認
34 | #===========================================
35 | plt.subplot(2,2,1)
36 | ensemble_clf1.plotEnsenbleErrorAndBaseError()
37 | plt.subplot(2,2,2)
38 | ensemble_clf2.plotEnsenbleErrorAndBaseError()
39 | plt.subplot(2,2,3)
40 | ensemble_clf3.plotEnsenbleErrorAndBaseError()
41 | plt.subplot(2,2,4)
42 | ensemble_clf4.plotEnsenbleErrorAndBaseError()
43 |
44 | plt.savefig("./EnsembleLearning_scikit-learn_1.png", dpi = 300, bbox_inches = 'tight' )
45 | plt.show()
46 |
47 | print("Finish main()")
48 | return
49 |
50 | if __name__ == '__main__':
51 | main()
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/LogisticRegression.py:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 | # Anaconda 4.3.0 環境
3 |
4 | import numpy
5 | import matplotlib.pyplot as plt
6 | import sklearn.linear_model # クラス名の衝突を避けるため
7 | #from sklearn.linear_model import LogisticRegression # ↑
8 |
9 |
10 | class LogisticRegression(object):
11 | """
12 | scikit-learn ライブラリでのロジスティクス回帰のラッパークラス
13 |
14 | [public]
15 | logReg_ : sklearn.linear_model の LogisticRegression クラスのオブジェクト
16 | """
17 |
18 | def __init__( self , paramC = 100 ):
19 | """ """
20 | # sklearn.linear_model の LogisticRegression クラスのオブジェクト生成
21 | self.logReg_ = sklearn.linear_model.LogisticRegression( C = paramC, random_state = 0 )
22 |
23 | return
24 |
25 | def sigmoidFunction( self, z ):
26 | """
27 | シグモイド関数の値を求める
28 | [input]
29 | z : numppy.ndarry
30 | [Output]
31 | 引数のリスト z に対応したシグモイド関数値のリスト value
32 | """
33 | value = 1.0 / ( 1.0 + numpy.exp(-z) )
34 | return value
35 |
36 | def costFunctionClass0( self, z ):
37 | """
38 | クラス0に属しているサンプルのコスト関数の値を求める
39 | [input]
40 | z : numppy.ndarry
41 | [Output]
42 | 引数のリスト z に対応したコスト関数値のリスト value
43 | """
44 | value = -numpy.log( 1- self.sigmoidFunction(z) )
45 | return value
46 |
47 | def costFunctionClass1( self, z ):
48 | """
49 | クラス1に属しているサンプルのコスト関数の値を求める
50 | [input]
51 | z : numppy.ndarry
52 | [Output]
53 | 引数のリスト z に対応したコスト関数値のリスト value
54 | """
55 | value = -numpy.log( self.sigmoidFunction(z) )
56 | return value
57 |
58 | def plotSigmoidFunction( self, z = numpy.arange(-7, 7, 0.1), xlabel = 'z', ylabel = '$\phi (z)$', isGrid = True ):
59 | """
60 | シグモイド関数を図に描写する
61 |
62 | """
63 | phi_z = self.sigmoidFunction( z )
64 |
65 | """
66 | # 描写用のオブジェクトを作成(オブジェクト指向的な描写処理)
67 | fig = plt.figure() # Figure クラスのオブジェクトを生成
68 | axis = fig.add_subplot(1,1,1) # Axes クラスのオブジェクトを生成
69 |
70 | # *オブジェクトの確認
71 | print("type(fig): {}".format( type(fig) ) )
72 | print("type(axis): {}".format(type(axis)))
73 |
74 | axis.plot( z, phi_z)
75 |
76 | axis.set_ylim( -0.1, 1.1)
77 | axis.set_yticks( [0.0, 0.5, 1.0] ) # y軸の目盛り
78 | axis.yaxis.grid( True ) # y軸の水平グリッド線
79 | axis.axvline( 0.0, color='k' ) # z=0 の垂直線
80 | axis.set_xlabel( xlabel )
81 | axis.set_ylabel( ylabel )
82 | fig.tight_layout()
83 | """
84 | plt.clf() # 現在の図をクリア
85 | plt.plot( z, phi_z )
86 |
87 | plt.ylim( -0.1, 1.1 )
88 | plt.axvline( 0.0, color='k' ) # z=0 の垂直線
89 | plt.xlabel( xlabel )
90 | plt.ylabel( ylabel )
91 |
92 | plt.yticks( [0.0, 0.5, 1.0] ) # y軸の目盛り追加
93 | axis = plt.gca() # Axes クラスのオブジェクト生成
94 | axis.yaxis.grid(True) # y軸の目盛りに合わせた水平グリッド線
95 |
96 | plt.tight_layout()
97 | #plt.show()
98 |
99 | return
100 |
101 | def plotCostFunction( self ):
102 | z = numpy.arange( -10, 10, 0.1 )
103 | phi_z = self.sigmoidFunction(z)
104 |
105 | #cost0 = [cost_0(x) for x in z] # 書式: z の要素インデックス x で抽出し、この x で呼び出したコスト関数の値を配列の要素とする
106 |
107 | cost0 = []
108 | cost1 = []
109 | for zi in z:
110 | cost0.append( self.costFunctionClass0(zi) )
111 | cost1.append( self.costFunctionClass1(zi) )
112 |
113 | # plot figure
114 | plt.clf() # 現在の図をクリア
115 | plt.plot(
116 | phi_z, cost0,
117 | linestyle='--',
118 | label='J(w) : cross-entropy error function (class label:0)'
119 | )
120 |
121 | plt.plot(
122 | phi_z, cost1,
123 | linestyle='-',
124 | label='J(w) : cross-entropy error function (class label:1)'
125 | )
126 | plt.ylim(0.0, 5.1)
127 | plt.xlim([0, 1])
128 | plt.xlabel('$\phi$(z)')
129 | plt.ylabel('J(w) : cross-entropy error function (cost)')
130 | plt.legend(loc='best')
131 | plt.tight_layout()
132 |
133 | #plt.show()
134 |
135 | return
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/LogisticRegression_scikit-learn_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/LogisticRegression_scikit-learn_1.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/LogisticRegression_scikit-learn_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/LogisticRegression_scikit-learn_2.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/LogisticRegression_scikit-learn_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/LogisticRegression_scikit-learn_3.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/LogisticRegression_scikit-learn_4'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/LogisticRegression_scikit-learn_4'.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/LogisticRegression_scikit-learn_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/LogisticRegression_scikit-learn_4.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/LogisticRegression_scikit-learn_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/LogisticRegression_scikit-learn_5.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-10_170208.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-10_170208.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-11'_170210.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-11'_170210.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-11_170209.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-11_170209.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-12'_170210.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-12'_170210.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-12_170209.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-12_170209.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-13_170210.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-13_170210.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-14_170210.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-14_170210.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-15_170210.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-15_170210.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-16_170210.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-16_170210.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-17_170726.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-17_170726.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-18_170726.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-18_170726.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-19_170727.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-19_170727.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-1_161130.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-1_161130.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-2_161130.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-2_161130.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-3_161130.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-3_161130.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-4_161130.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-4_161130.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-5_161201.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-5_161201.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-6'_170204.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-6'_170204.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-6_161201.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-6_161201.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-7'_170204.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-7'_170204.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-7_161201.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-7_161201.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-8_170204.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-8_170204.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_パターン認識18-9_170208.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_パターン認識18-9_170208.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_機械学習_3-1_160924.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_機械学習_3-1_160924.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_機械学習_3-2_160924.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_機械学習_3-2_160924.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_機械学習_3-3_160924.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_機械学習_3-3_160924.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_機械学習_3-4_170727.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_機械学習_3-4_170727.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_機械学習_3-5_170810.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_機械学習_3-5_170810.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_機械学習_3-6_170810.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_機械学習_3-6_170810.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_機械学習_3-7_170810.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_機械学習_3-7_170810.png
--------------------------------------------------------------------------------
/LogisticRegression_scikit-learn/img/twitter_機械学習_3-8_170810.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/LogisticRegression_scikit-learn/img/twitter_機械学習_3-8_170810.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_1.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_2.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_3.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_4.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_5.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_5_1'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_5_1'.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_5_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_5_1.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_5_2'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_5_2'.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_5_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_5_2.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_5_3'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_5_3'.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_5_4'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/MachineLearningPipeline_scikit-learn_5_4'.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識10-1_161005.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識10-1_161005.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識10-2_161005.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識10-2_161005.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識10-3_161005.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識10-3_161005.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識11-1_161005.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識11-1_161005.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識11-3_161005.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識11-3_161005.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識12-1_161004.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識12-1_161004.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識13-10_170102.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識13-10_170102.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識13-1_161227.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識13-1_161227.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識13-2_161227.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識13-2_161227.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識13-3_161229.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識13-3_161229.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識13-5_170101.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識13-5_170101.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識13-8_170102.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識13-8_170102.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識13-9_170102.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識13-9_170102.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識20-1_170108.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識20-1_170108.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識4-1_160918.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識4-1_160918.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識5-1_160918.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識5-1_160918.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識5-2_160919.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識5-2_160919.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識5-3_160922.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_パターン認識5-3_160922.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_情報理論_情報と確率_10-1_170625.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_情報理論_情報と確率_10-1_170625.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_情報理論_情報と確率_10-2_170625.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_情報理論_情報と確率_10-2_170625.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_機械学習_3-1_160924.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_機械学習_3-1_160924.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_機械学習_3-2_160924.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_機械学習_3-2_160924.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/img/twitter_機械学習_3-3_160924.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/MachineLearningPipeline_scikit-learn/img/twitter_機械学習_3-3_160924.png
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/main1.py:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 | # Anaconda 4.3.0 環境
3 |
4 | import numpy
5 | import pandas
6 | import matplotlib.pyplot as plt
7 |
8 | # scikit-learn ライブラリ関連
9 | from sklearn.decomposition import PCA
10 | from sklearn.linear_model import LogisticRegression
11 |
12 | from sklearn.preprocessing import StandardScaler # scikit-learn の preprocessing モジュールの StandardScaler クラス
13 | from sklearn.model_selection import StratifiedKFold #
14 | from sklearn.model_selection import cross_val_score #
15 |
16 | from sklearn.pipeline import Pipeline
17 |
18 | # 自作クラス
19 | import Plot2D
20 | import DataPreProcess
21 |
22 |
23 | def main():
24 | """
25 | 機械学習パイプラインによる、機械学習処理フロー(scikit-learn ライブラリの Pipeline クラスを使用)
26 | クロス・バディゲーションによる汎化性能の確認
27 | """
28 | print("Enter main()")
29 |
30 | # データの読み込み
31 | prePro = DataPreProcess.DataPreProcess()
32 | prePro.setDataFrameFromCsvFile(
33 | "https://raw.githubusercontent.com/rasbt/python-machine-learning-book/master/code/datasets/wdbc/wdbc.data"
34 | )
35 | #prePro.print( "Breast Cancer Wisconsin dataset" )
36 |
37 | dat_X = prePro.df_.loc[:, 2:].values
38 | dat_y = prePro.df_.loc[:, 1].values
39 |
40 | #===========================================
41 | # 前処理 [PreProcessing]
42 | #===========================================
43 | # 欠損データへの対応
44 | #prePro.meanImputationNaN()
45 |
46 | # ラベルデータをエンコード
47 | prePro.encodeClassLabelByLabelEncoder( colum = 1 )
48 | prePro.print( "Breast Cancer Wisconsin dataset" )
49 |
50 | # データをトレードオフデータとテストデータに分割
51 | X_train, X_test, y_train, y_test \
52 | = DataPreProcess.DataPreProcess.dataTrainTestSplit( X_input = dat_X, y_input = dat_y, ratio_test = 0.2 )
53 |
54 | #-------------------------------------------
55 | # Pipeline の設定
56 | #-------------------------------------------
57 | # パイプラインに各変換器、推定器を設定
58 | pipe_logReg = Pipeline(
59 | steps = [ # タプル (任意の識別文字, 変換器 or 推定器のクラス) で指定
60 | ( "scl", StandardScaler() ), # スケーリング: 変換器のクラス(fit() 関数を持つ)
61 | ( "pca", PCA( n_components=2 ) ), # PCA でデータの次元削除
62 | ( "clf", LogisticRegression( random_state=1 ) ) # ロジスティクス回帰:推定器のクラス(preddict()関数を持つ)
63 | ]
64 | )
65 |
66 | #
67 | """
68 | pipe_logReg.set_params(
69 | [
70 | ( "scl", StandardScaler() ), # スケーリング: 変換器のクラス(fit() 関数を持つ)
71 | ( "pca", PCA( n_components=2 ) ), # PCA でデータの次元削除
72 | ( "clf", LogisticRegression( random_state=1 ) ) # ロジスティクス回帰:推定器のクラス(preddict()関数を持つ)
73 | ]
74 | )
75 | """
76 |
77 | # パイプラインに設定した変換器の fit() 関数を実行
78 | pipe_logReg.fit( X_train, y_train )
79 |
80 | #
81 | print( "Test Accuracy: %.3f" % pipe_logReg.score( X_test, y_test ) )
82 |
83 | #============================================
84 | # Learning Process
85 | #===========================================
86 | # パイプラインに設定した推定器の predict() 実行
87 | y_predict = pipe_logReg.predict(X_test)
88 | print("predict : ", y_predict )
89 |
90 | # pipeline オブジェクトの内容確認
91 | #print( "pipe_logReg.get_params() : \n", pipe_logReg.get_params( deep = True ) )
92 | #print( "pipe_logReg.get_params() : \n", pipe_logReg.get_params( deep = False ) )
93 |
94 | #===========================================
95 | # 汎化性能の確認
96 | #===========================================
97 |
98 | #-------------------------------------------
99 | # クロスバディゲーション : CV
100 | #-------------------------------------------
101 | scores = cross_val_score(
102 | estimator = pipe_logReg, # 推定器 [estimator]
103 | X = X_train, #
104 | y = y_train, #
105 | cv = 10, # 交差検証の回数(分割数)
106 | n_jobs = -1 # 全てのCPUで並列処理
107 | )
108 |
109 | print( 'CV accuracy scores: %s' % scores )
110 | print( 'CV accuracy: %.3f +/- %.3f' % ( numpy.mean(scores), numpy.std(scores) ) )
111 |
112 |
113 | print("Finish main()")
114 | return
115 |
116 | if __name__ == '__main__':
117 | main()
--------------------------------------------------------------------------------
/MachineLearningPipeline_scikit-learn/main5.py:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 | # Anaconda 4.3.0 環境
3 |
4 | import numpy
5 | import pandas
6 | import matplotlib.pyplot as plt
7 |
8 |
9 | # scikit-learn ライブラリ関連
10 | from sklearn.preprocessing import LabelEncoder #
11 | from sklearn.preprocessing import StandardScaler # scikit-learn の preprocessing モジュールの StandardScaler クラス
12 | from sklearn.decomposition import PCA
13 | from sklearn.model_selection import StratifiedKFold #
14 |
15 | from sklearn.linear_model import LogisticRegression
16 |
17 | from sklearn.pipeline import Pipeline
18 |
19 | # 自作クラス
20 | import Plot2D
21 | import DataPreProcess
22 |
23 |
24 | def main():
25 | """
26 | 機械学習パイプラインによる、機械学習処理フロー(scikit-learn ライブラリの Pipeline クラスを使用)
27 | ROC 曲線によるモデルの汎化能力の評価
28 | """
29 | print("Enter main()")
30 |
31 | # データの読み込み
32 | prePro = DataPreProcess.DataPreProcess()
33 | prePro.setDataFrameFromCsvFile(
34 | "https://raw.githubusercontent.com/rasbt/python-machine-learning-book/master/code/datasets/wdbc/wdbc.data"
35 | )
36 | #prePro.print( "Breast Cancer Wisconsin dataset" )
37 |
38 | #===========================================
39 | # 前処理 [PreProcessing]
40 | #===========================================
41 | # 特徴データとラベルデータ(教師データ)を取り出し
42 | dat_X = prePro.df_.loc[:, 2:].values
43 | dat_y = prePro.df_.loc[:, 1].values
44 |
45 | # 欠損データへの対応
46 | #prePro.meanImputationNaN()
47 |
48 | # カテゴリデータのエンコード
49 | #prePro.encodeClassLabelByLabelEncoder( colum = 1, bPrint = True )
50 | encoder = LabelEncoder()
51 | dat_y = encoder.fit_transform( dat_y ) #
52 | encoder.transform( ["M", "B"]) #
53 |
54 | print( "encoder.fit_transform( dat_y ) : \n", encoder.fit_transform( dat_y ) )
55 | print( "encoder.classes_ : \n", encoder.classes_ )
56 | prePro.print( "Breast Cancer Wisconsin dataset" )
57 |
58 | # データをトレードオフデータとテストデータに分割
59 | X_train, X_test, y_train, y_test \
60 | = DataPreProcess.DataPreProcess.dataTrainTestSplit( X_input = dat_X, y_input = dat_y, ratio_test = 0.2 )
61 |
62 | print( X_train )
63 | print( y_train )
64 |
65 | #-------------------------------------------
66 | # Pipeline の設定
67 | #-------------------------------------------
68 | # パイプラインに各変換器、推定器を設定
69 | pipe_logReg = Pipeline(
70 | # タプル (任意の識別文字, 変換器 or 推定器のクラス) で指定
71 | [
72 | ( "scl", StandardScaler() ), # 正規化 : 変換器のクラス(fit() 関数を持つ)
73 | ( 'pca', PCA( n_components = 2 ) ), # PCA で2次元に削除(特徴抽出)
74 | ( 'clf', LogisticRegression( penalty = 'l2', random_state = 0, C = 100.0 ) ) # ロジスティクス回帰(L2正則化)
75 | # 推定器のクラス(predict()関数を持つ)
76 | ]
77 | )
78 |
79 | # パイプラインに設定した変換器の fit() 関数を実行
80 | #pipe_logReg.fit( X_train, y_train )
81 |
82 | # 予想値
83 | #y_predict =pipe_logReg.predict( X_test )
84 |
85 | # pipeline オブジェクトの内容確認
86 | #print( "Pipeline.get_params( deep = True ) : \n", pipe_logReg.get_params( deep = True ) )
87 | #print( "Pipeline.get_params( deep = False ) : \n", pipe_logReg.get_params( deep = False ) )
88 |
89 | #print( "Pipeline.predict( X_test ) : \n", y_predict )
90 | #print( "Pipeline.predict( X_test )[0] : \n", y_predict[0] )
91 | #print( "Pipeline.predict( X_test )[1] : \n", y_predict[1] )
92 | #print( "Pipeline.predict( X_test )[2] : \n", y_predict[2] )
93 | #print( "Test Accuracy: %.3f" % pipe_csvm.score( X_test, y_test ) )
94 |
95 | # 使用するデータ(特徴量)の一部を抽出
96 | # ROC曲線の結果が検証用に適した形状となるように、特徴量の意図的な抽出
97 | #(AUC 値がほぼ 1.0の結果のみになってしまうため。)
98 | X_train2 = X_train[:, [4, 14]]
99 |
100 | #-------------------------------------------
101 | # クロスバリデーションの設定
102 | #-------------------------------------------
103 | # クロスバディゲーションの回数毎の ROC 曲線を描写するため、
104 | # クラスのオブジェクト作成を作成.
105 | cv = StratifiedKFold( n_splits = 3, random_state = 1 )
106 |
107 | # クラスのオブジェクトをイテレータ化するために split() して list 化
108 | list_cv = list( cv.split( X_train2, y_train ) )
109 |
110 | #print( "StratifiedKFold() : \n", cv )
111 | #print( "list( StratifiedKFold().split() ) : \n", list_cv )
112 |
113 | #------------------------------------
114 | # ROC 曲線
115 | #------------------------------------
116 | Plot2D.Plot2D.drawROCCurveFromTrainTestIterator(
117 | classifiler = pipe_logReg, # 推定器 : fit() 関数, predict() 関数を持つ
118 | iterator = list_cv, #
119 | X_train = X_train2, # 一部を抽出した特徴行列で ROC 曲線を作図
120 | y_train = y_train,
121 | X_test = X_test,
122 | y_test = y_test,
123 | positiveLabel = 1 # positive と見なすラベル値 : "B" = 1
124 | )
125 |
126 | plt.savefig("./MachineLearningPipeline_scikit-learn_5.png", dpi = 300, bbox_inches = 'tight' )
127 | plt.show()
128 |
129 |
130 |
131 |
132 |
133 | print("Finish main()")
134 | return
135 |
136 | if __name__ == '__main__':
137 | main()
--------------------------------------------------------------------------------
/PCA_scikit-learn/PCA_scikit-learn_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/PCA_scikit-learn_1.png
--------------------------------------------------------------------------------
/PCA_scikit-learn/PCA_scikit-learn_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/PCA_scikit-learn_2.png
--------------------------------------------------------------------------------
/PCA_scikit-learn/PCA_scikit-learn_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/PCA_scikit-learn_3.png
--------------------------------------------------------------------------------
/PCA_scikit-learn/PCA_scikit-learn_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/PCA_scikit-learn_4.png
--------------------------------------------------------------------------------
/PCA_scikit-learn/PCA_scikit-learn_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/PCA_scikit-learn_5.png
--------------------------------------------------------------------------------
/PCA_scikit-learn/Plot2D.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import matplotlib.pyplot as plt
4 | import numpy
5 | from matplotlib.colors import ListedColormap
6 |
7 | class Plot2D(object):
8 | """
9 | 2次元の図を描写をサポートする関数群からなるクラス
10 | """
11 |
12 | def __init__( self ):
13 | self.mainTitle = "mainTitle"
14 |
15 | @ staticmethod
16 | def drawDiscriminantRegions( dat_X, dat_y, classifier, list_test_idx = None, resolusion = 0.02 ):
17 | """ 識別器 [classifier] による識別領域を色分けで描写する """
18 |
19 | # 識別クラス数に対応したMAPの作成(最大5クラス対応)
20 | tuple_makers = ( "s","x","+","^","v" ) # タプル(定数リスト)
21 | tuple_colors = ( "red","blue","lightgreen", "gray", "cyan" ) # 塗りつぶす色を表すタプル(定数リスト)
22 | numClass = len( numpy.unique(dat_y) ) # numpy.unique() : 指定したarray変数の要素の重複をなくしたものを返す,更にlen() でユニークな値の数取得
23 | cmap = ListedColormap( tuple_colors[0:numClass] ) # plt.scatter() の引数で使用
24 |
25 | # plot the decision surface
26 | x1_min = dat_X[:, 0].min() - 1
27 | x1_max = dat_X[:, 0].max() + 1
28 | x2_min = dat_X[:, 1].min() - 1
29 | x2_max = dat_X[:, 1].max() + 1
30 |
31 | meshgrids = numpy.meshgrid( # マス目を作る ( 戻り値:numpy.ndarray )
32 | numpy.arange( x1_min, x1_max, resolusion ), # numpy.arang(): min~max by resolution
33 | numpy.arange( x2_min, x2_max, resolusion )
34 | )
35 | # 入力データ datX のx1軸、x2軸の値の全ての組み合わせ
36 | xx1 = meshgrids[0]
37 | xx2 = meshgrids[1]
38 |
39 | # ? 値の全ての組み合わせを1次元配列に変換 numpy.array( [xx1.ravel(), xx2.ravel()] ) し、
40 | # classifierに設定されている predict(予想)を実行
41 | Z = classifier.predict(
42 | numpy.array( [xx1.ravel(), xx2.ravel()] ).T
43 | )
44 | # ? 予測結果を元のグリッドポイントサイズに変換
45 | Z = Z.reshape( xx1.shape ) # numpy.ndarray の属性 shape は,各次元ごとの配列の大きさをまとめたタプルで指定
46 |
47 | # 等高線plotで識別領域を塗りつぶす
48 | plt.contourf( xx1, xx2, Z, alpha=0.4, cmap=cmap )
49 |
50 | # 図の軸の範囲指定
51 | plt.xlim( xx1.min(), xx1.max() )
52 | plt.ylim( xx2.min(), xx2.max() )
53 |
54 | # 識別クラス毎に、入力データ dat_X, dat_y の散布図 plot
55 | for (idx, cl) in enumerate( numpy.unique(dat_y) ): # enumerate():idx と共に clもloop
56 | plt.scatter(
57 | x = dat_X[dat_y == cl, 0],
58 | y = dat_X[dat_y == cl, 1],
59 | alpha = 0.8,
60 | c = cmap(idx),
61 | edgecolor = 'black',
62 | marker = tuple_makers[idx],
63 | label = cl
64 | )
65 |
66 | # テスト用サンプルデータを強調表示
67 | if (list_test_idx != None):
68 | X_test = dat_X[list_test_idx, :]
69 | y_test = dat_y[list_test_idx]
70 | plt.scatter(
71 | X_test[:, 0], X_test[:, 1],
72 | c='',
73 | alpha=1.0,
74 | edgecolor='black',
75 | linewidths=1,
76 | marker='o',
77 | s=55,
78 | label='test set'
79 | )
80 |
81 | # グラフ同士のラベルが重ならない程度にグラフを小さくする。
82 | plt.tight_layout()
83 |
84 | return
85 |
--------------------------------------------------------------------------------
/PCA_scikit-learn/README.md:
--------------------------------------------------------------------------------
1 | ## 主成分分析 [PCA : Principal Component Analysis] による教師なしデータの次元削除、特徴抽出
2 |
3 | ## コードの実行結果
4 |
5 | ### Wine データセット (https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data)
6 |
7 | 13×178 次元のデータ(13:特徴量、178:データ数)
8 |
9 | ||Class label |Alcohol |Malic acid |Ash |Alcalinity of ash|Magnesium |Total phenols|Flavanoids|Nonflavanoid phenols|Proanthocyanins|Color intensity|Hue|OD280/OD315 of diluted wines|Proline|
10 | |---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
11 | |0 |1 |14.23 |1.71 |2.43 |15.6 |127 |2.80|3.06|0.28|2.29|5.640000|1.04|3.92|1065|
12 | |1 |1 |13.20 |1.78 |2.14 |11.2 |100 |2.65|2.76|0.26|1.28|4.380000|1.05|3.40|1050|
13 | |2 |1 |13.16 |2.36 |2.67 |18.6 |101 |2.80|3.24|0.30|2.81|5.680000|1.03|3.17|1185|
14 | |3 |1 |14.37 |1.95 |2.50 |16.8 |113 |3.85|3.49|0.24|2.18|7.800000|0.86|3.45|1480|
15 | |4 |1 |13.24 |2.59 |2.87 |21.0 |118 |2.80|2.69|0.39|1.82|4.320000|1.04|2.93|735|
16 | |5 |1 |14.20 |1.76 |2.45 |15.2 |112 |3.27|3.39|0.34|1.97|6.750000|1.05|2.85|1450|
17 | |...|...|...|...|...|...|...|...|...|...|...|...|...|...|...|
18 | |170|3|12.20|3.03|2.32|19.0|96 |1.25|0.49|0.40|0.73|5.500000 |0.66|1.83|510|
19 | |171|3|12.77|2.39|2.28|19.5|86 |1.39|0.51|0.48|0.64|9.899999 |0.57|1.63|470|
20 | |172|3|14.16|2.51|2.48|20.0|91 |1.68|0.70|0.44|1.24|9.700000 |0.62|1.71|660|
21 | |173|3|13.71|5.65|2.45|20.5|95 |1.68|0.61|0.52|1.06|7.700000 |0.64|1.74|740|
22 | |174|3|13.40|3.91|2.48|23.0|102|1.80|0.75|0.43|1.41|7.300000 |0.70|1.56|750|
23 | |175|3|13.27|4.28|2.26|20.0|120|1.59|0.69|0.43|1.35|10.200000 |0.59|1.56|835|
24 | |176|3|13.17|2.59|2.37|20.0|120|1.65|0.68|0.53|1.46|9.300000 |0.60|1.62|840|
25 | |177|3|14.13|4.10|2.74|24.5|96 |2.05|0.76|0.56|1.35|9.200000 |0.61|1.60|560|
26 |
27 |
28 | ### 固有値 [eigenvalue]
29 |
30 | |λ_1|λ_2|λ_3|λ_4|λ_5|λ_6|λ_7|λ_8|λ_9|λ_10|λ_11|λ_12|λ_13|
31 | |---|---|---|---|---|---|---|---|---|---|---|---|---|
32 | |4.56|2.65|1.33|1.13|0.80|0.55|0.43|0.25|0.22|0.18|0.16|0.12|0.11|
33 |
34 | 
35 |
36 | ### 寄与率(分散の比)[proportion of the variance] / 累積寄与率 [Cumulative contribution rate]
37 |
38 | |principal component|1|2|3|4|5|6|7|8|9|10|11|12|13|
39 | |---|---|---|---|---|---|---|---|---|---|---|---|---|---|
40 | |寄与率|0.366|0.213|0.107|0.090|0.064|0.044|0.035|0.020|0.017|0.014|0.0125|0.009|0.0086|
41 | |累積寄与率|0.366|0.578|0.685|0.775|0.839|0.883|0.918|0.938|0.955|0.970|0.982|0.991|1.000|
42 |
43 | 
44 |
45 | ### 13×178 次元のワインデータ → 2×124 次元のデータに次元削除(特徴抽出)(※124は分割したトレーニングデータ数)
46 |
47 | ワインデータをPCAによる次元削除を行なったデータの散布図。
48 | 寄与率と累積寄与率の図より、第1主成分と第2主成分だけで、全体のデータの60%近くを説明できることから、2×124 次元のデータで散布図を図示。この後、この次元削除したデータでクラス識別用のデータに使用する。
49 |
50 | 
51 |
52 | ### 次元削除したトレーニングデータをロジスティクス回帰で識別
53 |
54 | |classifier 1 : logisitic Regression 1 ( leraning data dimesion by PCA )|value|
55 | |---|--|
56 | |誤識別数 [Misclassified samples]|4|
57 | |正解率 [Accuracy]|0.97|
58 |
59 | 
60 |
61 | ### 次元削除したテストデータをロジスティクス回帰で識別
62 |
63 | |classifier 2 : logisitic Regression 2 ( test data dimesion by PCA )|value|
64 | |---|--|
65 | |誤識別数 [Misclassified samples]|1|
66 | |正解率 [Accuracy]|0.98|
67 |
68 |
69 | 
70 |
71 | ## Theory
72 | 
73 |
74 | ### PCAの分散最大化による定式化
75 |
76 | 
77 | 
78 | 
79 |
80 | 尚、PCA での射影行列は線形変換であるので、PCA による次元削除法は、線形分離可能な問題に適した、所詮線形変換法であることに注意。非線形問題に対応したのが、カーネルPCA [kernel Principal Component Analysis]になる。
81 |
82 | ### PCAの誤差最小化による定式化
83 |
84 | 
85 | 
86 | 
87 | 
88 | 
89 | 
90 | 
91 | 
92 | 
93 | 
94 |
--------------------------------------------------------------------------------
/PCA_scikit-learn/img/twitter_PCA_1-1_170812.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/img/twitter_PCA_1-1_170812.png
--------------------------------------------------------------------------------
/PCA_scikit-learn/img/twitter_PCA_1-2_170812.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/img/twitter_PCA_1-2_170812.png
--------------------------------------------------------------------------------
/PCA_scikit-learn/img/twitter_PCA_1-3_170813.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/img/twitter_PCA_1-3_170813.png
--------------------------------------------------------------------------------
/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-10_161209.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-10_161209.png
--------------------------------------------------------------------------------
/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-1_161209.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-1_161209.png
--------------------------------------------------------------------------------
/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-2_161209.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-2_161209.png
--------------------------------------------------------------------------------
/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-3_161209.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-3_161209.png
--------------------------------------------------------------------------------
/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-4_161209.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-4_161209.png
--------------------------------------------------------------------------------
/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-5_161209.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-5_161209.png
--------------------------------------------------------------------------------
/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-6_161209.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-6_161209.png
--------------------------------------------------------------------------------
/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-7_161209.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-7_161209.png
--------------------------------------------------------------------------------
/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-8_161209.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-8_161209.png
--------------------------------------------------------------------------------
/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-9_161209.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/img/twitter_多変量解析_主成分分析1-9_161209.png
--------------------------------------------------------------------------------
/PCA_scikit-learn/img/twitter_特徴抽出と次元削減_1-1_170812.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/PCA_scikit-learn/img/twitter_特徴抽出と次元削減_1-1_170812.png
--------------------------------------------------------------------------------
/Perceptron/Perceptron.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import numpy
4 |
5 | class Perceptron(object):
6 |
7 | """
8 | [クラス変数(staticな変数)]
9 | Nothing
10 |
11 | [インスタンス変数(全てpublic, private や protected でアクセスを制限することはできません]
12 | public : publicな変数には便宜上 _ をつける
13 | weigths_ : numpy.ndarray
14 | 重みベクトル
15 | errors_ : numpy.ndarray
16 | 各エポック[epoch](トレーニング回数)での誤分類数
17 |
18 | private :
19 | lRate : float
20 | learning rate
21 | numIter : int
22 | トレーニングデータの繰り返し回数(イテレータ)
23 |
24 | """
25 |
26 | def __init__( self , lRate , numIter ) :
27 | """
28 | インスタンスを生成するときに自動的に呼び出される初期化用特殊メソッド
29 | なお、__init__() は return で値を返すとエラーになります。
30 | Python の場合、メソッドの第 1 引数には self と書く習慣あり
31 |
32 | """
33 | self.lRate = lRate
34 | self.numIter = numIter
35 | # self.weights_ = numpy.array()
36 | # self.errors_ = numpy.array()
37 |
38 | def fit( self, X_train, y_train ):
39 | """
40 | パーセプトロンを更新(学習)
41 | [Input]
42 | X_train : numpy.ndarray.shape = [numSamples, numFeatures]
43 | 学習データの行列
44 |
45 | y_train : numpy.ndarray.shape = [numSamples]
46 | ラベルのベクトル
47 |
48 | *numpy.ndarray
49 | 最初の属性 dtype は配列の要素の型
50 | 二番目の属性 ndim は,次元数
51 | 三番目の属性 shape は,各次元ごとの配列の大きさをまとめたタプルで指定
52 | [Output]
53 | self : 自身のオブジェクト
54 |
55 | """
56 | # numpy.zeros() : 全要素が0の行列を生成
57 | self.weights_ = numpy.zeros( 1+X_train.shape[1] ) # numFeatures+1 個の配列
58 | self.errors_ = []
59 |
60 | for it in range(self.numIter):
61 | errors = 0
62 |
63 | # zip() を用いて複数シーケンス(X_train, y_train)の並列処理ループ
64 | for (xi, yi) in zip( X_train,y_train ):
65 | diffWeight = self.lRate * ( yi- self.predict(xi) ) # Δw = η*(y_i-y^_i)
66 | self.weights_[1:] += diffWeight*xi # 重みの更新
67 | errors += int( diffWeight != 0.0) # 重みの変化量が0でない(重みを変化)させる際は、誤りであったので誤りカウントをインクリメント
68 |
69 | self.errors_.append( errors ) # 反復回数[numSamples]あたりの誤りカウント量を配列の最後に挿入
70 |
71 | return self
72 |
73 |
74 | def CalcNetInput( self, X_train ):
75 | """
76 | パーセプトロンを構成する入力層から出力層への入力を計算
77 |
78 |
79 | """
80 | numInputLayer = numpy.dot( X_train, self.weights_[1:] ) + self.weights_[0]
81 | return numInputLayer
82 |
83 | def predict(self, X_train ):
84 | """
85 | パーセプトロンによる識別結果のクラスラベル [+1 or -1]を返す
86 |
87 | """
88 | # numpy.where() で条件を満たす配列のindex を取得
89 | # 条件 self.CalcNetInput(X_train) >= 0.0 が True なら label=1, Falseなら label=-1
90 | label = numpy.where( self.CalcNetInput(X_train) >= 0.0, 1,-1 )
91 | return label
92 |
--------------------------------------------------------------------------------
/Perceptron/Perceptron_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron/Perceptron_1.png
--------------------------------------------------------------------------------
/Perceptron/README.md:
--------------------------------------------------------------------------------
1 | ## パーセプトロン [Perceptron](scikit-learn ライブラリ不使用)
2 |
3 | 分かりやすいように main.py ファイル毎に1つの完結したコードにしています。
4 |
5 | ### 項目 [Contents]
6 |
7 | 1. [使用するライブラリ](#ID_1)
8 | 1. [使用するデータセット](#ID_2)
9 | 1. [コードの実行結果](#ID_3)
10 | 1. [パーセプトロンによる重みベクトルの更新と識別処理 : `main.py`](#ID_3-1)
11 | 1. [背景理論](#ID_1)
12 | 1. [ニューラルネットワークの概要](#ID_4-1)
13 | 1. [活性化関数](#ID_4-2)
14 | 1. [単純パーセプトロン](#ID_4-3)
15 | 1. [パーセプトロンによる論理演算](#ID_4-4)
16 | 1. [最急降下法による学習](#ID_4-5)
17 |
18 |
19 |
20 |
21 | ### 使用するライブラリ
22 |
23 |
24 |
25 |
26 |
27 | ### 使用するデータセット
28 |
29 | > Iris データセット :
30 | > https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data
31 |
32 |
33 |
34 |
35 | ## コードの実行結果
36 |
37 |
38 |
39 | ## パーセプトロンによる重みベクトルの更新と識別処理 : `main.py`
40 |
41 | - Iris データセットを使用 : `pandas.read_csv()`
42 | - 特徴行列 `X_features` は、特徴数 2 個 × サンプル数 100 個 : `X_features = df_Iris.iloc[0:100, [0,2]].values`
43 | - サンプル数 100 個の内、品種 "setosa" が 50 個、"virginica" が 50 個。
44 | - 教師データ `y_labels` は、サンプル数 100 個 : `y_labels = df_Iris.iloc[0:100,4].values`
45 | - カテゴリーデータを -1 or 1 に変換 : `y_labels = numpy.where( y_labels == "Iris-setosa", -1, 1)`
46 | - 正規化処理を実施しない。
47 | - 自作クラス `Perceptron` でパーセプトロンの fitting 処理(重みベクトルの更新)を実施 :
48 | `Perceptron.fit( X_features, y_labels )`
49 |
50 |
51 |
52 | >アヤメデータを単一パーセプトロン&最急降下法で識別結果 (重みの更新:Δw = η*(y_i-y^_i))
53 | 
54 |
55 |
56 |
57 | ---
58 |
59 |
60 |
61 | ## 背景理論
62 |
63 |
64 |
65 | ## ニューラルネットワークの概要
66 | 
67 | 
68 | 
69 |
70 |
71 |
72 | ## 活性化関数
73 | 
74 | 
75 |
76 |
77 |
78 | # 単純パーセプトロン
79 | 
80 |
81 |
82 |
83 | # パーセプトロンによる論理演算
84 | 
85 | 
86 |
87 |
88 |
89 | # 最急降下法による学習
90 | 
91 |
92 |
93 |
94 | ##### 最急降下法の単層パーセプトロンでの適用
95 | 
96 | 
97 |
98 |
99 |
100 | ##### 最急降下法の多層パーセプトロンでの適用
101 | 
102 | 
103 | 
--------------------------------------------------------------------------------
/Perceptron/img/twitter_NN1_1_160825.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron/img/twitter_NN1_1_160825.png
--------------------------------------------------------------------------------
/Perceptron/img/twitter_NN1_2_160825.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron/img/twitter_NN1_2_160825.png
--------------------------------------------------------------------------------
/Perceptron/img/twitter_NN2-1_160826.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron/img/twitter_NN2-1_160826.png
--------------------------------------------------------------------------------
/Perceptron/img/twitter_NN2-2_160826.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron/img/twitter_NN2-2_160826.png
--------------------------------------------------------------------------------
/Perceptron/img/twitter_NN3'-1_160827.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron/img/twitter_NN3'-1_160827.png
--------------------------------------------------------------------------------
/Perceptron/img/twitter_NN4'-1_160829.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron/img/twitter_NN4'-1_160829.png
--------------------------------------------------------------------------------
/Perceptron/img/twitter_NN6-1_160829.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron/img/twitter_NN6-1_160829.png
--------------------------------------------------------------------------------
/Perceptron/img/twitter_NN6-2_160829.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron/img/twitter_NN6-2_160829.png
--------------------------------------------------------------------------------
/Perceptron/img/twitter_NN8-2''_160902.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron/img/twitter_NN8-2''_160902.png
--------------------------------------------------------------------------------
/Perceptron/img/twitter_NN8-3''_160902.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron/img/twitter_NN8-3''_160902.png
--------------------------------------------------------------------------------
/Perceptron/img/twitter_パーセプトロン_1_2_170718.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron/img/twitter_パーセプトロン_1_2_170718.png
--------------------------------------------------------------------------------
/Perceptron/main.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # Anaconda 4.3.0 環境
3 |
4 | import numpy
5 | import matplotlib.pyplot as plt
6 | import pandas
7 |
8 | # 自作クラス
9 | import Perceptron
10 | from MLPlot import MLPlot
11 |
12 |
13 | def main():
14 | #----------------------------------------------------
15 | # read & set iris data
16 | #----------------------------------------------------
17 | print("reading iris data from pandas-lib")
18 | # pandasライブラリを使用して Iris データを読み込み (dataframe obj)
19 | df_Iris = pandas.read_csv(
20 | 'https://archive.ics.uci.edu/ml/'
21 | 'machine-learning-databases/iris/iris.data',
22 | header = None
23 | )
24 | print("finish reading iris data from pandas-lib")
25 | #df_Iris.tail()
26 |
27 | y_labels = df_Iris.iloc[ 0:100,4 ].values #
28 | y_labels = numpy.where( y_labels == "Iris-setosa", -1, 1 ) # Iris-setosa = -1, Iris-virginica = 1 に変換
29 | X_features = df_Iris.iloc[ 0:100, [0,2] ].values # pandas DataFrame のrow,columnの指定方法(iloc:rawのindex(0 ~ ), columnのindex(0 ~ ))
30 |
31 | #----------------------------------------------------
32 | # Draw learing data
33 | #----------------------------------------------------
34 | plt.subplot( 2,2,1 ) # plt.subplot(行数, 列数, 何番目のプロットか)
35 | plt.tight_layout() # グラフ同士のラベルが重ならない程度にグラフを小さくする。
36 |
37 | # 品種 setosa のplot(赤の○)
38 | plt.scatter(
39 | X_features[0:50,0], X_features[0:50,1],
40 | color = "red",
41 | marker = "o",
42 | label = "setosa"
43 | )
44 | # 品種 virginica のplot(青のx)
45 | plt.scatter(
46 | X_features[50:100,0], X_features[50:100,1],
47 | color = "blue",
48 | marker = "x",
49 | label = "virginica"
50 | )
51 |
52 | plt.title( "Learning data" ) #
53 | plt.xlabel( "sepal length [cm]" )
54 | plt.ylabel( "petal length [cm]" ) # label
55 | plt.legend( loc = "upper left" ) # 凡例
56 |
57 | #----------------------------------------------------
58 | # set perceptron & draw
59 | #----------------------------------------------------
60 | ppn1 = Perceptron.Perceptron( lRate=0.1, numIter=10 )
61 | ppn1.fit( X_features, y_labels )
62 |
63 | plt.subplot( 2,2,2 ) # plt.subplot(行数, 列数, 何番目のプロットか)
64 | plt.tight_layout() # グラフ同士のラベルが重ならない程度にグラフを小さくする。
65 | plt.plot(
66 | range( 1,len(ppn1.errors_) + 1 ), ppn1.errors_,
67 | marker = 'o'
68 | )
69 | plt.title( "Fitting" )
70 | plt.xlabel("Epochs (Number of trainings)")
71 | plt.ylabel("Number of updates")
72 |
73 | #----------------------------------------------
74 | plt.subplot( 2,2,3 ) # plt.subplot(行数, 列数, 何番目のプロットか)
75 |
76 | MLPlot.drawDiscriminantRegions( X_features, y_labels, classifier=ppn1 )
77 | plt.title( "Result of discrimination" )
78 | plt.xlabel("sepal length [cm]")
79 | plt.ylabel("petal length [cm]")
80 | plt.legend( loc="upper left" )
81 | plt.tight_layout() # グラフ同士のラベルが重ならない程度にグラフを小さくする。
82 |
83 | #-----------------------------------------------
84 | plt.savefig( "./Perceptron_1.png", dpi=300 )
85 | plt.show()
86 |
87 | if __name__ == '__main__':
88 | main()
89 |
--------------------------------------------------------------------------------
/Perceptron_scikit-learn/Perceptron_scikit-learn_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron_scikit-learn/Perceptron_scikit-learn_1.png
--------------------------------------------------------------------------------
/Perceptron_scikit-learn/Perceptron_scikit-learn_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron_scikit-learn/Perceptron_scikit-learn_2.png
--------------------------------------------------------------------------------
/Perceptron_scikit-learn/README.md:
--------------------------------------------------------------------------------
1 | ## パーセプトロン [Perceptron](scikit-learn ライブラリ使用)
2 |
3 | 分かりやすいように main.py ファイル毎に1つの完結したコードにしています。
4 |
5 | ### 項目 [Contents]
6 |
7 | 1. [使用するライブラリ](#ID_1)
8 | 1. [使用するデータセット](#ID_2)
9 | 1. [コードの実行結果](#ID_3)
10 | 1. [パーセプトロンによる3クラス(アヤメデータ)の識別 : `main.py`](#ID_3-1)
11 | 1. [背景理論](#ID_1)
12 | 1. [ニューラルネットワークの概要](#ID_4-1)
13 | 1. [活性化関数](#ID_4-2)
14 | 1. [単純パーセプトロン](#ID_4-3)
15 | 1. [パーセプトロンによる論理演算](#ID_4-4)
16 | 1. [最急降下法による学習](#ID_4-5)
17 |
18 |
19 |
20 |
21 | ### 使用するライブラリ
22 |
23 | > scikit-learn ライブラリ
24 | >> データセット Dataset loading utilities : `sklearn.datasets`
25 | >> http://scikit-learn.org/stable/datasets/index.html
26 |
27 | >> モデル選択 : `sklearn.model_selection`
28 | >>> データの分割 : `sklearn.model_selection.train_test_split()`
29 | http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html
30 |
31 | >> 前処理 : `sklearn.preprocessing`
32 | >>> 正規化処理 : `sklearn.preprocessing.StandardScaler`
33 | http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html
34 |
35 | >> 正解率の算出 : `sklearn.metrics.accuracy_score`
36 | http://scikit-learn.org/stable/modules/generated/sklearn.metrics.accuracy_score.html
37 |
38 | >> パーセプトロン : `sklearn.linear_model.Perceptron`
39 | http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Perceptron.html
40 |
41 |
42 |
43 |
44 |
45 | ### 使用するデータセット
46 |
47 | > Iris データセット : `datasets.load_iris()`
48 |
49 |
50 |
51 | ## コードの実行結果
52 |
53 |
54 |
55 | ## パーセプトロンによる3クラス(アヤメデータ)の識別 : `main.py`
56 |
57 | - Iris データセットを使用 : `datasets.load_iris()`
58 | - 特徴行列 `X_features` は、特徴数 2 個 × サンプル数 150 個 : `iris.data[ :, [2,3] ]`
59 | - サンプル数 150 個の内、品種 "setosa" が 50 個、"virginica" が 50 個、"versicolor" が 50 個。
60 | - 教師データ `y_labels` は、サンプル数 150 個 : `y_labels = iris.target`
61 | - ここで、`iris.target` で取得したデータは、カテゴリーデータを 0, 1, 2 に変換したデータとなっている。
62 | - トレーニングデータ 70% 、テストデータ 30%の割合で分割 : `sklearn.cross_validation.train_test_split( test_size = 0.3, random_state = 0 )`
63 | - 正規化処理を実施する。 : `sklearn.preprocessing.StandardScaler` クラスを使用
64 | - モデルとして、単純パーセプトロンモデルを使用する (グリッドサーチによるハイパーパラメータのチューニングは行わない):
65 | `ppn1 = Perceptron( n_iter = 40, eta0 = 0.1, random_state = 0, shuffle = True )`
66 | - この単純パーセプトロンモデルの fitting 処理でモデルを学習させる :
67 | `ppn1.fit( X = X_train_std, y = y_train )`
68 | - predict した結果 `y_predict = ppn1.predict( X_test_std )` を元に、`accuracy_score()` 関数で、正解率、誤分類のサンプル数を算出。
69 | 正解率 : `accuracy_score( y_test, y_predict )`
70 | 誤分類数 : `( y_test != y_predict ).sum()`
71 | - `predict_proba()` 関数を使用して、指定したサンプルのクラスの所属関係を予想 :
72 | 例 : `linearSVM.predict_proba( X_test_std[0, :].reshape(1, -1) )`
73 |
74 |
75 |
76 | パーセプトロンによる3クラス(アヤメデータ)の識別結果と識別境界の図。
77 | (重みの更新:Δw = η*(y_i-y^_i))
78 | ※ 以下の図中の分割方法に関する記述の、クロス・バリデーションの部分は誤記で、クロス・バリデーションでの各種スコアの評価は行なっていない。
79 | 
80 |
81 |
82 |
83 | ---
84 |
85 |
86 |
87 | ## 背景理論
88 |
89 |
90 |
91 | ## ニューラルネットワークの概要
92 | 
93 | 
94 | 
95 |
96 |
97 |
98 | ## 活性化関数
99 | 
100 | 
101 |
102 |
103 |
104 | # 単純パーセプトロン
105 | 
106 |
107 |
108 |
109 | # パーセプトロンによる論理演算
110 | 
111 | 
112 |
113 |
114 |
115 | # 最急降下法による学習
116 | 
117 |
118 |
119 |
120 | ##### 最急降下法の単層パーセプトロンでの適用
121 | 
122 | 
123 |
124 |
125 |
126 | ##### 最急降下法の多層パーセプトロンでの適用
127 | 
128 | 
129 | 
--------------------------------------------------------------------------------
/Perceptron_scikit-learn/img/twitter_NN1_1_160825.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron_scikit-learn/img/twitter_NN1_1_160825.png
--------------------------------------------------------------------------------
/Perceptron_scikit-learn/img/twitter_NN1_2_160825.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron_scikit-learn/img/twitter_NN1_2_160825.png
--------------------------------------------------------------------------------
/Perceptron_scikit-learn/img/twitter_NN2-1_160826.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron_scikit-learn/img/twitter_NN2-1_160826.png
--------------------------------------------------------------------------------
/Perceptron_scikit-learn/img/twitter_NN2-2_160826.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron_scikit-learn/img/twitter_NN2-2_160826.png
--------------------------------------------------------------------------------
/Perceptron_scikit-learn/img/twitter_NN3'-1_160827.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron_scikit-learn/img/twitter_NN3'-1_160827.png
--------------------------------------------------------------------------------
/Perceptron_scikit-learn/img/twitter_NN4'-1_160829.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron_scikit-learn/img/twitter_NN4'-1_160829.png
--------------------------------------------------------------------------------
/Perceptron_scikit-learn/img/twitter_NN6-1_160829.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron_scikit-learn/img/twitter_NN6-1_160829.png
--------------------------------------------------------------------------------
/Perceptron_scikit-learn/img/twitter_NN6-2_160829.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron_scikit-learn/img/twitter_NN6-2_160829.png
--------------------------------------------------------------------------------
/Perceptron_scikit-learn/img/twitter_NN8-2''_160902.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron_scikit-learn/img/twitter_NN8-2''_160902.png
--------------------------------------------------------------------------------
/Perceptron_scikit-learn/img/twitter_NN8-3''_160902.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron_scikit-learn/img/twitter_NN8-3''_160902.png
--------------------------------------------------------------------------------
/Perceptron_scikit-learn/img/twitter_python_scikit-learn_1_1_170719.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/Perceptron_scikit-learn/img/twitter_python_scikit-learn_1_1_170719.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MachineLearning_Exercises_Python_scikit-learn
2 | Python&機械学習ライブラリ scikit-learn の使い方の練習コード集。機械学習の理論解説付き。
3 |
4 | 分かりやすいように、各フォルダ毎で完結したコード一式になっています。
5 | 又、各フォルダにある README.md ファイルに、コード実行結果の解説と合わせて関連する機械学習の背景理論の解説も記載してます。
6 |
7 |
8 | ### 機械学習ライブラリ : scikit-learn
9 |
10 | > scikit-learn ライブラリ チートシート:
11 | >> http://scikit-learn.org/stable/tutorial/machine_learning_map/
12 |
13 |
14 | ### 検証用データセット
15 | > https://github.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/blob/master/dataset.md
16 |
17 | ## 項目(フォルダ別)
18 |
19 | 1. [./Perceptron](https://github.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/tree/master/Perceptron)
20 | 1. [./AdaLineGD](https://github.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/tree/master/AdaLineGD)
21 | 1. [./AdaLineSGD](https://github.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/tree/master/AdaLineSGD)
22 | 1. [./Perceptron_scikit-learn](https://github.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/tree/master/Perceptron_scikit-learn)
23 | 1. [./LogisticRegression_scikit-learn](https://github.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/tree/master/LogisticRegression_scikit-learn)
24 | 1. [./SVM_scikit-learn](https://github.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/tree/master/SVM_scikit-learn)
25 | 1. [./kNN_scikit-learn](https://github.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/tree/master/kNN_scikit-learn)
26 | 1. [./DecisionTree_scikit-learn](https://github.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/tree/master/DecisionTree_scikit-learn)
27 | 1. [./RandomForests_scikit-learn](https://github.com/Yagami360/MachineLearning_Samples_Python/tree/master/RandomForests_scikit-learn)
28 | 1. [./DataPreProcess_scikit-learn](https://github.com/Yagami360/MachineLearning_Samples_Python/tree/master/DataPreProcess_scikit-learn)
29 | 1. [./PCA_scikit-learn](https://github.com/Yagami360/MachineLearning_Samples_Python/tree/master/PCA_scikit-learn)
30 | 1. [./kernelPCA_scikit-learn](https://github.com/Yagami360/MachineLearning_Samples_Python/tree/master/kernelPCA_scikit-learn)
31 | 1. [./MachineLearningPipeline_scikit-learn](https://github.com/Yagami360/MachineLearning_Samples_Python/tree/master/MachineLearningPipeline_scikit-learn)
32 | 1. [./EnsembleLearning_scikit-learn](https://github.com/Yagami360/MachineLearning_Samples_Python/tree/master/EnsembleLearning_scikit-learn)
33 | 1. [./ClusteringAnalysis_scikit-learn](https://github.com/Yagami360/MachineLearning_Samples_Python/tree/master/ClusteringAnalysis_scikit-learn)
34 |
35 |
--------------------------------------------------------------------------------
/RandomForests_scikit-learn/Plot2D.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import matplotlib.pyplot as plt
4 | import numpy
5 | from matplotlib.colors import ListedColormap
6 |
7 | class Plot2D(object):
8 | """
9 | 2次元の図を描写をサポートする関数群からなるクラス
10 | """
11 |
12 | def __init__( self ):
13 | self.mainTitle = "mainTitle"
14 |
15 | @ staticmethod
16 | def drawDiscriminantRegions( dat_X, dat_y, classifier, list_test_idx = None, resolusion = 0.02 ):
17 | """ 識別器 [classifier] による識別領域を色分けで描写する """
18 |
19 | # 識別クラス数に対応したMAPの作成(最大5クラス対応)
20 | tuple_makers = ( "s","x","+","^","v" ) # タプル(定数リスト)
21 | tuple_colors = ( "red","blue","lightgreen", "gray", "cyan" ) # 塗りつぶす色を表すタプル(定数リスト)
22 | numClass = len( numpy.unique(dat_y) ) # numpy.unique() : 指定したarray変数の要素の重複をなくしたものを返す,更にlen() でユニークな値の数取得
23 | cmap = ListedColormap( tuple_colors[0:numClass] ) # plt.scatter() の引数で使用
24 |
25 | # plot the decision surface
26 | x1_min = dat_X[:, 0].min() - 1
27 | x1_max = dat_X[:, 0].max() + 1
28 | x2_min = dat_X[:, 1].min() - 1
29 | x2_max = dat_X[:, 1].max() + 1
30 |
31 | meshgrids = numpy.meshgrid( # マス目を作る ( 戻り値:numpy.ndarray )
32 | numpy.arange( x1_min, x1_max, resolusion ), # numpy.arang(): min~max by resolution
33 | numpy.arange( x2_min, x2_max, resolusion )
34 | )
35 | # 入力データ datX のx1軸、x2軸の値の全ての組み合わせ
36 | xx1 = meshgrids[0]
37 | xx2 = meshgrids[1]
38 |
39 | # ? 値の全ての組み合わせを1次元配列に変換 numpy.array( [xx1.ravel(), xx2.ravel()] ) し、
40 | # classifierに設定されている predict(予想)を実行
41 | Z = classifier.predict(
42 | numpy.array( [xx1.ravel(), xx2.ravel()] ).T
43 | )
44 | # ? 予測結果を元のグリッドポイントサイズに変換
45 | Z = Z.reshape( xx1.shape ) # numpy.ndarray の属性 shape は,各次元ごとの配列の大きさをまとめたタプルで指定
46 |
47 | # 等高線plotで識別領域を塗りつぶす
48 | plt.contourf( xx1, xx2, Z, alpha=0.4, cmap=cmap )
49 |
50 | # 図の軸の範囲指定
51 | plt.xlim( xx1.min(), xx1.max() )
52 | plt.ylim( xx2.min(), xx2.max() )
53 |
54 | # 識別クラス毎に、入力データ dat_X, dat_y の散布図 plot
55 | for (idx, cl) in enumerate( numpy.unique(dat_y) ): # enumerate():idx と共に clもloop
56 | plt.scatter(
57 | x = dat_X[dat_y == cl, 0],
58 | y = dat_X[dat_y == cl, 1],
59 | alpha = 0.8,
60 | c = cmap(idx),
61 | edgecolor = 'black',
62 | marker = tuple_makers[idx],
63 | label = cl
64 | )
65 |
66 | # テスト用サンプルデータを強調表示
67 | if (list_test_idx != None):
68 | X_test = dat_X[list_test_idx, :]
69 | y_test = dat_y[list_test_idx]
70 | plt.scatter(
71 | X_test[:, 0], X_test[:, 1],
72 | c='',
73 | alpha=1.0,
74 | edgecolor='black',
75 | linewidths=1,
76 | marker='o',
77 | s=55,
78 | label='test set'
79 | )
80 |
81 | # グラフ同士のラベルが重ならない程度にグラフを小さくする。
82 | plt.tight_layout()
83 |
84 | return
85 |
--------------------------------------------------------------------------------
/RandomForests_scikit-learn/README.md:
--------------------------------------------------------------------------------
1 | ## ランダムフォレスト [RandomForest]
2 |
3 | ### 項目 [Contents]
4 |
5 | 1. [使用するライブラリ](#使用するライブラリ)
6 | 1. [コードの実行結果](#コードの実行結果)
7 | 1. [背景理論](#背景理論)
8 |
9 |
10 |
11 |
12 |
13 | ### 使用するライブラリ:
14 |
15 | >ランダムフォレスト : `sklearn.ensemble.RandomForestClassifier`
16 | http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html
17 |
18 |
19 |
20 | ## コードの実行結果
21 |
22 | ランダムフォレストを用いた識別問題における、森のサイズと特徴の誤り率&OOB誤り率の変化の関係図。
23 |
24 | データはアヤメデータの3品種、合計150個を、それぞれ指定された森のサイズ(弱識別器の数)を持つランダムフォレスト全てに適用している。
25 | 決定木構築のための不純度としてジニ係数を使用。
26 |
27 | 森のサイズ(弱識別器数:決定木数)が大きくなるほど誤り率は低下しており、およそ25個程度で値が収束(OOB error rate : 0.057, iris error rate : 0.002)していることが分かる。
28 | 
29 |
30 | ---
31 |
32 | ランダムフォレストを用いたアヤメデータの識別問題における、各特徴(がく片 [sepal] の長さ、幅、花弁 [petal] の長さ、幅)の関係図。
33 |
34 | データはアヤメデータの3品種合計150個を、50個の森を持つランダムフォレストに適用。
35 |
36 | データは、トレーニング用:105個、テスト用:45個、に分割する。データの分割は、トレーニングデータ:70%, テストデータ :30% のランダムサンプリング。決定木構築のための不純度としてジニ係数を使用。
37 |
38 | <各特徴の重要度の値>
39 |
40 | 1 : sepal length (cm) = 0.151
41 |
42 | 2 : sepal width (cm) = 0.025
43 |
44 | 3 : petal length (cm) = 0.429010
45 |
46 | 4 : petal width (cm) =0.395
47 |
48 | 
49 |
50 |
51 |
52 |
53 | ## 背景理論
54 |
55 | 
56 | 
57 | 
58 |
59 | 
60 | 
61 |
62 | 
63 | 
64 | 
65 |
66 |
67 |
--------------------------------------------------------------------------------
/RandomForests_scikit-learn/RamdomForest_scikit-learn_2'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/RandomForests_scikit-learn/RamdomForest_scikit-learn_2'.png
--------------------------------------------------------------------------------
/RandomForests_scikit-learn/RamdomForest_scikit-learn_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/RandomForests_scikit-learn/RamdomForest_scikit-learn_2.png
--------------------------------------------------------------------------------
/RandomForests_scikit-learn/RamdomForest_scikit-learn_3'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/RandomForests_scikit-learn/RamdomForest_scikit-learn_3'.png
--------------------------------------------------------------------------------
/RandomForests_scikit-learn/RamdomForest_scikit-learn_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/RandomForests_scikit-learn/RamdomForest_scikit-learn_3.png
--------------------------------------------------------------------------------
/RandomForests_scikit-learn/RamdomForest_scikit-learn_4'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/RandomForests_scikit-learn/RamdomForest_scikit-learn_4'.png
--------------------------------------------------------------------------------
/RandomForests_scikit-learn/RamdomForest_scikit-learn_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/RandomForests_scikit-learn/RamdomForest_scikit-learn_4.png
--------------------------------------------------------------------------------
/RandomForests_scikit-learn/RandomForest_scikit-learn_1'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/RandomForests_scikit-learn/RandomForest_scikit-learn_1'.png
--------------------------------------------------------------------------------
/RandomForests_scikit-learn/RandomForest_scikit-learn_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/RandomForests_scikit-learn/RandomForest_scikit-learn_1.png
--------------------------------------------------------------------------------
/RandomForests_scikit-learn/img/twitter_パターン認識22-1_170802.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/RandomForests_scikit-learn/img/twitter_パターン認識22-1_170802.png
--------------------------------------------------------------------------------
/RandomForests_scikit-learn/img/twitter_パターン認識22-2_170802.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/RandomForests_scikit-learn/img/twitter_パターン認識22-2_170802.png
--------------------------------------------------------------------------------
/RandomForests_scikit-learn/img/twitter_パターン認識22-3_170802.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/RandomForests_scikit-learn/img/twitter_パターン認識22-3_170802.png
--------------------------------------------------------------------------------
/RandomForests_scikit-learn/img/twitter_パターン認識22-6_170804.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/RandomForests_scikit-learn/img/twitter_パターン認識22-6_170804.png
--------------------------------------------------------------------------------
/RandomForests_scikit-learn/img/twitter_パターン認識22-7_170804.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/RandomForests_scikit-learn/img/twitter_パターン認識22-7_170804.png
--------------------------------------------------------------------------------
/RandomForests_scikit-learn/img/twitter_パターン認識22-8_170804.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/RandomForests_scikit-learn/img/twitter_パターン認識22-8_170804.png
--------------------------------------------------------------------------------
/RandomForests_scikit-learn/twitter_パターン認識22-4_170803.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/RandomForests_scikit-learn/twitter_パターン認識22-4_170803.png
--------------------------------------------------------------------------------
/RandomForests_scikit-learn/twitter_パターン認識22-5_170803.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/RandomForests_scikit-learn/twitter_パターン認識22-5_170803.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/SVM_scikit-learn_1'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/SVM_scikit-learn_1'.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/SVM_scikit-learn_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/SVM_scikit-learn_1.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/SVM_scikit-learn_2'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/SVM_scikit-learn_2'.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/SVM_scikit-learn_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/SVM_scikit-learn_2.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/SVM_scikit-learn_3'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/SVM_scikit-learn_3'.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/SVM_scikit-learn_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/SVM_scikit-learn_3.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/SVM_scikit-learn_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/SVM_scikit-learn_4.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/SVM_scikit-learn_5'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/SVM_scikit-learn_5'.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/SVM_scikit-learn_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/SVM_scikit-learn_5.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/SVM_scikit-learn_6'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/SVM_scikit-learn_6'.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/SVM_scikit-learn_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/SVM_scikit-learn_6.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_1-1_170211.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_1-1_170211.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_1-2_170211.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_1-2_170211.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_2-1_170212.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_2-1_170212.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_2-2_170212.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_2-2_170212.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_3-1_170214.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_3-1_170214.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_3-2_170214.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_3-2_170214.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_3-3_170214.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_3-3_170214.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_3-4_170214.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_3-4_170214.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_3-5_170216.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_3-5_170216.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_4-1_170216.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_4-1_170216.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_4-2_170217.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_4-2_170217.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_4-3_170217.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_4-3_170217.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_4-4_170218.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_4-4_170218.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_4-5_170218.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_4-5_170218.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_5-1_170219.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_5-1_170219.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_5-2_170220.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_5-2_170220.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_5-2_170225.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_5-2_170225.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_5-3_170222.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_5-3_170222.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_5-4_170225.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_5-4_170225.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_5-5_170303.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_5-5_170303.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_5-6_170303.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_5-6_170303.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_5-7_170305.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_5-7_170305.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_6-1_170728.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_6-1_170728.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_6-2'_170728.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_6-2'_170728.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_6-3_170729.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_6-3_170729.png
--------------------------------------------------------------------------------
/SVM_scikit-learn/img/twitter_SVM_6-4_170729.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/SVM_scikit-learn/img/twitter_SVM_6-4_170729.png
--------------------------------------------------------------------------------
/dataset.md:
--------------------------------------------------------------------------------
1 | ## 検証用データセット
2 |
3 | ### Iris データセット : (csvフォーマット)
4 | URL : https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data
5 |
6 | 全サンプル数 150 個の内、アヤメの品種("setosa", "versicolor", "versicolor" )は、以下のように構成されている。
12 |
13 | ### ワインデータセット:(csvフォーマット)
14 |
15 | URL : https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data
16 |
17 | コラムにラベルを追加して記載した表
18 |
19 | ||Class label |Alcohol |Malic acid |Ash |Alcalinity of ash|Magnesium |Total phenols|Flavanoids|Nonflavanoid phenols|Proanthocyanins|Color intensity|Hue|OD280/OD315 of diluted wines|Proline|
20 | |---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
21 | |0 |1 |14.23 |1.71 |2.43 |15.6 |127 |2.80|3.06|0.28|2.29|5.640000|1.04|3.92|1065|
22 | |1 |1 |13.20 |1.78 |2.14 |11.2 |100 |2.65|2.76|0.26|1.28|4.380000|1.05|3.40|1050|
23 | |2 |1 |13.16 |2.36 |2.67 |18.6 |101 |2.80|3.24|0.30|2.81|5.680000|1.03|3.17|1185|
24 | |3 |1 |14.37 |1.95 |2.50 |16.8 |113 |3.85|3.49|0.24|2.18|7.800000|0.86|3.45|1480|
25 | |4 |1 |13.24 |2.59 |2.87 |21.0 |118 |2.80|2.69|0.39|1.82|4.320000|1.04|2.93|735|
26 | |5 |1 |14.20 |1.76 |2.45 |15.2 |112 |3.27|3.39|0.34|1.97|6.750000|1.05|2.85|1450|
27 | |...|...|...|...|...|...|...|...|...|...|...|...|...|...|...|
28 | |170|3|12.20|3.03|2.32|19.0|96 |1.25|0.49|0.40|0.73|5.500000 |0.66|1.83|510|
29 | |171|3|12.77|2.39|2.28|19.5|86 |1.39|0.51|0.48|0.64|9.899999 |0.57|1.63|470|
30 | |172|3|14.16|2.51|2.48|20.0|91 |1.68|0.70|0.44|1.24|9.700000 |0.62|1.71|660|
31 | |173|3|13.71|5.65|2.45|20.5|95 |1.68|0.61|0.52|1.06|7.700000 |0.64|1.74|740|
32 | |174|3|13.40|3.91|2.48|23.0|102|1.80|0.75|0.43|1.41|7.300000 |0.70|1.56|750|
33 | |175|3|13.27|4.28|2.26|20.0|120|1.59|0.69|0.43|1.35|10.200000 |0.59|1.56|835|
34 | |176|3|13.17|2.59|2.37|20.0|120|1.65|0.68|0.53|1.46|9.300000 |0.60|1.62|840|
35 | |177|3|14.13|4.10|2.74|24.5|96 |2.05|0.76|0.56|1.35|9.200000 |0.61|1.60|560|
36 |
37 |
38 |
39 | ### Brest Cancer Wisconsin データセット:(csvフォーマット)
40 |
41 | URL : https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/wdbc.data
42 |
43 | 悪性腫瘍細胞と良性腫瘍細胞の 569 個のサンプルが含まれている。 1 列目は固有の ID 、2 列目は悪性 [malignant] or 良性 [belign] を表すラベル、3 ~ 32 列目には、細胞核のデジタル画像から算出された 30 個の実数値の特徴量が含まれれいる。
44 |
45 | |行番号|ID|悪性(M)/良性(B)|1|2|3|4|5|6|7|8|...|22|23|24|25|26|27|28|29|30|
46 | |---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
47 | |1|842302 |M |17.990 |10.38 |122.80 |1001.0 |0.11840 |0.27760 |0.300100|0.147100|...|25.380|17.33| 184.60 |2019.0 |0.16220| 0.66560| 0.71190| 0.26540| 0.4601| 0.11890 |
48 | |2|842517 |M |20.570 |17.77 |132.90 |1326.0 |0.08474 |0.07864 |0.086900|0.147100|...|25.380| 17.33 |184.60 |2019.0 |0.16220 |0.66560|0.24160 |0.18600 |0.2750 |0.08902|
49 | |3|84300903 |M |19.690 |21.25 |130.00 |1203.0 |0.10960 |0.15990 |0.197400|0.127900 |...|23.570 |25.53 |152.50 |1709.0 |0.14440 |0.42450|0.45040 |0.24300 |0.3613 |0.08758|
50 | |...|
51 | |568|927241 |M |20.600 |29.33 |140.10 |1265.0 |0.11780 |0.27700 |0.351400|0.152000 |...|25.740 |39.42 |184.60 |1821.0 |0.16500 |0.86810|0.93870 |0.26500 |0.4087 |0.12400|
52 | |569|92751 |B |7.760 |24.54 |47.92 |181.0 |0.05263 |0.04362 |0.000000|0.000000|...|9.456 |30.37 |59.16 |268.6 |0.08996 |0.06444|0.00000 |0.00000 |0.2871 |0.07039|
53 |
54 |
55 |
56 | ### MNIST:(手書き数字文字画像データ)
57 |
58 | URL : http://yann.lecun.com/exdb/mnist/
59 |
60 | ### 渦巻きデータ:(csvフォーマット)
61 |
62 | URL : https://github.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/blob/master/EnsembleLearning_scikit-learn/data/naruto.csv
63 |
64 | 2クラス(0 or 1)識別問題用の渦巻状のデータ。
65 |
--------------------------------------------------------------------------------
/kNN_scikit-learn/README.md:
--------------------------------------------------------------------------------
1 | ## k-NN 法 [k-nearest neighbor algorithm]
2 |
3 | ### 項目 [Contents]
4 |
5 | 1. [使用するライブラリ](#使用するライブラリ)
6 | 1. [使用するデータセット](#使用するデータセット)
7 | 1. [コードの実行結果](#コードの実行結果)
8 | 1. [線形SVMによる3クラス(アヤメデータ)の識別問題](#線形SVMによる3クラス(アヤメデータ)の識別問題の実行結果)
9 | 1. [RBFカーネル関数を使用した2クラス(XORデータ分布)の識別問題](#RBFカーネル関数を使用した2クラス(XORデータ分布)の識別問題)
10 | 1. [RBFカーネル関数を使用した3クラス(アヤメデータ)の識別問題](#RBFカーネル関数を使用した3クラス(アヤメデータ)の識別問題)
11 | 1. [背景理論](#背景理論)
12 | 1. [最近傍法、k-NN 法の概要](#最近傍法、k-NN法の概要)
13 | 1. [最近傍法とボロノイ図](#最近傍法とボロノイ図)
14 | 1. [鋳型の数と識別性能](#鋳型の数と識別性能)
15 | 1. [k-NN 法](#k-NN法)
16 | 1. [k-NN 法での誤り発生のメカニズムとベイズの誤り率の関係](#k-NN法での誤り発生のメカニズムとベイズの誤り率の関係)
17 |
18 |
19 |
20 |
21 |
22 | ### 使用するライブラリ
23 |
24 | > scikit-learn ライブラリ
25 | >> データセット Dataset loading utilities : `sklearn.datasets`
26 | >> http://scikit-learn.org/stable/datasets/index.html
27 |
28 | >> モデル選択 : `sklearn.model_selection`
29 | >>> データの分割 : `sklearn.model_selection.train_test_split()`
30 | http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html
31 |
32 | >> 前処理 : `sklearn.preprocessing`
33 | >>> 正規化処理 : `sklearn.preprocessing.StandardScaler`
34 | http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html
35 |
36 | >> 正解率の算出 : `sklearn.metrics.accuracy_score`
37 | http://scikit-learn.org/stable/modules/generated/sklearn.metrics.accuracy_score.html
38 |
39 | >> k-NN 法 : `sklearn.neighbors.KNeighborsClassifier`
40 | sklearn.neighbors.KNeighborsClassifier
41 |
42 |
43 |
44 |
45 |
46 |
47 | ### 使用するデータセット
48 |
49 | > Iris データセット : `datasets.load_iris()`
50 |
51 |
52 |
53 | ## コードの実行結果
54 |
55 |
56 |
57 | ## 線形SVMによる3クラス(アヤメデータ)の識別問題 : `main1.py`
58 |
59 | - Iris データセットを使用 : `datasets.load_iris()`
60 | - 特徴行列 `X_features` は、特徴数 2 個 × サンプル数 150 個 : `iris.data[ :, [2,3] ]`
61 | - サンプル数 150 個の内、品種 "setosa" が 50 個、"virginica" が 50 個、"versicolor" が 50 個。
62 | - 教師データ `y_labels` は、サンプル数 150 個 : `y_labels = iris.target`
63 | - ここで、`iris.target` で取得したデータは、カテゴリーデータを 0, 1, 2 に変換したデータとなっている。
64 | - トレーニングデータ 70% 、テストデータ 30%の割合で分割 : `sklearn.cross_validation.train_test_split( test_size = 0.3, random_state = 0 )`
65 | - 正規化処理を実施 :
66 | `sklearn.preprocessing.StandardScaler` クラスを使用
67 | - モデルとして、それぞれハイパーパラメータの異なる3つの k-NN モデルを使用する。 (グリッドサーチによる最適なハイパーパラメータの検討は行わない):
68 | `kNN1 = KNeighborsClassifier( n_neighbors = 1, p = 2, metric = 'minkowski' )`
69 | `kNN2 = KNeighborsClassifier( n_neighbors = 5, p = 2, metric = 'minkowski' )`
70 | `kNN3 = KNeighborsClassifier( n_neighbors = 10, p = 2, metric = 'minkowski' )`
71 | - それらの k-NN モデルの fitting 処理でモデルを学習させる :
72 | `kNN1.fit( X_train_std, y_train )`
73 | `kNN2.fit( X_train_std, y_train )`
74 | `kNN3.fit( X_train_std, y_train )`
75 | - predict した結果 `y_predict = kNN.predict( X_test_std )` を元に、`accuracy_score()` 関数で、正解率、誤分類のサンプル数を算出。
76 | 正解率 : `accuracy_score( y_test, y_predict )`
77 | 誤分類数 : `( y_test != y_predict ).sum()`
78 | - `predict_proba()` 関数を使用して、指定したサンプルのクラスの所属関係を予想 :
79 | 例 : `kNN1.predict_proba( X_test_std[0, :].reshape(1, -1) )`
80 |
81 | 
82 |
83 | ---
84 |
85 |
86 |
87 | ## 背景理論
88 |
89 |
90 |
91 | ### 最近傍法、k-NN 法の概要
92 |
93 | 
94 |
95 |
96 |
97 | ### 最近傍法とボロノイ図
98 | 
99 | 
100 | 
101 |
102 |
103 |
104 | ### 鋳型の数と識別性能
105 | 
106 |
107 |
108 |
109 | ### k-NN 法
110 | 
111 | 
112 |
113 |
114 |
115 | ### k-NN 法での誤り発生のメカニズムとベイズの誤り率の関係
116 | 
117 | 
118 |
--------------------------------------------------------------------------------
/kNN_scikit-learn/img/twitter_パターン認識14-1_161007.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kNN_scikit-learn/img/twitter_パターン認識14-1_161007.png
--------------------------------------------------------------------------------
/kNN_scikit-learn/img/twitter_パターン認識14-2_161007.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kNN_scikit-learn/img/twitter_パターン認識14-2_161007.png
--------------------------------------------------------------------------------
/kNN_scikit-learn/img/twitter_パターン認識14-3_161008.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kNN_scikit-learn/img/twitter_パターン認識14-3_161008.png
--------------------------------------------------------------------------------
/kNN_scikit-learn/img/twitter_パターン認識14-4_161009.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kNN_scikit-learn/img/twitter_パターン認識14-4_161009.png
--------------------------------------------------------------------------------
/kNN_scikit-learn/img/twitter_パターン認識14-5_161010.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kNN_scikit-learn/img/twitter_パターン認識14-5_161010.png
--------------------------------------------------------------------------------
/kNN_scikit-learn/img/twitter_パターン認識16-1_161011.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kNN_scikit-learn/img/twitter_パターン認識16-1_161011.png
--------------------------------------------------------------------------------
/kNN_scikit-learn/img/twitter_パターン認識16-2_161012.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kNN_scikit-learn/img/twitter_パターン認識16-2_161012.png
--------------------------------------------------------------------------------
/kNN_scikit-learn/img/twitter_パターン認識16-5_161112.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kNN_scikit-learn/img/twitter_パターン認識16-5_161112.png
--------------------------------------------------------------------------------
/kNN_scikit-learn/img/twitter_パターン認識16-6_161112.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kNN_scikit-learn/img/twitter_パターン認識16-6_161112.png
--------------------------------------------------------------------------------
/kNN_scikit-learn/kNN_scikit-learn_1'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kNN_scikit-learn/kNN_scikit-learn_1'.png
--------------------------------------------------------------------------------
/kNN_scikit-learn/kNN_scikit-learn_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kNN_scikit-learn/kNN_scikit-learn_1.png
--------------------------------------------------------------------------------
/kNN_scikit-learn/kNN_scikit-learn_2'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kNN_scikit-learn/kNN_scikit-learn_2'.png
--------------------------------------------------------------------------------
/kNN_scikit-learn/kNN_scikit-learn_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kNN_scikit-learn/kNN_scikit-learn_2.png
--------------------------------------------------------------------------------
/kernelPCA_scikit-learn/Plot2D.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import matplotlib.pyplot as plt
4 | import numpy
5 | from matplotlib.colors import ListedColormap
6 |
7 | class Plot2D(object):
8 | """
9 | 2次元の図を描写をサポートする関数群からなるクラス
10 | """
11 |
12 | def __init__( self ):
13 | self.mainTitle = "mainTitle"
14 |
15 | @ staticmethod
16 | def drawDiscriminantRegions( dat_X, dat_y, classifier, list_test_idx = None, resolusion = 0.02 ):
17 | """ 識別器 [classifier] による識別領域を色分けで描写する """
18 |
19 | # 識別クラス数に対応したMAPの作成(最大5クラス対応)
20 | tuple_makers = ( "s","x","+","^","v" ) # タプル(定数リスト)
21 | tuple_colors = ( "red","blue","lightgreen", "gray", "cyan" ) # 塗りつぶす色を表すタプル(定数リスト)
22 | numClass = len( numpy.unique(dat_y) ) # numpy.unique() : 指定したarray変数の要素の重複をなくしたものを返す,更にlen() でユニークな値の数取得
23 | cmap = ListedColormap( tuple_colors[0:numClass] ) # plt.scatter() の引数で使用
24 |
25 | # plot the decision surface
26 | x1_min = dat_X[:, 0].min() - 1
27 | x1_max = dat_X[:, 0].max() + 1
28 | x2_min = dat_X[:, 1].min() - 1
29 | x2_max = dat_X[:, 1].max() + 1
30 |
31 | meshgrids = numpy.meshgrid( # マス目を作る ( 戻り値:numpy.ndarray )
32 | numpy.arange( x1_min, x1_max, resolusion ), # numpy.arang(): min~max by resolution
33 | numpy.arange( x2_min, x2_max, resolusion )
34 | )
35 | # 入力データ datX のx1軸、x2軸の値の全ての組み合わせ
36 | xx1 = meshgrids[0]
37 | xx2 = meshgrids[1]
38 |
39 | # ? 値の全ての組み合わせを1次元配列に変換 numpy.array( [xx1.ravel(), xx2.ravel()] ) し、
40 | # classifierに設定されている predict(予想)を実行
41 | Z = classifier.predict(
42 | numpy.array( [xx1.ravel(), xx2.ravel()] ).T
43 | )
44 | # ? 予測結果を元のグリッドポイントサイズに変換
45 | Z = Z.reshape( xx1.shape ) # numpy.ndarray の属性 shape は,各次元ごとの配列の大きさをまとめたタプルで指定
46 |
47 | # 等高線plotで識別領域を塗りつぶす
48 | plt.contourf( xx1, xx2, Z, alpha=0.4, cmap=cmap )
49 |
50 | # 図の軸の範囲指定
51 | plt.xlim( xx1.min(), xx1.max() )
52 | plt.ylim( xx2.min(), xx2.max() )
53 |
54 | # 識別クラス毎に、入力データ dat_X, dat_y の散布図 plot
55 | for (idx, cl) in enumerate( numpy.unique(dat_y) ): # enumerate():idx と共に clもloop
56 | plt.scatter(
57 | x = dat_X[dat_y == cl, 0],
58 | y = dat_X[dat_y == cl, 1],
59 | alpha = 0.8,
60 | c = cmap(idx),
61 | edgecolor = 'black',
62 | marker = tuple_makers[idx],
63 | label = cl
64 | )
65 |
66 | # テスト用サンプルデータを強調表示
67 | if (list_test_idx != None):
68 | X_test = dat_X[list_test_idx, :]
69 | y_test = dat_y[list_test_idx]
70 | plt.scatter(
71 | X_test[:, 0], X_test[:, 1],
72 | c='',
73 | alpha=1.0,
74 | edgecolor='black',
75 | linewidths=1,
76 | marker='o',
77 | s=55,
78 | label='test set'
79 | )
80 |
81 | # グラフ同士のラベルが重ならない程度にグラフを小さくする。
82 | plt.tight_layout()
83 |
84 | return
85 |
--------------------------------------------------------------------------------
/kernelPCA_scikit-learn/README.md:
--------------------------------------------------------------------------------
1 | ## カーネル主成分分析 [kernelPCA : kernel Principal Component Analysis] による非線形写像と教師なしデータの次元削除、特徴抽出
2 |
3 | 使用する scikit-learn ライブラリ:
4 |
5 | `sklearn.decomposition.KernelPCA` : http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.KernelPCA.html
6 |
7 | `sklearn.decomposition.PCA` : http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html
8 |
9 | ## コードの実行結果
10 |
11 | ### `main1.py`
12 |
13 | `sklearn.datasets.make_moons( n_samples = 100 )` で生成した半月状のデータ(サンプル数:100個)に対し、通常の PCA を適用した結果。
14 |
15 | 上段の図より、通常の PCA では、うまく線形分離可能なテータに変換できていないことが分かる。(※下段の図は、各主成分に対する固有値と寄与率、累積率寄与率の図)尚、第1主成分 PC1 のみに次元削除(特徴抽出)した図は、各クラス(0 or 1)の識別を見やすくするため、上下に少し移動させている。
16 |
17 | 
18 |
19 | `sklearn.datasets.make_moons( n_samples = 100 )` で生成した半月状のデータ(サンプル数:100個)に対し、RBF カーネルをカーネル関数とする、カーネル PCA を適用した結果。
20 | 上段の図より、RBFカーネルをカーネルとするkernelPCA では、この半月状のデータをうまく線形分離可能な特徴空間に写像出来ていることが分かる。(尚、第1主成分 PC1 のみに次元削除(特徴抽出)した図は、各クラス(0 or 1)の識別を見やすくするため、上下に少し移動させている。)
21 |
22 | 下段の図は、RBFカーネル関数のカーネル行列(グラム行列)の固有値を、大きい順に 40 個表示した図。カーネル行列の固有値は固有値分解を近似的な数値解析的手法で解いており、0 に近い値の固有値がこれに続いている。
23 |
24 | 
25 |
26 |
27 | `sklearn.datasets.make_circles( n_samples = 1000 )` で生成した同心円状のデータ(サンプル数:1000個)に対し、通常の PCA を適用した結果。
28 |
29 | 上段の図より、通常の PCA では、うまく線形分離可能なテータに変換できていないことが分かる。(※下段の図は、各主成分に対する固有値と寄与率、累積率寄与率の図)尚、第1主成分 PC1 のみに次元削除(特徴抽出)した図は、各クラス(0 or 1)の識別を見やすくするため、上下に少し移動させている。
30 |
31 | 
32 |
33 |
34 | `sklearn.datasets.make_circles( n_samples = 1000 )` で生成した同心円状のデータ(サンプル数:1000個)に対し、RBF カーネルをカーネル関数とする、カーネル PCA を適用した結果。
35 | 上段の図より、RBFカーネルをカーネルとするkernelPCA では、この半月状のデータをうまく線形分離可能な特徴空間に写像出来ていることが分かる。(尚、第1主成分 PC1 のみに次元削除(特徴抽出)した図は、各クラス(0 or 1)の識別を見やすくするため、上下に少し移動させている。)
36 |
37 | 
38 |
39 |
40 | ## Theory
41 |
42 | 
43 | 
44 | 
45 | 
46 |
--------------------------------------------------------------------------------
/kernelPCA_scikit-learn/img/twitter_PCA_2-1_170815.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kernelPCA_scikit-learn/img/twitter_PCA_2-1_170815.png
--------------------------------------------------------------------------------
/kernelPCA_scikit-learn/img/twitter_PCA_2-2_170815.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kernelPCA_scikit-learn/img/twitter_PCA_2-2_170815.png
--------------------------------------------------------------------------------
/kernelPCA_scikit-learn/img/twitter_PCA_2-3_170815.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kernelPCA_scikit-learn/img/twitter_PCA_2-3_170815.png
--------------------------------------------------------------------------------
/kernelPCA_scikit-learn/img/twitter_PCA_2-4_170815.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kernelPCA_scikit-learn/img/twitter_PCA_2-4_170815.png
--------------------------------------------------------------------------------
/kernelPCA_scikit-learn/kernelPCA_scikit-learn_1'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kernelPCA_scikit-learn/kernelPCA_scikit-learn_1'.png
--------------------------------------------------------------------------------
/kernelPCA_scikit-learn/kernelPCA_scikit-learn_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kernelPCA_scikit-learn/kernelPCA_scikit-learn_1.png
--------------------------------------------------------------------------------
/kernelPCA_scikit-learn/kernelPCA_scikit-learn_2'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kernelPCA_scikit-learn/kernelPCA_scikit-learn_2'.png
--------------------------------------------------------------------------------
/kernelPCA_scikit-learn/kernelPCA_scikit-learn_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kernelPCA_scikit-learn/kernelPCA_scikit-learn_2.png
--------------------------------------------------------------------------------
/kernelPCA_scikit-learn/kernelPCA_scikit-learn_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kernelPCA_scikit-learn/kernelPCA_scikit-learn_3.png
--------------------------------------------------------------------------------
/kernelPCA_scikit-learn/kernelPCA_scikit-learn_4'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kernelPCA_scikit-learn/kernelPCA_scikit-learn_4'.png
--------------------------------------------------------------------------------
/kernelPCA_scikit-learn/kernelPCA_scikit-learn_5'.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yagami360/MachineLearning_Exercises_Python_scikit-learn/ac62026d6bb96b0ee7d9b81c9b7784809b5efae1/kernelPCA_scikit-learn/kernelPCA_scikit-learn_5'.png
--------------------------------------------------------------------------------