[go: nahoru, domu]

Skip to content

Commit

Permalink
update file header.
Browse files Browse the repository at this point in the history
  • Loading branch information
luokn committed Nov 22, 2022
1 parent 00c3e1c commit 335ed0a
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 45 deletions.
18 changes: 11 additions & 7 deletions src/adaboost.py
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 : olooook@outlook.com
# @File : adaboost.py
# @Data : 2020/5/27
# @Author : Luo Kun
# @Contact: luokun485@gmail.com

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): 弱分类器个数.
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/decision_tree.py
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 : olooook@outlook.com
# @File : decision_tree.py
# @Data : 2020/5/23
# @Author : Luo Kun
# @Contact: luokun485@gmail.com

import numpy as np

Expand Down
8 changes: 5 additions & 3 deletions src/em.py
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 : olooook@outlook.com
# @File : em.py
# @Data : 2020/5/27
# @Author : Luo Kun
# @Contact: luokun485@gmail.com

import numpy as np

Expand Down
8 changes: 5 additions & 3 deletions src/gmm.py
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 : olooook@outlook.com
# @File : gmm.py
# @Data : 2020/5/31
# @Author : Luo Kun
# @Contact: luokun485@gmail.com

import random

Expand Down
8 changes: 5 additions & 3 deletions src/kmeans.py
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 : olooook@outlook.com
# @File : kmeans.py
# @Data : 2020/5/21
# @Author : Luo Kun
# @Contact: luokun485@gmail.com

import random

Expand Down
8 changes: 5 additions & 3 deletions src/knn.py
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 : olooook@outlook.com
# @File : knn.py
# @Data : 2020/5/20
# @Author : Luo Kun
# @Contact: luokun485@gmail.com

import numpy as np
from matplotlib import pyplot as plt
Expand Down
8 changes: 5 additions & 3 deletions src/lda.py
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 : olooook@outlook.com
# @File : lda.py
# @Data : 2020/5/31
# @Author : Luo Kun
# @Contact: luokun485@gmail.com

import numpy as np
from matplotlib import pyplot as plt
Expand Down
8 changes: 5 additions & 3 deletions src/logistic_regression.py
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 : olooook@outlook.com
# @File : logistic_regression.py
# @Data : 2020/5/21
# @Author : Luo Kun
# @Contact: luokun485@gmail.com

import numpy as np
from matplotlib import pyplot as plt
Expand Down
8 changes: 5 additions & 3 deletions src/naive_bayes.py
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 : olooook@outlook.com
# @File : naive_bayes.py
# @Data : 2020/5/22
# @Author : Luo Kun
# @Contact: luokun485@gmail.com

import numpy as np

Expand Down
8 changes: 5 additions & 3 deletions src/pca.py
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 : olooook@outlook.com
# @File : pca.py
# @Data : 2020/5/20
# @Author : Luo Kun
# @Contact: luokun485@gmail.com

import numpy as np
from matplotlib import pyplot as plt
Expand Down
8 changes: 5 additions & 3 deletions src/perceptron.py
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 : olooook@outlook.com
# @File : perceptron.py
# @Data : 2020/5/20
# @Author : Luo Kun
# @Contact: luokun485@gmail.com

import numpy as np
from matplotlib import pyplot as plt
Expand Down
8 changes: 5 additions & 3 deletions src/svm.py
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 : olooook@outlook.com
# @File : svm.py
# @Data : 2020/5/23
# @Author : Luo Kun
# @Contact: luokun485@gmail.com

import numpy as np
from matplotlib import pyplot as plt
Expand Down
10 changes: 5 additions & 5 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/python3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @File : utils.py
# @Time : 2022/05/18 15:11:16
# @Author: Kun Luo
# @Email : olooook@outlook.com
# @File : utils.py
# @Data : 2022/05/18
# @Author : Luo Kun
# @Contact: luokun485@gmail.com

from typing import List, Optional

Expand Down

0 comments on commit 335ed0a

Please sign in to comment.