-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
71 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# @Date : 2020/5/27 | ||
# @Author: Luokun | ||
# @Email : [email protected] | ||
# @File : adaboost.py | ||
# @Data : 2020/5/27 | ||
# @Author : Luo Kun | ||
# @Contact: [email protected] | ||
|
||
import numpy as np | ||
from matplotlib import pyplot as plt | ||
|
||
|
||
class AdaBoost: | ||
|
||
def __init__(self, n_estimators: int, lr=1e-2, eps=1e-5): | ||
def __init__(self, n_estimators: int, lr: float = 1e-2, eps: float = 1e-5): | ||
""" | ||
Args: | ||
n_estimators (int): 弱分类器个数. | ||
|
@@ -53,17 +55,19 @@ def __call__(self, X: np.ndarray) -> np.ndarray: | |
|
||
class WeakEstimator: # 弱分类器, 一阶决策树 | ||
|
||
def __init__(self, lr: float): | ||
self.lr, self.feature, self.threshold, self.sign = lr, None, None, None # 划分特征、划分阈值,符号{-1,1} | ||
def __init__(self, lr: float = 1e-3): | ||
# 学习率、符号{-1,1}、划分特征、划分阈值 | ||
self.lr, self.sign, self.feature, self.threshold, = lr, 1, None, None | ||
|
||
def fit(self, X: np.ndarray, y: np.ndarray, weights: np.ndarray): | ||
min_error = float("inf") # 最小带权误差 | ||
min_error = np.inf # 最小带权误差 | ||
for feature, x in enumerate(X.T): | ||
for threshold in np.arange(np.min(x) - self.lr, np.max(x) + self.lr, self.lr): | ||
# 取分类错误的样本权重求和 | ||
pos_error = np.sum(weights[np.where(x > threshold, 1, -1) != y]) | ||
if pos_error < min_error: | ||
min_error, self.feature, self.threshold, self.sign = pos_error, feature, threshold, 1 | ||
|
||
neg_error = 1 - pos_error | ||
if neg_error < min_error: | ||
min_error, self.feature, self.threshold, self.sign = neg_error, feature, threshold, -1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# @Date : 2020/5/23 | ||
# @Author: Luokun | ||
# @Email : [email protected] | ||
# @File : decision_tree.py | ||
# @Data : 2020/5/23 | ||
# @Author : Luo Kun | ||
# @Contact: [email protected] | ||
|
||
import numpy as np | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# @Date : 2020/5/27 | ||
# @Author: Luokun | ||
# @Email : [email protected] | ||
# @File : em.py | ||
# @Data : 2020/5/27 | ||
# @Author : Luo Kun | ||
# @Contact: [email protected] | ||
|
||
import numpy as np | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# @Date : 2020/5/31 | ||
# @Author: Luokun | ||
# @Email : [email protected] | ||
# @File : gmm.py | ||
# @Data : 2020/5/31 | ||
# @Author : Luo Kun | ||
# @Contact: [email protected] | ||
|
||
import random | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# @Date : 2020/5/21 | ||
# @Author: Luokun | ||
# @Email : [email protected] | ||
# @File : kmeans.py | ||
# @Data : 2020/5/21 | ||
# @Author : Luo Kun | ||
# @Contact: [email protected] | ||
|
||
import random | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# @Date : 2020/5/20 | ||
# @Author: Luokun | ||
# @Email : [email protected] | ||
# @File : knn.py | ||
# @Data : 2020/5/20 | ||
# @Author : Luo Kun | ||
# @Contact: [email protected] | ||
|
||
import numpy as np | ||
from matplotlib import pyplot as plt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# @Date : 2020/5/31 | ||
# @Author: Luokun | ||
# @Email : [email protected] | ||
# @File : lda.py | ||
# @Data : 2020/5/31 | ||
# @Author : Luo Kun | ||
# @Contact: [email protected] | ||
|
||
import numpy as np | ||
from matplotlib import pyplot as plt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# @Date : 2020/5/21 | ||
# @Author: Luokun | ||
# @Email : [email protected] | ||
# @File : logistic_regression.py | ||
# @Data : 2020/5/21 | ||
# @Author : Luo Kun | ||
# @Contact: [email protected] | ||
|
||
import numpy as np | ||
from matplotlib import pyplot as plt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# @Date : 2020/5/22 | ||
# @Author: Luokun | ||
# @Email : [email protected] | ||
# @File : naive_bayes.py | ||
# @Data : 2020/5/22 | ||
# @Author : Luo Kun | ||
# @Contact: [email protected] | ||
|
||
import numpy as np | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# @Date : 2020/5/20 | ||
# @Author: Luokun | ||
# @Email : [email protected] | ||
# @File : pca.py | ||
# @Data : 2020/5/20 | ||
# @Author : Luo Kun | ||
# @Contact: [email protected] | ||
|
||
import numpy as np | ||
from matplotlib import pyplot as plt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# @Date : 2020/5/20 | ||
# @Author: Luokun | ||
# @Email : [email protected] | ||
# @File : perceptron.py | ||
# @Data : 2020/5/20 | ||
# @Author : Luo Kun | ||
# @Contact: [email protected] | ||
|
||
import numpy as np | ||
from matplotlib import pyplot as plt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# @Date : 2020/5/23 | ||
# @Author: Luokun | ||
# @Email : [email protected] | ||
# @File : svm.py | ||
# @Data : 2020/5/23 | ||
# @Author : Luo Kun | ||
# @Contact: [email protected] | ||
|
||
import numpy as np | ||
from matplotlib import pyplot as plt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters