minimatrix 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- minimatrix-0.1.1/LICENSE +21 -0
- minimatrix-0.1.1/PKG-INFO +123 -0
- minimatrix-0.1.1/README.md +82 -0
- minimatrix-0.1.1/minimatrix/__init__.py +3 -0
- minimatrix-0.1.1/minimatrix/mdts/__init__.py +60 -0
- minimatrix-0.1.1/minimatrix/mdts/adv_reg/__init__.py +13 -0
- minimatrix-0.1.1/minimatrix/mdts/adv_reg/bin_smoother.py +128 -0
- minimatrix-0.1.1/minimatrix/mdts/adv_reg/kernel_smoother.py +233 -0
- minimatrix-0.1.1/minimatrix/mdts/adv_reg/knn_smoother.py +168 -0
- minimatrix-0.1.1/minimatrix/mdts/adv_reg/lowess.py +247 -0
- minimatrix-0.1.1/minimatrix/mdts/adv_reg/lwr.py +215 -0
- minimatrix-0.1.1/minimatrix/mdts/machine_learning/__init__.py +30 -0
- minimatrix-0.1.1/minimatrix/mdts/machine_learning/bagging_classifier.py +190 -0
- minimatrix-0.1.1/minimatrix/mdts/machine_learning/bagging_regressor.py +148 -0
- minimatrix-0.1.1/minimatrix/mdts/machine_learning/decision_tree_classifier.py +256 -0
- minimatrix-0.1.1/minimatrix/mdts/machine_learning/decision_tree_regressor.py +218 -0
- minimatrix-0.1.1/minimatrix/mdts/machine_learning/indexing.py +37 -0
- minimatrix-0.1.1/minimatrix/mdts/machine_learning/kmeans_clustering.py +129 -0
- minimatrix-0.1.1/minimatrix/mdts/machine_learning/knn_classifier.py +249 -0
- minimatrix-0.1.1/minimatrix/mdts/machine_learning/knn_regressor.py +182 -0
- minimatrix-0.1.1/minimatrix/mdts/machine_learning/naive_bayes.py +2 -0
- minimatrix-0.1.1/minimatrix/mdts/machine_learning/random_forest_classifier.py +356 -0
- minimatrix-0.1.1/minimatrix/mdts/machine_learning/random_forest_regressor.py +238 -0
- minimatrix-0.1.1/minimatrix/mdts/machine_learning/support_vector_classifier.py +186 -0
- minimatrix-0.1.1/minimatrix/mdts/machine_learning/support_vector_regressor.py +191 -0
- minimatrix-0.1.1/minimatrix/mdts/optimization/__init__.py +20 -0
- minimatrix-0.1.1/minimatrix/mdts/optimization/conjugate_gradient_with_direction.py +185 -0
- minimatrix-0.1.1/minimatrix/mdts/optimization/conjugate_gradient_without_direction.py +165 -0
- minimatrix-0.1.1/minimatrix/mdts/optimization/fibonacci_method.py +126 -0
- minimatrix-0.1.1/minimatrix/mdts/optimization/golden_section.py +159 -0
- minimatrix-0.1.1/minimatrix/mdts/optimization/newton_method.py +153 -0
- minimatrix-0.1.1/minimatrix/mdts/optimization/quassi_newton.py +232 -0
- minimatrix-0.1.1/minimatrix/mdts/optimization/quassi_newton_documentation.py +110 -0
- minimatrix-0.1.1/minimatrix/mdts/optimization/steepest_descent.py +173 -0
- minimatrix-0.1.1/minimatrix/optimizer/__init__.py +60 -0
- minimatrix-0.1.1/minimatrix/optimizer/adv_reg/__init__.py +13 -0
- minimatrix-0.1.1/minimatrix/optimizer/adv_reg/bin_smoother.py +128 -0
- minimatrix-0.1.1/minimatrix/optimizer/adv_reg/kernel_smoother.py +233 -0
- minimatrix-0.1.1/minimatrix/optimizer/adv_reg/knn_smoother.py +168 -0
- minimatrix-0.1.1/minimatrix/optimizer/adv_reg/lowess.py +247 -0
- minimatrix-0.1.1/minimatrix/optimizer/adv_reg/lwr.py +215 -0
- minimatrix-0.1.1/minimatrix/optimizer/machine_learning/__init__.py +30 -0
- minimatrix-0.1.1/minimatrix/optimizer/machine_learning/bagging_classifier.py +190 -0
- minimatrix-0.1.1/minimatrix/optimizer/machine_learning/bagging_regressor.py +148 -0
- minimatrix-0.1.1/minimatrix/optimizer/machine_learning/decision_tree_classifier.py +256 -0
- minimatrix-0.1.1/minimatrix/optimizer/machine_learning/decision_tree_regressor.py +218 -0
- minimatrix-0.1.1/minimatrix/optimizer/machine_learning/indexing.py +37 -0
- minimatrix-0.1.1/minimatrix/optimizer/machine_learning/kmeans_clustering.py +129 -0
- minimatrix-0.1.1/minimatrix/optimizer/machine_learning/knn_classifier.py +249 -0
- minimatrix-0.1.1/minimatrix/optimizer/machine_learning/knn_regressor.py +182 -0
- minimatrix-0.1.1/minimatrix/optimizer/machine_learning/naive_bayes.py +2 -0
- minimatrix-0.1.1/minimatrix/optimizer/machine_learning/random_forest_classifier.py +356 -0
- minimatrix-0.1.1/minimatrix/optimizer/machine_learning/random_forest_regressor.py +238 -0
- minimatrix-0.1.1/minimatrix/optimizer/machine_learning/support_vector_classifier.py +186 -0
- minimatrix-0.1.1/minimatrix/optimizer/machine_learning/support_vector_regressor.py +191 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/__init__.py +60 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/adv_reg/__init__.py +13 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/adv_reg/bin_smoother.py +128 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/adv_reg/kernel_smoother.py +233 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/adv_reg/knn_smoother.py +168 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/adv_reg/lowess.py +247 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/adv_reg/lwr.py +215 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/machine_learning/__init__.py +30 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/machine_learning/bagging_classifier.py +190 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/machine_learning/bagging_regressor.py +148 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/machine_learning/decision_tree_classifier.py +256 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/machine_learning/decision_tree_regressor.py +218 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/machine_learning/indexing.py +37 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/machine_learning/kmeans_clustering.py +129 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/machine_learning/knn_classifier.py +249 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/machine_learning/knn_regressor.py +182 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/machine_learning/naive_bayes.py +2 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/machine_learning/random_forest_classifier.py +356 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/machine_learning/random_forest_regressor.py +238 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/machine_learning/support_vector_classifier.py +186 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/machine_learning/support_vector_regressor.py +191 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/optimization/__init__.py +20 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/optimization/conjugate_gradient_with_direction.py +185 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/optimization/conjugate_gradient_without_direction.py +165 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/optimization/fibonacci_method.py +126 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/optimization/golden_section.py +159 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/optimization/newton_method.py +153 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/optimization/quassi_newton.py +232 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/optimization/quassi_newton_documentation.py +110 -0
- minimatrix-0.1.1/minimatrix/optimizer/mdts/optimization/steepest_descent.py +173 -0
- minimatrix-0.1.1/minimatrix/optimizer/optimization/__init__.py +20 -0
- minimatrix-0.1.1/minimatrix/optimizer/optimization/conjugate_gradient_with_direction.py +185 -0
- minimatrix-0.1.1/minimatrix/optimizer/optimization/conjugate_gradient_without_direction.py +165 -0
- minimatrix-0.1.1/minimatrix/optimizer/optimization/fibonacci_method.py +126 -0
- minimatrix-0.1.1/minimatrix/optimizer/optimization/golden_section.py +159 -0
- minimatrix-0.1.1/minimatrix/optimizer/optimization/newton_method.py +153 -0
- minimatrix-0.1.1/minimatrix/optimizer/optimization/quassi_newton.py +232 -0
- minimatrix-0.1.1/minimatrix/optimizer/optimization/quassi_newton_documentation.py +110 -0
- minimatrix-0.1.1/minimatrix/optimizer/optimization/steepest_descent.py +173 -0
- minimatrix-0.1.1/minimatrix/sxc/__init__.py +3 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/__init__.py +60 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/adv_reg/__init__.py +13 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/adv_reg/bin_smoother.py +128 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/adv_reg/kernel_smoother.py +233 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/adv_reg/knn_smoother.py +168 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/adv_reg/lowess.py +247 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/adv_reg/lwr.py +215 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/machine_learning/__init__.py +30 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/machine_learning/bagging_classifier.py +190 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/machine_learning/bagging_regressor.py +148 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/machine_learning/decision_tree_classifier.py +256 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/machine_learning/decision_tree_regressor.py +218 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/machine_learning/indexing.py +37 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/machine_learning/kmeans_clustering.py +129 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/machine_learning/knn_classifier.py +249 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/machine_learning/knn_regressor.py +182 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/machine_learning/naive_bayes.py +2 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/machine_learning/random_forest_classifier.py +356 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/machine_learning/random_forest_regressor.py +238 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/machine_learning/support_vector_classifier.py +186 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/machine_learning/support_vector_regressor.py +191 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/optimization/__init__.py +20 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/optimization/conjugate_gradient_with_direction.py +185 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/optimization/conjugate_gradient_without_direction.py +165 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/optimization/fibonacci_method.py +126 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/optimization/golden_section.py +159 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/optimization/newton_method.py +153 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/optimization/quassi_newton.py +232 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/optimization/quassi_newton_documentation.py +110 -0
- minimatrix-0.1.1/minimatrix/sxc/mdts/optimization/steepest_descent.py +173 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/__init__.py +60 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/adv_reg/__init__.py +13 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/adv_reg/bin_smoother.py +128 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/adv_reg/kernel_smoother.py +233 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/adv_reg/knn_smoother.py +168 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/adv_reg/lowess.py +247 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/adv_reg/lwr.py +215 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/machine_learning/__init__.py +30 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/machine_learning/bagging_classifier.py +190 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/machine_learning/bagging_regressor.py +148 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/machine_learning/decision_tree_classifier.py +256 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/machine_learning/decision_tree_regressor.py +218 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/machine_learning/indexing.py +37 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/machine_learning/kmeans_clustering.py +129 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/machine_learning/knn_classifier.py +249 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/machine_learning/knn_regressor.py +182 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/machine_learning/naive_bayes.py +2 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/machine_learning/random_forest_classifier.py +356 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/machine_learning/random_forest_regressor.py +238 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/machine_learning/support_vector_classifier.py +186 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/machine_learning/support_vector_regressor.py +191 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/__init__.py +60 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/adv_reg/__init__.py +13 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/adv_reg/bin_smoother.py +128 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/adv_reg/kernel_smoother.py +233 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/adv_reg/knn_smoother.py +168 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/adv_reg/lowess.py +247 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/adv_reg/lwr.py +215 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/machine_learning/__init__.py +30 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/machine_learning/bagging_classifier.py +190 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/machine_learning/bagging_regressor.py +148 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/machine_learning/decision_tree_classifier.py +256 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/machine_learning/decision_tree_regressor.py +218 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/machine_learning/indexing.py +37 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/machine_learning/kmeans_clustering.py +129 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/machine_learning/knn_classifier.py +249 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/machine_learning/knn_regressor.py +182 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/machine_learning/naive_bayes.py +2 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/machine_learning/random_forest_classifier.py +356 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/machine_learning/random_forest_regressor.py +238 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/machine_learning/support_vector_classifier.py +186 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/machine_learning/support_vector_regressor.py +191 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/optimization/__init__.py +20 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/optimization/conjugate_gradient_with_direction.py +185 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/optimization/conjugate_gradient_without_direction.py +165 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/optimization/fibonacci_method.py +126 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/optimization/golden_section.py +159 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/optimization/newton_method.py +153 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/optimization/quassi_newton.py +232 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/optimization/quassi_newton_documentation.py +110 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/mdts/optimization/steepest_descent.py +173 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/optimization/__init__.py +20 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/optimization/conjugate_gradient_with_direction.py +185 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/optimization/conjugate_gradient_without_direction.py +165 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/optimization/fibonacci_method.py +126 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/optimization/golden_section.py +159 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/optimization/newton_method.py +153 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/optimization/quassi_newton.py +232 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/optimization/quassi_newton_documentation.py +110 -0
- minimatrix-0.1.1/minimatrix/sxc/optimizer/optimization/steepest_descent.py +173 -0
- minimatrix-0.1.1/minimatrix.egg-info/PKG-INFO +123 -0
- minimatrix-0.1.1/minimatrix.egg-info/SOURCES.txt +191 -0
- minimatrix-0.1.1/minimatrix.egg-info/dependency_links.txt +1 -0
- minimatrix-0.1.1/minimatrix.egg-info/requires.txt +6 -0
- minimatrix-0.1.1/minimatrix.egg-info/top_level.txt +1 -0
- minimatrix-0.1.1/pyproject.toml +28 -0
- minimatrix-0.1.1/setup.cfg +4 -0
- minimatrix-0.1.1/setup.py +11 -0
minimatrix-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Suchibrata Patra
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: minimatrix
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: For academic and educational use under St. Xavier's College only.
|
|
5
|
+
Author: Suchibrata Patra
|
|
6
|
+
Author-email: SXC_Student_developer_Community <suchibratapatra2003@gmail.com>
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2025 Suchibrata Patra
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
Keywords: machine-learning,classification,regression,data-science,automated-ml
|
|
29
|
+
Requires-Python: >=3.7
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Requires-Dist: numpy<3.0,>=1.23
|
|
33
|
+
Requires-Dist: pandas>=1.5
|
|
34
|
+
Requires-Dist: scikit-learn>=1.2
|
|
35
|
+
Requires-Dist: matplotlib>=3.7
|
|
36
|
+
Requires-Dist: seaborn>=0.12
|
|
37
|
+
Requires-Dist: plotly>=5.0
|
|
38
|
+
Dynamic: author
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
Dynamic: requires-python
|
|
41
|
+
|
|
42
|
+
SXC is a Python library designed for academic and educational use, providing intuitive access to machine learning algorithms, nonparametric smoothing techniques, and classical statistical learning workflows. Inspired by Scikit-Learn’s clean API principles, SXC ensures that users can perform data analysis with consistent, modular, and user-friendly interfaces.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Features
|
|
48
|
+
|
|
49
|
+
### Supervised Learning
|
|
50
|
+
- Decision Tree Classifier & Regressor
|
|
51
|
+
- Random Forest Classifier & Regressor
|
|
52
|
+
- K-Nearest Neighbors Classification & Regression
|
|
53
|
+
- Naive Bayes Classifier
|
|
54
|
+
- Support Vector Machines (Classification & Regression)
|
|
55
|
+
- Bagging for both Regression and Classification
|
|
56
|
+
|
|
57
|
+
### Nonparametric Regression & Smoothing
|
|
58
|
+
Located under `sxc.mdts.adv_reg`:
|
|
59
|
+
- Bin Smoother
|
|
60
|
+
- KNN Smoother
|
|
61
|
+
- Kernel Weighted Regression
|
|
62
|
+
- LOWESS (Locally Weighted Regression)
|
|
63
|
+
- LWR (Local Weighted Regression variants)
|
|
64
|
+
|
|
65
|
+
### Clustering
|
|
66
|
+
- K-Means clustering
|
|
67
|
+
|
|
68
|
+
### Utility
|
|
69
|
+
- Indexing helper for dataset preprocessing
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Installation
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install sxc
|
|
77
|
+
```
|
|
78
|
+
This will install all core dependencies required to run the machine learning modules inside SXC.
|
|
79
|
+
|
|
80
|
+
## Quick Start
|
|
81
|
+
```py
|
|
82
|
+
from sxc.mdts.decision_tree_classifier import DecisionTreeClassifier
|
|
83
|
+
from sklearn.datasets import load_iris
|
|
84
|
+
from sklearn.model_selection import train_test_split
|
|
85
|
+
from sklearn.metrics import accuracy_score
|
|
86
|
+
|
|
87
|
+
# Load toy dataset
|
|
88
|
+
X, y = load_iris(return_X_y=True)
|
|
89
|
+
|
|
90
|
+
# Train-test split
|
|
91
|
+
X_train, X_test, y_train, y_test = train_test_split(
|
|
92
|
+
X, y, test_size=0.3, random_state=42
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
# Initialize the model
|
|
96
|
+
model = DecisionTreeClassifier()
|
|
97
|
+
|
|
98
|
+
# Fit and predict
|
|
99
|
+
model.fit(X_train, y_train)
|
|
100
|
+
preds = model.predict(X_test)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
All algorithms included are intended for educational demonstrations and experiments. SXC facilitates rapid learning of:
|
|
104
|
+
|
|
105
|
+
Machine learning theory
|
|
106
|
+
Practical model building
|
|
107
|
+
Nonparametric regression foundations
|
|
108
|
+
For academic citation or publication:
|
|
109
|
+
|
|
110
|
+
## Patra, S. (2025).
|
|
111
|
+
SXC: Statistical & Explainable Computing (Version 0.1.x).
|
|
112
|
+
Python package available at PyPI.
|
|
113
|
+
|
|
114
|
+
# Contributing
|
|
115
|
+
Contributions are welcomed. Kindly create pull requests via GitHub or report issues to help improve stability, documentation, and performance.
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
Licensed under the MIT License. Free to view, modify, and learn from.
|
|
119
|
+
|
|
120
|
+
## Acknowledgement
|
|
121
|
+
Developed with passion for the community of statisticians, data scientists, and research enthusiasts at St. Xavier’s College.
|
|
122
|
+
|
|
123
|
+
Keep experimenting. Keep learning. Keep computing elegantly.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
SXC is a Python library designed for academic and educational use, providing intuitive access to machine learning algorithms, nonparametric smoothing techniques, and classical statistical learning workflows. Inspired by Scikit-Learn’s clean API principles, SXC ensures that users can perform data analysis with consistent, modular, and user-friendly interfaces.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
### Supervised Learning
|
|
9
|
+
- Decision Tree Classifier & Regressor
|
|
10
|
+
- Random Forest Classifier & Regressor
|
|
11
|
+
- K-Nearest Neighbors Classification & Regression
|
|
12
|
+
- Naive Bayes Classifier
|
|
13
|
+
- Support Vector Machines (Classification & Regression)
|
|
14
|
+
- Bagging for both Regression and Classification
|
|
15
|
+
|
|
16
|
+
### Nonparametric Regression & Smoothing
|
|
17
|
+
Located under `sxc.mdts.adv_reg`:
|
|
18
|
+
- Bin Smoother
|
|
19
|
+
- KNN Smoother
|
|
20
|
+
- Kernel Weighted Regression
|
|
21
|
+
- LOWESS (Locally Weighted Regression)
|
|
22
|
+
- LWR (Local Weighted Regression variants)
|
|
23
|
+
|
|
24
|
+
### Clustering
|
|
25
|
+
- K-Means clustering
|
|
26
|
+
|
|
27
|
+
### Utility
|
|
28
|
+
- Indexing helper for dataset preprocessing
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install sxc
|
|
36
|
+
```
|
|
37
|
+
This will install all core dependencies required to run the machine learning modules inside SXC.
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
```py
|
|
41
|
+
from sxc.mdts.decision_tree_classifier import DecisionTreeClassifier
|
|
42
|
+
from sklearn.datasets import load_iris
|
|
43
|
+
from sklearn.model_selection import train_test_split
|
|
44
|
+
from sklearn.metrics import accuracy_score
|
|
45
|
+
|
|
46
|
+
# Load toy dataset
|
|
47
|
+
X, y = load_iris(return_X_y=True)
|
|
48
|
+
|
|
49
|
+
# Train-test split
|
|
50
|
+
X_train, X_test, y_train, y_test = train_test_split(
|
|
51
|
+
X, y, test_size=0.3, random_state=42
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
# Initialize the model
|
|
55
|
+
model = DecisionTreeClassifier()
|
|
56
|
+
|
|
57
|
+
# Fit and predict
|
|
58
|
+
model.fit(X_train, y_train)
|
|
59
|
+
preds = model.predict(X_test)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
All algorithms included are intended for educational demonstrations and experiments. SXC facilitates rapid learning of:
|
|
63
|
+
|
|
64
|
+
Machine learning theory
|
|
65
|
+
Practical model building
|
|
66
|
+
Nonparametric regression foundations
|
|
67
|
+
For academic citation or publication:
|
|
68
|
+
|
|
69
|
+
## Patra, S. (2025).
|
|
70
|
+
SXC: Statistical & Explainable Computing (Version 0.1.x).
|
|
71
|
+
Python package available at PyPI.
|
|
72
|
+
|
|
73
|
+
# Contributing
|
|
74
|
+
Contributions are welcomed. Kindly create pull requests via GitHub or report issues to help improve stability, documentation, and performance.
|
|
75
|
+
|
|
76
|
+
## License
|
|
77
|
+
Licensed under the MIT License. Free to view, modify, and learn from.
|
|
78
|
+
|
|
79
|
+
## Acknowledgement
|
|
80
|
+
Developed with passion for the community of statisticians, data scientists, and research enthusiasts at St. Xavier’s College.
|
|
81
|
+
|
|
82
|
+
Keep experimenting. Keep learning. Keep computing elegantly.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Machine Learning Folder
|
|
2
|
+
from .machine_learning import indexing
|
|
3
|
+
from .machine_learning import bagging_classifier
|
|
4
|
+
from .machine_learning import bagging_regressor
|
|
5
|
+
from .machine_learning import decision_tree_classifier
|
|
6
|
+
from .machine_learning import decision_tree_regressor
|
|
7
|
+
from .machine_learning import indexing
|
|
8
|
+
from .machine_learning import kmeans_clustering
|
|
9
|
+
from .machine_learning import knn_classifier
|
|
10
|
+
from .machine_learning import knn_regressor
|
|
11
|
+
from .machine_learning import naive_bayes
|
|
12
|
+
from .machine_learning import random_forest_classifier
|
|
13
|
+
from .machine_learning import random_forest_regressor
|
|
14
|
+
from .machine_learning import support_vector_classifier
|
|
15
|
+
from .machine_learning import support_vector_regressor
|
|
16
|
+
|
|
17
|
+
# From Advanced Regression Folder
|
|
18
|
+
from .adv_reg import bin_smoother
|
|
19
|
+
from .adv_reg import knn_smoother
|
|
20
|
+
from .adv_reg import kernel_smoother
|
|
21
|
+
from .adv_reg import lowess
|
|
22
|
+
from .adv_reg import lwr
|
|
23
|
+
|
|
24
|
+
# Fom Optimization Folder
|
|
25
|
+
from .optimization import newton_method
|
|
26
|
+
from .optimization import golden_section
|
|
27
|
+
from .optimization import fibonacci_method
|
|
28
|
+
from .optimization import conjugate_gradient_without_direction
|
|
29
|
+
from .optimization import conjugate_gradient_with_direction
|
|
30
|
+
from .optimization import steepest_descent
|
|
31
|
+
from .optimization import quassi_newton
|
|
32
|
+
from .optimization import quassi_newton_documentation
|
|
33
|
+
__all__ = [
|
|
34
|
+
"indexing",
|
|
35
|
+
"BaggingClassifier",
|
|
36
|
+
"BaggingRegressor",
|
|
37
|
+
"DecisionTreeClassifier",
|
|
38
|
+
"DecisionTreeRegressor",
|
|
39
|
+
"KMeansClustering",
|
|
40
|
+
"KNNClassifier",
|
|
41
|
+
"KNNRegressor",
|
|
42
|
+
"NaiveBayesClassifier",
|
|
43
|
+
"RandomForestClassifier",
|
|
44
|
+
"RandomForestRegressor",
|
|
45
|
+
"SVC",
|
|
46
|
+
"SVR",
|
|
47
|
+
"bin_smoother",
|
|
48
|
+
"knn_smoother",
|
|
49
|
+
"kernel_smoother",
|
|
50
|
+
"lowess",
|
|
51
|
+
"lwr",
|
|
52
|
+
"newton_method",
|
|
53
|
+
"golden_section",
|
|
54
|
+
"fibonacci_method",
|
|
55
|
+
"conjugate_gradient_without_direction",
|
|
56
|
+
"conjugate_gradient_with_direction",
|
|
57
|
+
"steepest_descent",
|
|
58
|
+
"quassi_newton",
|
|
59
|
+
"quassi_newton_documentation"
|
|
60
|
+
]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from .bin_smoother import bin_smoother
|
|
2
|
+
from .knn_smoother import knn_smoother
|
|
3
|
+
from .kernel_smoother import kernel_smoother
|
|
4
|
+
from .lowess import lowess
|
|
5
|
+
from .lwr import lwr
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"bin_smoother",
|
|
9
|
+
"knn_smoother",
|
|
10
|
+
"kernel_smoother",
|
|
11
|
+
"lowess",
|
|
12
|
+
"lwr"
|
|
13
|
+
]
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import matplotlib.pyplot as plt
|
|
3
|
+
import pandas as pd
|
|
4
|
+
|
|
5
|
+
def bin_smoother(train, test, target="target", regression=None, bin=5):
|
|
6
|
+
"""
|
|
7
|
+
Perform bin smoothing estimation for a univariate nonparametric regression model.
|
|
8
|
+
|
|
9
|
+
The method divides the range of the covariate variable into a specified number of
|
|
10
|
+
equal-width bins using only the training set. It then estimates a stepwise regression
|
|
11
|
+
curve by computing the mean of the regression function values within each bin.
|
|
12
|
+
|
|
13
|
+
Parameters
|
|
14
|
+
----------
|
|
15
|
+
train : pandas.DataFrame
|
|
16
|
+
Training dataset containing the covariate in the first column and the response
|
|
17
|
+
specified by the target parameter.
|
|
18
|
+
test : pandas.DataFrame
|
|
19
|
+
Test dataset with similar structure as train.
|
|
20
|
+
target : str, optional
|
|
21
|
+
Name of the response variable column. Default is "target".
|
|
22
|
+
regression : callable, optional
|
|
23
|
+
A function that represents the true regression function f(x). It must accept
|
|
24
|
+
a NumPy array of x values and return predicted y values of equal length.
|
|
25
|
+
bin : int, optional
|
|
26
|
+
Number of equal-width bins for bin smoothing. Default is 5.
|
|
27
|
+
|
|
28
|
+
Example
|
|
29
|
+
-------
|
|
30
|
+
>>> from sxc import mdts
|
|
31
|
+
>>> import numpy as np
|
|
32
|
+
>>> import pandas as pd
|
|
33
|
+
>>>
|
|
34
|
+
>>> np.random.seed(1234)
|
|
35
|
+
>>> def reg(x):
|
|
36
|
+
... return 5*np.sin(x) + 23*(np.cos(x)**2)
|
|
37
|
+
>>>
|
|
38
|
+
>>> x = np.random.uniform(5, 15, 100)
|
|
39
|
+
>>> y = reg(x) + np.random.normal(0, 5, 100)
|
|
40
|
+
>>> data = pd.DataFrame({"feature": x, "target": y})
|
|
41
|
+
>>> train = data.iloc[:80]
|
|
42
|
+
>>> test = data.iloc[80:]
|
|
43
|
+
>>>
|
|
44
|
+
>>> mdts.bin_smoother(train, test, target="target", regression=reg, bin=10)
|
|
45
|
+
"""
|
|
46
|
+
# Function body continues here...
|
|
47
|
+
|
|
48
|
+
X_train = train.iloc[:, 0].values
|
|
49
|
+
y_train = train[target].values
|
|
50
|
+
|
|
51
|
+
X_test = test.iloc[:, 0].values
|
|
52
|
+
y_test = test[target].values
|
|
53
|
+
|
|
54
|
+
# Create bins using training data
|
|
55
|
+
bins = np.linspace(X_train.min(), X_train.max(), bin + 1)
|
|
56
|
+
bin_indices = np.digitize(X_train, bins) - 1
|
|
57
|
+
|
|
58
|
+
# Compute mean predicted value in each bin
|
|
59
|
+
bin_means = []
|
|
60
|
+
for i in range(bin):
|
|
61
|
+
in_bin = bin_indices == i
|
|
62
|
+
if np.any(in_bin):
|
|
63
|
+
bin_means.append(np.mean(regression(X_train[in_bin])))
|
|
64
|
+
else:
|
|
65
|
+
bin_means.append(0)
|
|
66
|
+
|
|
67
|
+
bin_means = np.array(bin_means)
|
|
68
|
+
|
|
69
|
+
# Step smoother prediction helper
|
|
70
|
+
def step_predict(x_values):
|
|
71
|
+
preds = np.zeros_like(x_values, float)
|
|
72
|
+
idx = np.digitize(x_values, bins) - 1
|
|
73
|
+
for i in range(bin):
|
|
74
|
+
preds[idx == i] = bin_means[i]
|
|
75
|
+
return preds
|
|
76
|
+
|
|
77
|
+
# Compute errors
|
|
78
|
+
train_pred = step_predict(X_train)
|
|
79
|
+
test_pred = step_predict(X_test)
|
|
80
|
+
|
|
81
|
+
train_mse = np.mean((y_train - train_pred)**2)
|
|
82
|
+
test_mse = np.mean((y_test - test_pred)**2)
|
|
83
|
+
|
|
84
|
+
# Plotting
|
|
85
|
+
plt.figure(figsize=(10, 6))
|
|
86
|
+
|
|
87
|
+
# Scatter
|
|
88
|
+
plt.scatter(X_train, y_train, label="Train", alpha=0.7)
|
|
89
|
+
plt.scatter(X_test, y_test, label="Test", marker='s')
|
|
90
|
+
|
|
91
|
+
# True function curve
|
|
92
|
+
x_curve = np.linspace(X_train.min(), X_train.max(), 400)
|
|
93
|
+
plt.plot(x_curve, regression(x_curve), label="True function", color='blue')
|
|
94
|
+
|
|
95
|
+
# Step horizontal segments
|
|
96
|
+
for i in range(bin):
|
|
97
|
+
plt.hlines(bin_means[i], bins[i], bins[i+1], colors='red', linewidth=2)
|
|
98
|
+
|
|
99
|
+
# Vertical dotted bin edges
|
|
100
|
+
for b in bins:
|
|
101
|
+
plt.axvline(x=b, linestyle='dotted', color='gray')
|
|
102
|
+
|
|
103
|
+
plt.title(f'k = {bin}')
|
|
104
|
+
|
|
105
|
+
# Legend at top right corner
|
|
106
|
+
plt.legend(loc='upper right')
|
|
107
|
+
|
|
108
|
+
plt.grid(True)
|
|
109
|
+
plt.show()
|
|
110
|
+
|
|
111
|
+
print(f"Train MSE: {train_mse:.4f}")
|
|
112
|
+
print(f"Test MSE: {test_mse:.4f}")
|
|
113
|
+
|
|
114
|
+
bin_summary = pd.DataFrame({
|
|
115
|
+
"Bin": [f"{i+1}" for i in range(bin)],
|
|
116
|
+
"Range Start": [round(bins[i], 3) for i in range(bin)],
|
|
117
|
+
"Range End": [round(bins[i+1], 3) for i in range(bin)],
|
|
118
|
+
"Mean Estimate": [round(bin_means[i], 3) for i in range(bin)]
|
|
119
|
+
})
|
|
120
|
+
print("Summary Table:")
|
|
121
|
+
print(bin_summary.to_string(index=False))
|
|
122
|
+
|
|
123
|
+
# return {
|
|
124
|
+
# "train_mse": train_mse,
|
|
125
|
+
# "test_mse": test_mse,
|
|
126
|
+
# "bin_means": bin_means,
|
|
127
|
+
# "bin_edges": bins
|
|
128
|
+
# }
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import matplotlib.pyplot as plt
|
|
4
|
+
from sklearn.model_selection import train_test_split
|
|
5
|
+
from sklearn.metrics import mean_squared_error
|
|
6
|
+
from scipy.stats import norm
|
|
7
|
+
|
|
8
|
+
# Kernel Regression Function
|
|
9
|
+
def kernel_smoother(train, test, target="target",
|
|
10
|
+
kernel=["gaussian", "uniform", "triangular", "epanechnikov"],
|
|
11
|
+
n_repeats=50):
|
|
12
|
+
"""
|
|
13
|
+
Kernel Smoother: Documentation
|
|
14
|
+
---------------------------------------------------------------------------
|
|
15
|
+
Parameters
|
|
16
|
+
---------------------------------------------------------------------------
|
|
17
|
+
train : pandas.DataFrame
|
|
18
|
+
Training dataset with columns:
|
|
19
|
+
• "feature" (predictor)
|
|
20
|
+
• "target" (response)
|
|
21
|
+
|
|
22
|
+
test : pandas.DataFrame
|
|
23
|
+
Testing dataset with the same structure as train.
|
|
24
|
+
|
|
25
|
+
target : str, default = "target"
|
|
26
|
+
Target column name.
|
|
27
|
+
|
|
28
|
+
kernel : list of str
|
|
29
|
+
Names of kernels to apply. Supported options:
|
|
30
|
+
• "gaussian"
|
|
31
|
+
• "uniform"
|
|
32
|
+
• "epanechnikov"
|
|
33
|
+
• "triangular"
|
|
34
|
+
• "biweight"
|
|
35
|
+
• "triweight"
|
|
36
|
+
• "tricube"
|
|
37
|
+
|
|
38
|
+
n_repeats : int, default = 50
|
|
39
|
+
Number of repeated evaluations for stable error estimates.
|
|
40
|
+
---------------------------------------------------------------------------
|
|
41
|
+
R Equivalent Example (Kernel Smoothing with Train/Test Errors)
|
|
42
|
+
---------------------------------------------------------------------------
|
|
43
|
+
rm(list=ls())
|
|
44
|
+
set.seed(1234)
|
|
45
|
+
reg = function(x) 5 * sin(x) + 23 * (cos(x))^2
|
|
46
|
+
n = 100 ; x = runif(n, 5, 15)
|
|
47
|
+
y = reg(x) + rnorm(n, 0, 5)
|
|
48
|
+
train_idx = sample(1:n, size = 0.8 * n)
|
|
49
|
+
X_train = x[train_idx] ; Y_train = y[train_idx]
|
|
50
|
+
X_test = x[-train_idx] ; Y_test = y[-train_idx]
|
|
51
|
+
|
|
52
|
+
# Kernels
|
|
53
|
+
gaussian = function(u) exp(-0.5 * u^2) / sqrt(2*pi)
|
|
54
|
+
kernels = list( gaussian = gaussian )
|
|
55
|
+
bandwidths = c(0.1, 0.25, 0.5, 1, 2)
|
|
56
|
+
n_repeats = 50
|
|
57
|
+
results = data.frame()
|
|
58
|
+
|
|
59
|
+
# Kernel smoothing evaluation
|
|
60
|
+
for (kname in names(kernels)) {
|
|
61
|
+
cat("Processing Kernel:", toupper(kname)")
|
|
62
|
+
K = kernels[[kname]]
|
|
63
|
+
for (h in bandwidths) {
|
|
64
|
+
train_err = c()
|
|
65
|
+
test_err = c()
|
|
66
|
+
|
|
67
|
+
for (r in 1:n_repeats) {
|
|
68
|
+
n_train = length(X_train)
|
|
69
|
+
L = matrix(0, n_train, n_train)
|
|
70
|
+
for (i in 1:n_train) {
|
|
71
|
+
u = (X_train[i] - X_train) / h
|
|
72
|
+
w = K(u)
|
|
73
|
+
L[i, ] = w / sum(w)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
Y_pred_train = L %*% Y_train
|
|
77
|
+
train_mse = mean((Y_pred_train - Y_train)^2)
|
|
78
|
+
|
|
79
|
+
Y_pred_test = numeric(length(X_test))
|
|
80
|
+
for (i in 1:length(X_test)) {
|
|
81
|
+
u = (X_test[i] - X_train) / h
|
|
82
|
+
w = K(u)
|
|
83
|
+
Y_pred_test[i] = sum(w * Y_train) / sum(w)
|
|
84
|
+
}
|
|
85
|
+
test_mse = mean((Y_pred_test - Y_test)^2)
|
|
86
|
+
|
|
87
|
+
train_err = c(train_err, train_mse)
|
|
88
|
+
test_err = c(test_err, test_mse)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
results = rbind(results, data.frame(
|
|
92
|
+
Kernel = kname,
|
|
93
|
+
h = h,
|
|
94
|
+
Avg_Train_MSE = mean(train_err),
|
|
95
|
+
Avg_Test_MSE = mean(test_err)
|
|
96
|
+
))
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
print(results)
|
|
101
|
+
|
|
102
|
+
for (kname in names(kernels)) {
|
|
103
|
+
df = subset(results, Kernel == kname)
|
|
104
|
+
best_h = df$h[which.min(df$Avg_Test_MSE)]
|
|
105
|
+
K = kernels[[kname]]
|
|
106
|
+
cat("Best bandwidth for", kname, "=", best_h)
|
|
107
|
+
|
|
108
|
+
x_grid = seq(min(X_train), max(X_train), length.out = 200)
|
|
109
|
+
y_smooth = numeric(length(x_grid))
|
|
110
|
+
|
|
111
|
+
for (i in 1:length(x_grid)) {
|
|
112
|
+
u = (x_grid[i] - X_train) / best_h
|
|
113
|
+
w = K(u)
|
|
114
|
+
y_smooth[i] = sum(w * Y_train) / sum(w)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
plot(X_train, Y_train, col="blue", pch=16,
|
|
118
|
+
main=paste(kname, "Kernel Regression Fit"),
|
|
119
|
+
xlab="X", ylab="Y")
|
|
120
|
+
points(X_test, Y_test, col="orange", pch=16)
|
|
121
|
+
lines(x_grid, y_smooth, col="red", lwd=2)
|
|
122
|
+
legend("topleft", legend=c("Train","Test","Fit"),
|
|
123
|
+
col=c("blue","orange","red"), pch=c(16,16,NA), lty=c(NA,NA,1))
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
---------------------------------------------------------------------------
|
|
127
|
+
Returns
|
|
128
|
+
---------------------------------------------------------------------------
|
|
129
|
+
pandas.DataFrame
|
|
130
|
+
Summary of training/testing MSE for each kernel-bandwidth combination.
|
|
131
|
+
"""
|
|
132
|
+
X_train = train["feature"].values
|
|
133
|
+
y_train = train[target].values
|
|
134
|
+
X_test = test["feature"].values
|
|
135
|
+
y_test = test[target].values
|
|
136
|
+
|
|
137
|
+
# Bandwidth values (h or σ)
|
|
138
|
+
bandwidths = [0.1, 0.25, 0.5, 1, 2]
|
|
139
|
+
def gaussian_kernel(u): return (1/np.sqrt(2*np.pi)) * np.exp(-u**2 / 2)
|
|
140
|
+
def uniform_kernel(u): return np.where(np.abs(u) <= 1, 1/2, 0)
|
|
141
|
+
def epanechnikov_kernel(u): return np.where(np.abs(u) <= 1, 3/4 * (1 - u**2), 0)
|
|
142
|
+
def triangular_kernel(u): return np.where(np.abs(u) < 1, (35/32) * (1 - u**2)**3, 0)
|
|
143
|
+
def biweight_kernel(u): return np.where(np.abs(u) <= 1, 15/16 * (1 - u**2)**2, 0)
|
|
144
|
+
def triweight_kernel(u): return np.where(np.abs(u) <= 1, 35/32 * (1 - u**2)**3, 0)
|
|
145
|
+
def tricube_kernel(u): return np.where(np.abs(u) <= 1, 70/81 * (1 - np.abs(u)**3)**3, 0)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
kernels = {
|
|
149
|
+
"gaussian": gaussian_kernel,
|
|
150
|
+
"uniform": uniform_kernel,
|
|
151
|
+
"epanechnikov": epanechnikov_kernel,
|
|
152
|
+
"triangular": triangular_kernel,
|
|
153
|
+
"biweight": biweight_kernel,
|
|
154
|
+
"triweight": triweight_kernel,
|
|
155
|
+
"tricube": tricube_kernel
|
|
156
|
+
}
|
|
157
|
+
results = []
|
|
158
|
+
|
|
159
|
+
# Compute Regression for Each Kernel
|
|
160
|
+
for k_name in kernel:
|
|
161
|
+
K = kernels[k_name]
|
|
162
|
+
print(f"\nProcessing Kernel: {k_name.upper()}")
|
|
163
|
+
|
|
164
|
+
for h in bandwidths:
|
|
165
|
+
train_errors = []
|
|
166
|
+
test_errors = []
|
|
167
|
+
|
|
168
|
+
for _ in range(n_repeats):
|
|
169
|
+
# Predict on train and test
|
|
170
|
+
def kernel_regression(x_query, X, Y, h):
|
|
171
|
+
weights = K((x_query - X[:, None]) / h)
|
|
172
|
+
numer = np.dot(weights.T, Y)
|
|
173
|
+
denom = np.sum(weights, axis=0)
|
|
174
|
+
denom = np.where(denom == 0, 1e-8, denom)
|
|
175
|
+
return numer / denom
|
|
176
|
+
|
|
177
|
+
y_pred_train = kernel_regression(X_train, X_train, y_train, h)
|
|
178
|
+
y_pred_test = kernel_regression(X_test, X_train, y_train, h)
|
|
179
|
+
|
|
180
|
+
train_mse = mean_squared_error(y_train, y_pred_train)
|
|
181
|
+
test_mse = mean_squared_error(y_test, y_pred_test)
|
|
182
|
+
|
|
183
|
+
train_errors.append(train_mse)
|
|
184
|
+
test_errors.append(test_mse)
|
|
185
|
+
|
|
186
|
+
avg_train_err = np.mean(train_errors)
|
|
187
|
+
avg_test_err = np.mean(test_errors)
|
|
188
|
+
results.append({
|
|
189
|
+
"Kernel": k_name,
|
|
190
|
+
"h": h,
|
|
191
|
+
"Avg Train error": avg_train_err,
|
|
192
|
+
"Avg Test error": avg_test_err
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
Res_df = pd.DataFrame(results)
|
|
196
|
+
|
|
197
|
+
# Plot Average Train/Test MSE vs h
|
|
198
|
+
for k_name in kernel:
|
|
199
|
+
df_k = Res_df[Res_df["Kernel"] == k_name]
|
|
200
|
+
plt.figure(figsize=(8, 5))
|
|
201
|
+
plt.plot(df_k["h"], df_k["Avg Train error"], label="Avg Train error", marker="o")
|
|
202
|
+
plt.plot(df_k["h"], df_k["Avg Test error"], label="Avg Test error", marker="s")
|
|
203
|
+
plt.xlabel("Bandwidth (h)", fontsize=14)
|
|
204
|
+
plt.ylabel("Average MSE", fontsize=14)
|
|
205
|
+
plt.title(f"{k_name.capitalize()} Kernel: Train vs Test Error", fontsize=16)
|
|
206
|
+
plt.legend()
|
|
207
|
+
plt.grid(True)
|
|
208
|
+
plt.show()
|
|
209
|
+
|
|
210
|
+
# Plot Scatter + Smoothed Line
|
|
211
|
+
plt.figure(figsize=(8, 5))
|
|
212
|
+
plt.scatter(X_train, y_train, color="blue", alpha=0.6, label="Train Data")
|
|
213
|
+
plt.scatter(X_test, y_test, color="orange", alpha=0.6, label="Test Data")
|
|
214
|
+
|
|
215
|
+
x_grid = np.linspace(min(X_train), max(X_train), 200)
|
|
216
|
+
y_smooth = []
|
|
217
|
+
|
|
218
|
+
best_h = df_k.loc[df_k["Avg Test error"].idxmin(), "h"]
|
|
219
|
+
for xq in x_grid:
|
|
220
|
+
weights = K((xq - X_train) / best_h)
|
|
221
|
+
y_hat = np.sum(weights * y_train) / np.sum(weights)
|
|
222
|
+
y_smooth.append(y_hat)
|
|
223
|
+
|
|
224
|
+
plt.plot(x_grid, y_smooth, color="blue", linewidth=1,
|
|
225
|
+
label=f"Smoothed ({k_name}, h={best_h})")
|
|
226
|
+
plt.xlabel("Feature", fontsize=14)
|
|
227
|
+
plt.ylabel("Target", fontsize=14)
|
|
228
|
+
plt.title(f"{k_name.capitalize()} Kernel Regression Fit", fontsize=16)
|
|
229
|
+
plt.legend()
|
|
230
|
+
plt.grid(True)
|
|
231
|
+
plt.show()
|
|
232
|
+
|
|
233
|
+
return Res_df
|