[go: nahoru, domu]

Skip to content

Commit

Permalink
简化,修复
Browse files Browse the repository at this point in the history
  • Loading branch information
Kun Luo committed Jul 21, 2021
1 parent db17836 commit 8ee7f46
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions AdaBoost/adaboost.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def load_data():
x, y = load_data()
plt.figure(figsize=[12, 6])
plt.subplot(1, 2, 1)
plt.title('Real')
plt.title('Truth')
plt.scatter(x[0, :, 0], x[0, :, 1], color='r', marker='.')
plt.scatter(x[1, :, 0], x[1, :, 1], color='g', marker='.')

Expand All @@ -85,7 +85,7 @@ def load_data():

x0, x1 = x[pred == -1], x[pred == 1]
plt.subplot(1, 2, 2)
plt.title('Pred')
plt.title('Prediction')
plt.scatter(x0[:, 0], x0[:, 1], color='r', marker='.')
plt.scatter(x1[:, 0], x1[:, 1], color='g', marker='.')
plt.show()
4 changes: 2 additions & 2 deletions GMM/gmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def load_data():
x = load_data()
plt.figure(figsize=[12, 6])
plt.subplot(1, 2, 1)
plt.title('Real')
plt.title('Truth')
plt.scatter(x[0, :, 0], x[0, :, 1], color='r', marker='.')
plt.scatter(x[1, :, 0], x[1, :, 1], color='g', marker='.')

Expand All @@ -82,7 +82,7 @@ def load_data():

x0, x1 = x[pred == 0], x[pred == 1]
plt.subplot(1, 2, 2)
plt.title('Pred')
plt.title('Prediction')
plt.scatter(x0[:, 0], x0[:, 1], color='r', marker='.')
plt.scatter(x1[:, 0], x1[:, 1], color='g', marker='.')
plt.show()
4 changes: 2 additions & 2 deletions KMeans/kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def load_data():
x = load_data()
plt.figure(figsize=[12, 6])
plt.subplot(1, 2, 1)
plt.title('Real')
plt.title('Truth')
plt.scatter(x[0, :, 0], x[0, :, 1], color='r', marker='.')
plt.scatter(x[1, :, 0], x[1, :, 1], color='g', marker='.')
plt.scatter(x[2, :, 0], x[2, :, 1], color='b', marker='.')
Expand All @@ -64,7 +64,7 @@ def load_data():

x0, x1, x2 = x[pred == 0], x[pred == 1], x[pred == 2]
plt.subplot(1, 2, 2)
plt.title('Pred')
plt.title('Prediction')
plt.scatter(x0[:, 0], x0[:, 1], color='r', marker='.')
plt.scatter(x1[:, 0], x1[:, 1], color='g', marker='.')
plt.scatter(x2[:, 0], x2[:, 1], color='b', marker='.')
Expand Down
4 changes: 2 additions & 2 deletions KNN/knn.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def load_data():

plt.figure(figsize=[12, 6])
plt.subplot(1, 2, 1)
plt.title('Real')
plt.title('Truth')
plt.scatter(x[0, :, 0], x[0, :, 1], color='r', marker='.')
plt.scatter(x[1, :, 0], x[1, :, 1], color='g', marker='.')
plt.scatter(x[2, :, 0], x[2, :, 1], color='b', marker='.')
Expand All @@ -59,7 +59,7 @@ def load_data():

x0, x1, x2 = x[pred == 0], x[pred == 1], x[pred == 2]
plt.subplot(1, 2, 2)
plt.title('Pred')
plt.title('Prediction')
plt.scatter(x0[:, 0], x0[:, 1], color='r', marker='.')
plt.scatter(x1[:, 0], x1[:, 1], color='g', marker='.')
plt.scatter(x2[:, 0], x2[:, 1], color='b', marker='.')
Expand Down
4 changes: 2 additions & 2 deletions LDA/lda.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# @Email : olooook@outlook.com

import numpy as np
from numpy import linalg as LA
from matplotlib import pyplot as plt
from numpy import linalg as LA


class LDA:
Expand Down Expand Up @@ -72,7 +72,7 @@ def load_data():
x, y = load_data()
plt.figure(figsize=[18, 6])
plt.subplot(1, 3, 1)
plt.title('Real')
plt.title('Truth')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.scatter(x[0, :, 0], x[0, :, 1], color='r', marker='.')
Expand Down
4 changes: 2 additions & 2 deletions LogisticRegression/logistic_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def train_logistic_regression(model, x, y, epochs, batch_size=32):
x, y = load_data()
plt.figure(figsize=[12, 6])
plt.subplot(1, 2, 1)
plt.title('Real')
plt.title('Truth')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.scatter(x[0, :, 0], x[0, :, 1], color='r', marker='.')
Expand All @@ -74,7 +74,7 @@ def train_logistic_regression(model, x, y, epochs, batch_size=32):

x0, x1 = x[pred == 0], x[pred == 1]
plt.subplot(1, 2, 2)
plt.title('Pred')
plt.title('Prediction')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.scatter(x0[:, 0], x0[:, 1], color='r', marker='.')
Expand Down
2 changes: 1 addition & 1 deletion PCA/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def load_data():
x0, x1, x2 = x.reshape(3, -1, 2)
plt.figure(figsize=[15, 5])
plt.subplot(1, 3, 1)
plt.title('Real')
plt.title('Truth')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.scatter(x0[:, 0], x0[:, 1], color='r', marker='.')
Expand Down
4 changes: 2 additions & 2 deletions Perceptron/perceptron.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def train_perceptron(model, x, y, epochs):
x, y = load_data()
plt.figure(figsize=[12, 6])
plt.subplot(1, 2, 1)
plt.title('Real')
plt.title('Truth')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.scatter(x[0, :, 0], x[0, :, 1], color='r', marker='.')
Expand All @@ -69,7 +69,7 @@ def train_perceptron(model, x, y, epochs):

x0, x1 = x[pred == -1], x[pred == 1]
plt.subplot(1, 2, 2)
plt.title('Pred')
plt.title('Prediction')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.scatter(x0[:, 0], x0[:, 1], color='r', marker='.')
Expand Down
6 changes: 3 additions & 3 deletions SVM/svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, C=1.0, kernel='linear', iterations=100, tol=1e-3, **kwargs):

def fit(self, X: np.ndarray, Y: np.ndarray):
self.X, self.Y = X, Y
self.alpha = np.ones([len(X)], dtype=np.float) # 拉格朗日乘子
self.alpha = np.ones([len(X)]) # 拉格朗日乘子
for _ in range(self.iterations):
E = np.array([self._calc_error(i) for i in range(len(X))]) # 此次迭代缓存的误差
for i1 in range(len(X)): # 外层循环,寻找第一个alpha
Expand Down Expand Up @@ -134,7 +134,7 @@ def load_data():
x, y = load_data()
plt.figure(figsize=[18, 6])
plt.subplot(1, 3, 1)
plt.title('Real')
plt.title('Truth')
plt.xlim(-7, 7)
plt.ylim(-7, 7)
plt.scatter(x[0, :, 0], x[0, :, 1], color='r', marker='.')
Expand All @@ -149,7 +149,7 @@ def load_data():

x0, x1 = x[pred == -1], x[pred == 1]
plt.subplot(1, 3, 2)
plt.title('Pred')
plt.title('Prediction')
plt.xlim(-7, 7)
plt.ylim(-7, 7)
plt.scatter(x0[:, 0], x0[:, 1], color='r', marker='.')
Expand Down

0 comments on commit 8ee7f46

Please sign in to comment.