DataManip Insights BONUSMachine Learning FondamentauxGratuit

🗜️
🧱
🧭

-
-
-
-
-
-

-
-
-
-
-

🗜️
🚫
🎯
➕
Python · matrices_creuses.py
import numpy as np, scipy.sparse as sp
from sklearn.decomposition import PCA, TruncatedSVD

rng = np.random.default_rng(1)
X = sp.random(10_000, 5_000, density=0.005, format="csr", random_state=1,
              data_rvs=lambda k: rng.random(k) + 0.5)      # 99,5 % de zéros

print(X.data.nbytes + X.indices.nbytes + X.indptr.nbytes)   # 3040004 : format creux
print(X.shape[0] * X.shape[1] * 8)                          # 400000000 : en dense

svd = TruncatedSVD(50, random_state=0).fit(X)               # ne centre pas
pca = PCA(50, svd_solver="arpack", random_state=0).fit(X)   # centre en interne

mu = np.asarray(X.mean(axis=0)).ravel()                     # le « document moyen »
cos = lambda v: abs(v @ mu) / np.linalg.norm(mu) / np.linalg.norm(v)
print(round(cos(svd.components_[0]), 2))                    # 1.0  : TruncatedSVD
print(round(cos(pca.components_[0]), 2))                    # 0.01 : PCA
# testé avec scikit-learn 1.9.1 ; les versions anciennes refusent la PCA sur une matrice creuse

ACCÈS COMPLET

Cet épisode est gratuit. Les 297 autres t'attendent.

Statistiques, finance quantitative, machine learning, deep learning, LLM, agents IA, MLOps : 355 épisodes avec des simulateurs à manipuler, pas des vidéos.

99 € (+ TVA selon le pays) · accès à vie · remboursement possible sous 7 jours
Débloquer les 297 épisodes · 99 € J'ai déjà une clé de licence
FULL ACCESS

This episode is free. The other 297 are waiting for you.

Statistics, quantitative finance, machine learning, deep learning, LLMs, AI agents, MLOps: 355 interactive episodes with simulators to play with, not videos.

€99 (+ VAT depending on country) · lifetime access · 7-day refund
Unlock the 297 episodes · €99 I already have a license key