Skip to content

机器学习与深度学习资源专题

从经典算法到前沿框架——帮你建立完整的 ML/DL 知识体系


🧭 学习路径

数据准备  →  经典 ML  →  模型评估  →  深度学习  →  前沿专题
 (基础)      (核心)      (必修)       (进阶)       (探索)
阶段 核心内容 推荐时间 前置
🟢 基础 数据清洗、特征工程、scikit-learn 2-4 周 Python + Pandas
🟡 核心 回归、分类、聚类、集成方法 4-8 周 基础统计
🟠 进阶 深度学习、NLP、CV 8-12 周 线性代数 + 微积分
🔴 前沿 GNN、RL、生成模型、LLM 持续 上述全部

🎯 算法选择速查

"我该用什么算法?"——先看你的数据和目标

你要做什么? 数据特点 首选算法 备选
预测连续值 表格数据 XGBoost / LightGBM 随机森林、线性回归
二分类 表格数据 XGBoost / LightGBM 逻辑回归、SVM
多分类 表格数据 LightGBM / CatBoost 随机森林、神经网络
图像识别 图像 CNN (ResNet/EfficientNet) ViT、迁移学习
文本分类 文本 BERT / RoBERTa FastText、LSTM
用户分群 无标签 K-Means / DBSCAN 层次聚类、GMM
降维可视化 高维数据 t-SNE / UMAP PCA
时间序列预测 时序 LightGBM + 特征工程 Prophet、LSTM
推荐系统 交互矩阵 协同过滤 / 矩阵分解 Two-Tower NN
异常检测 不平衡 Isolation Forest AutoEncoder、LOF

80/20 原则:特征工程 > 算法选择 > 超参数调优。花 80% 时间在数据理解和特征工程上。


📚 核心理论

机器学习经典

书名 作者 难度 推荐理由
《机器学习》 周志华 ⭐⭐⭐⭐ 西瓜书,中文经典
《统计学习方法》 李航 ⭐⭐⭐⭐ 理论扎实,推导详细
《Hands-On ML》 Aurélien Géron ⭐⭐⭐ 实战首选
《Pattern Recognition and Machine Learning》 Christopher M. Bishop ⭐⭐⭐⭐⭐ 贝叶斯视角
《The Elements of Statistical Learning》 Hastie et al. ⭐⭐⭐⭐⭐ 统计学习圣经

配套资源: - 西瓜书笔记:链接 - 统计学习方法代码:链接 - ESL 中文翻译:链接


深度学习经典

书名 作者 难度 特点
《深度学习》 Ian Goodfellow ⭐⭐⭐⭐⭐ 花书,理论权威
《Deep Learning》 Ian Goodfellow ⭐⭐⭐⭐⭐ 英文原版
《Neural Networks and Deep Learning》 Michael Nielsen ⭐⭐⭐ 免费在线
《Dive into Deep Learning》 Aston Zhang ⭐⭐⭐ 交互式

🎓 在线课程

系统性课程

课程 讲师 平台 难度 链接
Machine Learning Andrew Ng Coursera ⭐⭐⭐ 链接
Deep Learning Specialization Andrew Ng Coursera ⭐⭐⭐⭐ 链接
CS229: Machine Learning Andrew Ng Stanford ⭐⭐⭐⭐ 链接
CS231n: CNN for Vision Fei-Fei Li Stanford ⭐⭐⭐⭐ 链接
机器学习 周志华 南京大学 ⭐⭐⭐⭐ 链接
李宏毅机器学习 李宏毅 NTU ⭐⭐⭐ B 站

专项课程

课程 领域 平台 链接
NLP Specialization NLP Coursera 链接
Convolutional Neural Networks CV Coursera 链接
Full Stack Deep Learning MLOps - 链接
Hugging Face NLP Course NLP HF 链接

🛠️ 工具库

Scikit-learn

基础用法

from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report

# 数据分割
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

# 模型训练
model = RandomForestClassifier(n_estimators=100, max_depth=5)
model.fit(X_train, y_train)

# 预测与评估
y_pred = model.predict(X_test)
print(classification_report(y_test, y_pred))

交叉验证与网格搜索

from sklearn.model_selection import cross_val_score, GridSearchCV

# 交叉验证
scores = cross_val_score(model, X, y, cv=5, scoring='accuracy')
print(f"CV Score: {scores.mean():.3f} (+/- {scores.std() * 2:.3f})")

# 网格搜索
param_grid = {
    'n_estimators': [50, 100, 200],
    'max_depth': [5, 10, None]
}
grid_search = GridSearchCV(RandomForestClassifier(), param_grid, cv=5)
grid_search.fit(X, y)
print(f"Best params: {grid_search.best_params_}")

XGBoost & LightGBM

环境配置

pip install xgboost==1.7.0 lightgbm==3.3.5 scikit-learn==1.2.2

基础对比

from xgboost import XGBClassifier
from lightgbm import LGBMClassifier

# XGBoost
xgb_model = XGBClassifier(
    n_estimators=100,
    learning_rate=0.1,
    max_depth=3,
    subsample=0.8,
    colsample_bytree=0.8
)

# LightGBM
lgb_model = LGBMClassifier(
    n_estimators=100,
    learning_rate=0.1,
    max_depth=3,
    subsample=0.8,
    feature_fraction=0.8
)

# 训练(Scikit-learn 接口)
xgb_model.fit(X_train, y_train)
lgb_model.fit(X_train, y_train)

特征重要性

import matplotlib.pyplot as plt

# XGBoost
xgb_model.feature_importances_
plt.bar(range(len(feature_names)), xgb_model.feature_importances_)
plt.xticks(range(len(feature_names)), feature_names, rotation=90)

# LightGBM
lgb.plot_importance(lgb_model, figsize=(10, 6))
plt.show()

PyTorch

基础示例

import torch
import torch.nn as nn
import torch.optim as optim

# 定义网络
class NeuralNet(nn.Module):
    def __init__(self, input_size, hidden_size, num_classes):
        super(NeuralNet, self).__init__()
        self.fc1 = nn.Linear(input_size, hidden_size)
        self.relu = nn.ReLU()
        self.fc2 = nn.Linear(hidden_size, num_classes)

    def forward(self, x):
        out = self.fc1(x)
        out = self.relu(out)
        out = self.fc2(out)
        return out

# 初始化
model = NeuralNet(input_size=784, hidden_size=128, num_classes=10)

# 损失函数和优化器
criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters(), lr=0.001)

# 训练循环
for epoch in range(num_epochs):
    for batch_X, batch_y in dataloader:
        outputs = model(batch_X)
        loss = criterion(outputs, batch_y)

        optimizer.zero_grad()
        loss.backward()
        optimizer.step()

CNN 示例

import torch.nn as nn
import torch.nn.functional as F

class CNN(nn.Module):
    def __init__(self):
        super(CNN, self).__init__()
        self.conv1 = nn.Conv2d(1, 32, kernel_size=3, padding=1)
        self.pool = nn.MaxPool2d(2, 2)
        self.conv2 = nn.Conv2d(32, 64, kernel_size=3, padding=1)
        self.fc1 = nn.Linear(64 * 7 * 7, 128)
        self.fc2 = nn.Linear(128, 10)

    def forward(self, x):
        x = self.pool(F.relu(self.conv1(x)))
        x = self.pool(F.relu(self.conv2(x)))
        x = x.view(-1, 64 * 7 * 7)
        x = F.relu(self.fc1(x))
        x = self.fc2(x)
        return x

TensorFlow & Keras

import tensorflow as tf
from tensorflow import keras

# 构建模型
model = keras.Sequential([
    keras.layers.Dense(128, activation='relu', input_shape=(input_dim,)),
    keras.layers.Dropout(0.2),
    keras.layers.Dense(64, activation='relu'),
    keras.layers.Dense(num_classes, activation='softmax')
])

# 编译
model.compile(
    optimizer='adam',
    loss='sparse_categorical_crossentropy',
    metrics=['accuracy']
)

# 训练
history = model.fit(
    X_train, y_train,
    epochs=50,
    batch_size=32,
    validation_split=0.2
)

# 评估
test_loss, test_acc = model.evaluate(X_test, y_test)

📊 实战案例

Kaggle 竞赛

Titanic - 入门首战

import pandas as pd
from sklearn.ensemble import RandomForestClassifier

# 加载数据
train = pd.read_csv('train.csv')
test = pd.read_csv('test.csv')

# 特征工程
features = ['Pclass', 'Sex', 'SibSp', 'Parch']
X = pd.get_dummies(train[features])
y = train['Survived']
X_test = pd.get_dummies(test[features])

# 模型训练
model = RandomForestClassifier(n_estimators=100, max_depth=5)
model.fit(X, y)

# 预测
predictions = model.predict(X_test)
output = pd.DataFrame({'PassengerId': test.PassengerId, 'Survived': predictions})
output.to_csv('submission.csv', index=False)

House Prices - 回归问题

from sklearn.model_selection import cross_val_score
from xgboost import XGBRegressor

# 特征选择
features = ['OverallQual', 'GrLivArea', 'GarageCars', 'GarageArea', 'TotalBsmtSF']
X = train[features]
y = train['SalePrice']

# XGBoost 回归
model = XGBRegressor(n_estimators=1000, learning_rate=0.05)
model.fit(X, y)

# 交叉验证
scores = -cross_val_score(model, X, y, cv=5, scoring='neg_mean_absolute_error')
print(f"MAE: {scores.mean():.0f}")

🔍 常见问题

Q1: 如何选择机器学习算法?

A: 根据数据特点选择: - 小数据集 (<1k 样本): 线性模型、SVM - 中等数据集 (1k-100k): 随机森林、XGBoost、LightGBM - 大数据集 (>100k): 深度学习、在线学习 - 高维稀疏 (如文本): 线性模型+SVD、Naive Bayes - 图像: CNN、ResNet - 序列: RNN、LSTM、Transformer

Q2: 过拟合怎么处理?

A: - 正则化: L1/L2 正则 - Dropout: 神经网络 - 早停: Early Stopping - 数据增强: 图像、文本 - 交叉验证: 评估泛化能力 - 简化模型: 减少参数

Q3: 特征工程有哪些技巧?

A:

# 1. 缺失值处理
df.fillna(df.mean())  # 均值填充
df.fillna(df.median())  # 中位数填充
df.fillna(method='ffill')  # 前向填充

# 2. 类别编码
pd.get_dummies(df['category'])  # One-Hot
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
df['category_encoded'] = le.fit_transform(df['category'])

# 3. 特征缩放
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)

# 4. 特征交互
df['feature_ratio'] = df['feature1'] / df['feature2']
df['feature_product'] = df['feature1'] * df['feature2']

# 5. 时间特征
df['dayofweek'] = df['date'].dt.dayofweek
df['month'] = df['date'].dt.month
df['is_weekend'] = df['date'].dt.dayofweek >= 5


📋 学习路径

graph TB
    A[数学基础] --> B[机器学习基础]
    B --> C[监督学习]
    B --> D[无监督学习]
    B --> E[模型评估]

    C --> C1[线性回归]
    C --> C2[逻辑回归]
    C --> C3[决策树]
    C --> C4[SVM]
    C --> C5[集成学习]

    D --> D1[聚类]
    D --> D2[降维]
    D --> D3[关联规则]

    E --> E1[交叉验证]
    E --> E2[评估指标]
    E --> E3[超参数调优]

    C5 --> F[XGBoost/LightGBM]

    B --> G[深度学习]
    G --> G1[神经网络基础]
    G --> G2[CNN]
    G --> G3[RNN/LSTM]
    G --> G4[Transformer]

🔗 更多资源

论文与博客

竞赛平台


最后更新: 2026-06-01