mirror of
https://github.com/Doctorado-ML/bayesclass.git
synced 2025-08-15 23:55:57 +00:00
Initial commit
This commit is contained in:
6
examples/README.txt
Normal file
6
examples/README.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
.. _general_examples:
|
||||
|
||||
General examples
|
||||
================
|
||||
|
||||
Introductory examples.
|
44
examples/plot_classifier.py
Normal file
44
examples/plot_classifier.py
Normal file
@@ -0,0 +1,44 @@
|
||||
"""
|
||||
============================
|
||||
Plotting Template Classifier
|
||||
============================
|
||||
|
||||
An example plot of :class:`bayesclass.template.TemplateClassifier`
|
||||
"""
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
from bayesclass import TemplateClassifier
|
||||
|
||||
X = [[0, 0], [1, 1]]
|
||||
y = [0, 1]
|
||||
clf = TemplateClassifier()
|
||||
clf.fit(X, y)
|
||||
|
||||
rng = np.random.RandomState(13)
|
||||
X_test = rng.rand(500, 2)
|
||||
y_pred = clf.predict(X_test)
|
||||
|
||||
X_0 = X_test[y_pred == 0]
|
||||
X_1 = X_test[y_pred == 1]
|
||||
|
||||
|
||||
p0 = plt.scatter(0, 0, c="red", s=100)
|
||||
p1 = plt.scatter(1, 1, c="blue", s=100)
|
||||
|
||||
ax0 = plt.scatter(X_0[:, 0], X_0[:, 1], c="crimson", s=50)
|
||||
ax1 = plt.scatter(X_1[:, 0], X_1[:, 1], c="deepskyblue", s=50)
|
||||
|
||||
leg = plt.legend(
|
||||
[p0, p1, ax0, ax1],
|
||||
["Point 0", "Point 1", "Class 0", "Class 1"],
|
||||
loc="upper left",
|
||||
fancybox=True,
|
||||
scatterpoints=1,
|
||||
)
|
||||
leg.get_frame().set_alpha(0.5)
|
||||
|
||||
plt.xlabel("Feature 1")
|
||||
plt.ylabel("Feature 2")
|
||||
plt.xlim([-0.5, 1.5])
|
||||
|
||||
plt.show()
|
17
examples/plot_template.py
Normal file
17
examples/plot_template.py
Normal file
@@ -0,0 +1,17 @@
|
||||
"""
|
||||
===========================
|
||||
Plotting Template Estimator
|
||||
===========================
|
||||
|
||||
An example plot of :class:`bayesclass.template.TemplateEstimator`
|
||||
"""
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
from bayesclass import TemplateEstimator
|
||||
|
||||
X = np.arange(100).reshape(100, 1)
|
||||
y = np.zeros((100,))
|
||||
estimator = TemplateEstimator()
|
||||
estimator.fit(X, y)
|
||||
plt.plot(estimator.predict(X))
|
||||
plt.show()
|
26
examples/plot_transformer.py
Normal file
26
examples/plot_transformer.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""
|
||||
=============================
|
||||
Plotting Template Transformer
|
||||
=============================
|
||||
|
||||
An example plot of :class:`bayesclass.template.TemplateTransformer`
|
||||
"""
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
from bayesclass import TemplateTransformer
|
||||
|
||||
X = np.arange(50, dtype=np.float).reshape(-1, 1)
|
||||
X /= 50
|
||||
estimator = TemplateTransformer()
|
||||
X_transformed = estimator.fit_transform(X)
|
||||
|
||||
plt.plot(X.flatten(), label="Original Data")
|
||||
plt.plot(X_transformed.flatten(), label="Transformed Data")
|
||||
plt.title("Plots of original and transformed data")
|
||||
|
||||
plt.legend(loc="best")
|
||||
plt.grid(True)
|
||||
plt.xlabel("Index")
|
||||
plt.ylabel("Value of Data")
|
||||
|
||||
plt.show()
|
Reference in New Issue
Block a user