技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
unsupervised-and-reduction【数据与研究】Use this sub-skill for MLAlgorithms clustering, Gaussian mixtures, PCA, t-SNE, RBM feature learning, metrics/distances, and packaged demo dataset loaders.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill when a task asks for MLAlgorithms' unsupervised estimators, dimensionality reduction, small visualization-oriented workflows, RBM feature learning, or demo data loaders. These APIs are CPU-only educational implementations; keep workloads small and validate output shapes or assignments before scaling.
../classical-estimators/SKILL.md.../neural-network-building-blocks/SKILL.md.Confirm the public imports you need:
from mla.kmeans import KMeans
from mla.gaussian_mixture import GaussianMixture
from mla.pca import PCA
from mla.tsne import TSNE
from mla.rbm import RBM
from mla.datasets import load_mnist, load_nietzsche
Choose the workflow:
KMeans(K=..., init="random"|"++").GaussianMixture(K=..., init="random"|"kmeans").PCA(n_components, solver="svd"|"eigen").TSNE(n_components=2, perplexity=..., max_iter=...).RBM(n_hidden=..., max_epochs=...).Avoid plotting in headless or automated runs; inspect returned labels, component shapes, likelihoods, embeddings, or errors instead.
Run scripts/run_unsupervised_smoke.py --workflow all for a safe no-display check.
from sklearn.datasets import make_blobs
from mla.kmeans import KMeans
X, _ = make_blobs(n_samples=120, centers=3, n_features=2, random_state=42)
model = KMeans(K=3, max_iters=50, init="++")
model.fit(X)
labels = model.predict() # labels for the fitted training data
centroids = model.centroids
Call fit(X) before predict(). KMeans.predict() without an argument returns assignments for the stored training data because the class overrides _predict around self.X.
from mla.gaussian_mixture import GaussianMixture
model = GaussianMixture(K=3, init="kmeans", max_iters=50, tolerance=1e-3)
model.fit(X)
assignments = model.predict(X)
GMM uses full covariance matrices and SciPy's multivariate_normal.pdf. Tiny or duplicate clusters can produce singular-covariance failures; increase samples, reduce K, or add slight jitter.
from mla.pca import PCA
pca = PCA(n_components=2, solver="svd")
pca.fit(X_train)
X_train_2d = pca.transform(X_train)
X_test_2d = pca.transform(X_test)
Fit PCA on training data only, then transform held-out data with the learned mean and components.
from mla.tsne import TSNE
embedding = TSNE(n_components=2, perplexity=10.0, max_iter=250, learning_rate=200).fit_transform(X)
Use t-SNE for visualization-style embeddings rather than predictive features. Keep sample counts small; this implementation uses dense pairwise distances and a Python loop.
import numpy as np
from mla.rbm import RBM
X = np.random.RandomState(0).uniform(0, 1, (100, 8))
rbm = RBM(n_hidden=4, learning_rate=0.05, batch_size=10, max_epochs=5)
rbm.fit(X)
features = rbm.predict(X)
RBM stores per-epoch reconstruction errors in rbm.errors.
load_mnist() returns (X_train, X_test, y_train, y_test) with image arrays shaped for the ConvNet example. load_nietzsche() creates one-hot text sequences for recurrent examples. Both read package data shipped with the distribution; do not copy those datasets into generated skills. With modern NumPy, load_nietzsche() may need numpy<1.24 or a source patch because it uses deprecated np.bool.
references/api-reference.md for import paths, signatures, state attributes, and outputs.references/workflows.md for cluster/reduction/RBM recipes and validation ideas.references/troubleshooting.md for singular covariance, plotting, data-loader, t-SNE runtime, and NumPy compatibility issues.scripts/run_unsupervised_smoke.py --workflow all to exercise small no-display checks against an installed mla package.