Skip to content

Commit

Permalink
demonstrate SVM smoothing sin
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemGr committed Jul 27, 2024
1 parent e59ed79 commit 8c611da
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
30 changes: 30 additions & 0 deletions data/math/svm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python

def sin():
"""demonstrate SVM smoothing sin"""
import libsvm.svmutil as svm # https://github.com/cjlin1/libsvm
import math
import matplotlib.pyplot as plt
import numpy as np

samples, fold = 100, 50
x = np.linspace (0, 6 * np.pi, samples)
features = list (map (lambda x: [x], x)) # [x1, x2, x3, ..] to [[x1], [x2], [x3], ..]
labels = list (map (lambda x: math.sin (x), x))
plt.subplot (2, 1, 1)
plt.plot (x, labels, label= 'sin')
plt.legend()
plt.grid (True)

prob = svm.svm_problem (labels[:fold], features[:fold])
m = svm.svm_train (prob, '-s 3 -t 2 -q') # epsilon RBF
y, _acc, _vals = svm.svm_predict (labels, features, m, '-q')
plt.subplot (2, 1, 2)
plt.plot (x, y, label= 'svm')
plt.legend()
plt.grid (True)
plt.gcf().canvas.manager.set_window_title ('sin')
plt.tight_layout()
plt.show()

sin()
4 changes: 3 additions & 1 deletion data/math/xgboost-.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ def perfect_symmetry():
ax.plot_trisurf(X[:, 0], X[:, 1], y_mul, cmap='viridis')

dtrain = xgb.DMatrix(X, label=y_mul)
params = {'tree_method': 'gpu_hist'}
params = {
#'tree_method': 'gpu_hist'
}
bst = xgb.train(params, dtrain, evals=[(dtrain, 'train')], num_boost_round=10)
y_pred = bst.predict(dtrain)

Expand Down

0 comments on commit 8c611da

Please sign in to comment.