From 8c611da3afd7bb9e3c114e978b6fc2e1a0604250 Mon Sep 17 00:00:00 2001 From: Artemciy Date: Sat, 27 Jul 2024 18:11:56 +0300 Subject: [PATCH] demonstrate SVM smoothing sin --- data/math/svm.py | 30 ++++++++++++++++++++++++++++++ data/math/xgboost-.py | 4 +++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 data/math/svm.py diff --git a/data/math/svm.py b/data/math/svm.py new file mode 100644 index 0000000..6508754 --- /dev/null +++ b/data/math/svm.py @@ -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() diff --git a/data/math/xgboost-.py b/data/math/xgboost-.py index 6a1d6d6..2b0f7e6 100644 --- a/data/math/xgboost-.py +++ b/data/math/xgboost-.py @@ -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)