← 返回首页

📚 上机考试语法点全解

人工智能训练师三级(高级)· 40 道上机真题全面解析 · 150+ 核心语法点 · 考前必备辅导资料

总题数

40 道上机真题

章节分布

8 个子章节

语法点

150+ 个核心考点

难度分布

3 个难度等级

第一章:数据处理基础(1.1.x)

1. Pandas 数据读取 基础

从 CSV、Excel 等文件读取数据到 DataFrame

import pandas as pd
data = pd.read_csv('file.csv')
data = pd.read_excel('file.xlsx')

2. 数据查看与探索 基础

查看数据前几行、基本信息、统计描述

data.head()          # 前 5 行
data.info()           # 基本信息
data.describe()       # 统计描述
data.shape           # 行列数

3. 数据筛选与条件过滤 中等

使用条件表达式筛选数据

data[data['age'] > 18]
data[(data['age'].between(18, 70))]
data[data['income'] > data['income'].mean()]

4. 数据分组聚合 中等

groupby 进行分组,配合 agg、count、mean 等聚合函数

data.groupby('category')['value'].mean()
data.groupby(['location', 'type']).agg({'value': ['mean', 'count']})
data.groupby('SensorType')['Value'].agg(['count', 'mean'])

5. 数据透视表 中等

使用 pivot_table 进行多维度分析

data.pivot_table(values='Value', index='Location', 
                columns='SensorType', aggfunc='mean')

6. 数据清洗 - 缺失值处理 中等

检测和处理缺失值

data.isnull().sum()              # 统计缺失值
data.dropna()                   # 删除缺失值
data.fillna(value)              # 填充缺失值
data['col'].fillna(method='ffill')  # 前向填充
data['col'].fillna(method='bfill')  # 后向填充

7. 数据清洗 - 重复值处理 基础

data.duplicated().sum()    # 统计重复值
data.drop_duplicates()   # 删除重复值

8. 异常值处理 中等

使用 IQR、条件过滤等方法处理异常值

# IQR 方法
Q1 = data.quantile(0.25)
Q3 = data.quantile(0.75)
IQR = Q3 - Q1
data_clean = data[~((data < (Q1 - 1.5 * IQR)) | 
                    (data > (Q3 + 1.5 * IQR))).any(axis=1)]

# 条件过滤
data = data[(data['age'].between(18, 70)) & 
            (data['value'] > 0)]

9. 数据标准化/归一化 中等

from sklearn.preprocessing import StandardScaler, MinMaxScaler

# Z-score 标准化
scaler = StandardScaler()
data[numerical_features] = scaler.fit_transform(data[numerical_features])

# Min-Max 归一化
scaler = MinMaxScaler()
data[numerical_features] = scaler.fit_transform(data[numerical_features])

10. 数据类型转换 基础

data['age'] = data['age'].astype(int)
data['price'] = data['price'].astype(float)

11. 数据分箱 中等

将连续变量转换为分类变量

import numpy as np
bins = [0, 18.5, 24, 28, np.inf]
labels = ['偏瘦', '正常', '超重', '肥胖']
data['BMIRange'] = pd.cut(data['BMI'], bins, labels=labels, right=False)

age_bins = [0, 26, 36, 46, 56, 66, np.inf]
age_labels = ['≤25 岁', '26-35 岁', '36-45 岁', '46-55 岁', '56-65 岁', '>65 岁']
data['AgeRange'] = pd.cut(data['Age'], age_bins, labels=age_labels, right=False)

12. 条件判断与 np.where 中等

data['RiskLevel'] = np.where(data['days'] > 7, '高风险患者', '低风险患者')
data['is_abnormal'] = np.where(
    ((data['SensorType'] == 'Temperature') & ((data['Value'] < -10) | (data['Value'] > 50))) |
    ((data['SensorType'] == 'Humidity') & ((data['Value'] < 0) | (data['Value'] > 100))),
    True, False
)

13. 数据统计计算 基础

data['col'].mean()      # 平均值
data['col'].sum()       # 求和
data['col'].count()     # 计数
data['col'].min()       # 最小值
data['col'].max()       # 最大值
data['col'].std()       # 标准差
data['col'].value_counts()  # 频数统计

14. 日期时间处理 中等

使用 pandas 处理日期时间数据

from datetime import datetime

# 转换为日期时间类型
data['就诊日期'] = pd.to_datetime(data['就诊日期'])
data['诊断日期'] = pd.to_datetime(data['诊断日期'])

# 计算日期差值(天数)
data['诊断延迟'] = (data['诊断日期'] - data['就诊日期']).dt.days
data['病程'] = (datetime(2024, 9, 1) - data['诊断日期']).dt.days

15. 列名修改 基础

# 修改列名
data.rename(columns={'old_name': 'new_name'}, inplace=True)

# 去除列名空格
data.columns = data.columns.str.strip()

16. 字符串处理 基础

# 去除字符串前后空格
df = df.applymap(lambda x: x.strip() if isinstance(x, str) else x)

# 字符串分割提取
y = X.apply(lambda x: int(x.split(' ')[0]))

17. 分类变量编码 中等

from sklearn.preprocessing import LabelEncoder

# LabelEncoder 标签编码
label_encoder = LabelEncoder()
data_cleaned['fitness_level'] = label_encoder.fit_transform(data_cleaned['fitness_level'])

# get_dummies 独热编码
data_cleaned = pd.get_dummies(data_cleaned, drop_first=True)
X = pd.get_dummies(X)  # 将分类变量转为数值变量

18. 数据填充 基础

# 使用众数填充
data_filled = data.apply(lambda x: x.fillna(x.mode()[0]))

# 使用特定值填充
data['col'].fillna(value, inplace=True)

19. 数据类型强制转换 基础

# 转换为数值类型,无法转换的变为 NaN
df['horsepower'] = pd.to_numeric(df['horsepower'], errors='coerce')

# 转换为整数类型
data_cleaned.loc[:, 'Your age'] = pd.to_numeric(data_cleaned['Your age'], errors='coerce')
data_cleaned = data_cleaned.dropna(subset=['Your age'])
data_cleaned.loc[:, 'Your age'] = data_cleaned['Your age'].astype(int)

20. 删除列 基础

# 删除指定列
data_cleaned = data.drop(columns=['序号', '所用时间'])
X = data.drop(['SeriousDlqin2yrs', 'Unnamed: 0'], axis=1)
cleaned_data = data.drop(columns=['is_abnormal'])

21. 选择数值列 基础

# 选择数值类型列
numeric_cols = data.select_dtypes(include=['float64', 'int64']).columns

22. 行索引操作 基础

# 获取行数
initial_rows = data.shape[0]
deleted_rows = initial_rows - data.shape[0]

# 统计行数
num_duplicates = duplicates.sum()

第二章:机器学习建模(2.1.x, 2.2.x)

1. 模型导入 中等

from sklearn.linear_model import LogisticRegression, LinearRegression
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
from sklearn.tree import DecisionTreeRegressor
import xgboost as xgb
from xgboost import XGBRegressor

2. 模型实例化 中等

# Logistic 回归
model = LogisticRegression(max_iter=1000)

# 线性回归
pipeline = Pipeline([('scaler', StandardScaler()), ('linreg', LinearRegression())])

# 随机森林(100 棵树)
rf_model = RandomForestRegressor(n_estimators=100, random_state=42)

# XGBoost(100 棵树,学习率 0.05,最大深度 5)
xgb_model = XGBRegressor(n_estimators=1000, learning_rate=0.05, max_depth=5, 
                         subsample=0.8, colsample_bytree=0.8, random_state=42)

# 决策树回归
dt_model = DecisionTreeRegressor(random_state=42)

3. 模型训练 中等

# 训练模型
model.fit(X_train, y_train)
pipeline.fit(X_train, y_train)
rf_model.fit(X_train, y_train)
xgb_model.fit(X_train, y_train)

4. 模型预测 中等

# 预测
y_pred = model.predict(X_test)
y_pred = pipeline.predict(X_test)
y_pred_rf = rf_model.predict(X_test)
y_pred_xgb = xgb_model.predict(X_test)

5. 模型保存与加载 基础

import pickle
import joblib

# pickle 保存
with open('model.pkl', 'wb') as file:
    pickle.dump(model, file)

# joblib 保存
joblib.dump(model, 'model.pkl')

6. 模型评估指标 中等

from sklearn.metrics import classification_report, accuracy_score
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score

# 分类指标
report = classification_report(y_test, y_pred, zero_division=1)
accuracy = accuracy_score(y_test, y_pred)

# 回归指标
mse = mean_squared_error(y_test, y_pred)  # 均方误差
mae = mean_absolute_error(y_test, y_pred)  # 平均绝对误差
r2 = r2_score(y_test, y_pred)  # 决定系数

# 模型得分
train_score = model.score(X_train, y_train)
test_score = model.score(X_test, y_test)

7. 数据不平衡处理 - SMOTE 中等

from imblearn.over_sampling import SMOTE

# SMOTE 过采样
smote = SMOTE(random_state=42)
X_resampled, y_resampled = smote.fit_resample(X_train, y_train)

8. Pipeline 管道 中等

from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegression

# 创建包含标准化和回归的管道
pipeline = Pipeline([('scaler', StandardScaler()), ('linreg', LinearRegression())])
pipeline.fit(X_train, y_train)

9. 特征与目标变量定义 基础

# 定义自变量和因变量
X = data.drop(['SeriousDlqin2yrs', 'Unnamed: 0'], axis=1)
y = data['SeriousDlqin2yrs']

# 删除目标列
X = data.drop(columns=[target])
y = data[target]

# 选择特定列
X = data[['feature1', 'feature2', 'feature3']]

10. 结果保存 基础

# 保存预测结果
pd.DataFrame(y_pred, columns=['预测结果']).to_csv('results.txt', index=False)

# 保存对比结果
results = pd.DataFrame({'实际值': y_test, '预测值': y_pred})
results.to_csv('results.txt', index=False, sep='\t')

# 保存报告到文件
with open('report.txt', 'w') as file:
    file.write(report)
    file.write(f'模型准确率:{accuracy:.2f}\n')

11. 可视化 - 柱状图 中等

import matplotlib.pyplot as plt
import matplotlib.font_manager as fm

# 设置中文字体
font_path = 'C:/Windows/Fonts/simhei.ttf'
my_font = fm.FontProperties(fname=font_path)

# 绘制堆叠柱状图
treatment_outcome_distribution.plot(kind='bar', stacked=True)
plt.title('标题', fontproperties=my_font)
plt.xlabel('X 轴标签', fontproperties=my_font)
plt.ylabel('Y 轴标签', fontproperties=my_font)
plt.xticks(fontproperties=my_font)
plt.yticks(fontproperties=my_font)
plt.legend(prop=my_font)
plt.show()

12. 可视化 - 散点图 中等

import matplotlib.pyplot as plt

plt.scatter(data['age'], data['severity'])
plt.title('年龄和疾病严重程度的关系', fontproperties=my_font)
plt.xlabel('年龄', fontproperties=my_font)
plt.ylabel('疾病严重程度', fontproperties=my_font)
plt.show()

13. 可视化 - 饼图 中等

import matplotlib.pyplot as plt

plt.figure(figsize=(10, 6))
plt.pie(exercise_frequency_counts, autopct='%1.1f%%', startangle=90, 
        colors=plt.cm.Paired.colors)
plt.title('Distribution of Exercise Frequency')
plt.ylabel('')
plt.show()

14. 可视化 - 箱线图(Seaborn) 中等

import matplotlib.pyplot as plt
import seaborn as sns

# 设置图像尺寸
plt.figure(figsize=(12, 8))

# 识别数值列
numeric_cols = data.select_dtypes(include=['float64', 'int64']).columns

# 创建子图网格绘制箱线图
for i, col in enumerate(numeric_cols, 1):
    plt.subplot(3, 4, i)  # 3行4列的子图
    sns.boxplot(x=data[col])
    plt.title(col)

plt.tight_layout()  # 自动调整子图间距
plt.show()

15. 可视化 - 直方图 中等

import matplotlib.pyplot as plt

# 绘制单变量直方图
plt.figure(figsize=(10, 6))
plt.hist(data['age'], bins=20, edgecolor='black')
plt.title('年龄分布')
plt.xlabel('年龄')
plt.ylabel('人数')
plt.show()

# 使用 Pandas 绘制直方图
data['age'].plot(kind='hist', bins=20, figsize=(10, 6))
plt.show()

16. 可视化 - Pandas 内置绘图 中等

import pandas as pd
import matplotlib.pyplot as plt

# 数据框直接绘图
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})

# 折线图
df.plot(kind='line', figsize=(10, 6))

# 柱状图
df.plot(kind='bar', stacked=True)

# 堆叠柱状图
treatment_outcome = data.groupby('疾病类型')['治疗结果'].value_counts().unstack()
treatment_outcome.plot(kind='bar', stacked=True)

# 饼图
exercise_counts.plot.pie(autopct='%1.1f%%', startangle=90)

plt.show()

17. 可视化 - 子图布局 中等

import matplotlib.pyplot as plt

# 创建子图(方法1)
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(12, 8))
axes[0, 0].plot(x, y1)  # 左上角
axes[0, 1].scatter(x, y2)  # 右上角
axes[1, 0].hist(data)  # 左下角
axes[1, 1].pie(counts)  # 右下角

# 创建子图(方法2)
plt.subplot(2, 2, 1)  # 2行2列,第1个子图
plt.plot(x, y)
plt.subplot(2, 2, 2)  # 2行2列,第2个子图
plt.scatter(x, y)

plt.tight_layout()  # 自动调整间距
plt.show()

18. 可视化 - 中文字体设置 基础

import matplotlib.pyplot as plt
import matplotlib.font_manager as fm

# Windows 系统
font_path = 'C:/Windows/Fonts/simhei.ttf'
my_font = fm.FontProperties(fname=font_path)

# macOS 系统
font_path = '/System/Library/Fonts/PingFang.ttc'
my_font = fm.FontProperties(fname=font_path)

# Linux 系统
font_path = '/usr/share/fonts/truetype/wqy/wqy-microhei.ttc'
my_font = fm.FontProperties(fname=font_path)

# 使用中文字体
plt.title('中文标题', fontproperties=my_font)
plt.xlabel('中文X轴', fontproperties=my_font)
plt.ylabel('中文Y轴', fontproperties=my_font)
plt.xticks(fontproperties=my_font)
plt.yticks(fontproperties=my_font)
plt.legend(prop=my_font)

plt.show()

19. 分组统计 中等

# 分组并值计数
treatment_outcome_distribution = data.groupby('疾病类型')['治疗结果'].value_counts().unstack()

# 分组求平均值
gender_stats = data.groupby('Gender')[['Speed', 'Distance', 'Time']].mean()

第三章:深度学习与 ONNX 模型推理(3.2.x)

1. ONNX Runtime 基础 中等

ONNX (Open Neural Network Exchange) 是开放的神经网络交换格式,允许在不同框架之间迁移模型

import onnxruntime as ort

# 加载 ONNX 模型创建推理会话
ort_session = ort.InferenceSession('model.onnx')

# 获取模型输入输出信息
input_name = ort_session.get_inputs()[0].name
output_name = ort_session.get_outputs()[0].name

# 获取输入形状
input_shape = ort_session.get_inputs()[0].shape

2. PIL 图像加载与预处理 中等

from PIL import Image
import numpy as np

# 加载图片并转换为 RGB
image = Image.open('image.jpg').convert('RGB')

# 加载为灰度图
image = Image.open('image.png').convert('L')

# 调整大小(双线性插值)
image = image.resize((256, 256), Image.BILINEAR)
image = image.resize((28, 28), Image.ANTIALIAS)  # MNIST 使用抗锯齿

# 中心裁剪
w, h = image.size
left = (w - crop_size) / 2
top = (h - crop_size) / 2
image = image.crop((left, top, left + crop_size, top + crop_size))

# 转换为 numpy 数组
image_array = np.array(image, dtype=np.float32)

3. 图像归一化 中等

# 标准归一化(0-1)
image = image_array / 255.0

# ImageNet 均值和标准差归一化
mean = [0.485, 0.456, 0.406]
std = [0.229, 0.224, 0.225]
image = (image - mean) / std

# 自定义均值归一化
image_mean = np.array([127, 127, 127])
image = (image - image_mean) / 128

4. 维度变换 中等

# HWC 转 CHW(高度 - 宽度 - 通道 → 通道 - 高度 - 宽度)
image = np.transpose(image, (2, 0, 1))
image = np.transpose(image, [2, 0, 1])

# 添加 batch 维度(NCHW 格式)
image = image.reshape((1,) + image.shape)
image = np.expand_dims(image, axis=0)  # 添加 batch 维度
image = np.expand_dims(image, axis=1)  # 添加 channel 维度

# 确保数据类型为 float32
image = image.astype(np.float32)

5. 模型推理执行 中等

# 准备输入字典
ort_inputs = {ort_session.get_inputs()[0].name: image_array}

# 执行推理
ort_outs = ort_session.run(None, ort_inputs)
output = ort_session.run([output_name], {input_name: processed_image})[0]

6. Softmax 概率计算 中等

import scipy.special

# 应用 softmax 函数获取概率分布
probabilities = scipy.special.softmax(output, axis=-1)
accuracy = scipy.special.softmax(output, axis=-1)

7. Top-K 预测结果 中等

# 获取预测类别索引
predicted_class = np.argmax(ort_outs[0])
predicted_idx = np.argmax(accuracy)

# 获取 Top-5 索引(降序排列)
top5_idx = np.argsort(probabilities)[-5:][::-1]
top5_prob = probabilities[top5_idx]

# 获取概率百分比
prob_percentage = accuracy[predicted_idx] * 100

8. 标签映射 基础

# 从文件加载标签
with open('labels.txt') as f:
    labels = [line.strip() for line in f.readlines()]

# 情感标签映射表
emotion_table = {
    'neutral': 0,
    'happy': 1,
    'sad': 2,
    'angry': 3,
    'fearful': 4,
    'disgusted': 5,
    'surprised': 6
}

# 获取预测标签
predicted_label = labels[predicted_idx]
predicted_emotion = emotion_table[predicted_label]

9. OpenCV 图像处理 中等

import cv2

# 读取图片(BGR 格式)
orig_image = cv2.imread(img_path)

# BGR 转 RGB
image = cv2.cvtColor(orig_image, cv2.COLOR_BGR2RGB)

# 调整大小
image = cv2.resize(image, (320, 240))

# 绘制矩形框
cv2.rectangle(orig_image, (box[0], box[1]), (box[2], box[3]), (255, 255, 0), 4)

# 保存结果图片
cv2.imwrite(os.path.join(result_path, file_path), orig_image)

10. 目标检测后处理 困难

def predict(width, height, confidences, boxes, prob_threshold, iou_threshold=0.3, top_k=-1):
    boxes = boxes[0]
    confidences = confidences[0]
    picked_box_probs = []
    picked_labels = []
    
    for class_index in range(1, confidences.shape[1]):
        probs = confidences[:, class_index]
        mask = probs > prob_threshold
        probs = probs[mask]
        if probs.shape[0] == 0:
            continue
        subset_boxes = boxes[mask, :]
        box_probs = np.concatenate([subset_boxes, probs.reshape(-1, 1)], axis=1)
        box_probs = box_utils.hard_nms(box_probs, iou_threshold=iou_threshold, top_k=top_k)
        picked_box_probs.append(box_probs)
        picked_labels.extend([class_index] * box_probs.shape[0])
    
    if not picked_box_probs:
        return np.array([]), np.array([]), np.array([])
    
    picked_box_probs = np.concatenate(picked_box_probs)
    # 坐标缩放回原图尺寸
    picked_box_probs[:, 0] *= width
    picked_box_probs[:, 1] *= height
    picked_box_probs[:, 2] *= width
    picked_box_probs[:, 3] *= height
    
    return picked_box_probs[:, :4].astype(np.int32), np.array(picked_labels), picked_box_probs[:, 4]

11. 文件与目录操作 基础

import os

# 检查目录是否存在
if not os.path.exists(result_path):
    os.makedirs(result_path)

# 获取目录下所有文件
listdir = os.listdir(path)

# 拼接路径
img_path = os.path.join(path, file_path)

# 遍历目录文件
for file_path in listdir:
    img_path = os.path.join(path, file_path)

12. 时间测量 基础

import time

# 记录开始时间
time_time = time.time()

# 执行推理
output = session.run([output_name], {input_name: processed_image})

# 计算耗时
print("cost time:{}".format(time.time() - time_time))

13. 断言检查 基础

# 形状检查
assert img_data.shape == input_shape, \
    f"Expected shape {input_shape}, but got {img_data.shape}"

14. 自定义预处理函数 中等

def preprocess_image(image, resize_size=256, crop_size=224, 
                      mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]):
    """图像预处理函数"""
    image = image.resize((resize_size, resize_size), Image.BILINEAR)
    w, h = image.size
    left = (w - crop_size) / 2
    top = (h - crop_size) / 2
    image = image.crop((left, top, left + crop_size, top + crop_size))
    image = np.array(image).astype(np.float32)
    image = image / 255.0
    image = (image - mean) / std
    image = np.transpose(image, (2, 0, 1))
    image = image.reshape((1,) + image.shape)
    return image

def preprocess(image_path):
    input_shape = (1, 1, 64, 64)
    img = Image.open(image_path).convert('L')
    img = img.resize((64, 64), Image.ANTIALIAS)
    img_data = np.array(img, dtype=np.float32)
    img_data = np.expand_dims(img_data, axis=0)
    img_data = np.expand_dims(img_data, axis=1)
    assert img_data.shape == input_shape
    return img_data

第四章:综合应用题与方案设计(4.1.x, 4.2.x)

💡 简答题备考建议

  • 掌握数据处理完整流程:数据采集 → 数据清洗 → 数据预处理 → 特征工程 → 模型训练 → 模型评估
  • 理解每个步骤的目的和常用方法
  • 能够清晰描述技术术语和算法原理
  • 结合实际应用场景进行作答

1. AI 应用场景分析 中等

常见应用场景:
  • 智能音箱:语音识别、自然语言处理、语音合成
  • 智能照明系统:环境感知、智能控制、节能优化
  • 智能健康手环:生理数据采集、健康监测、异常预警
  • 智能家居环境控制:温湿度监测、自动调节、场景模式

2. 数据处理流程设计 中等

标准流程:
  1. 数据采集:传感器数据、日志数据、用户行为数据
  2. 数据清洗:缺失值处理、重复值处理、异常值处理
  3. 数据转换:数据类型转换、格式标准化、编码处理
  4. 特征工程:特征提取、特征选择、特征转换
  5. 模型训练:选择合适算法、划分数据集、训练模型
  6. 模型评估:评估指标、交叉验证、模型优化
  7. 部署上线:模型导出、API封装、性能监控

3. 算法选择与比较 中等

常用算法对比:
算法 适用场景 优点 缺点
线性回归 预测连续值 简单、易解释 假设线性关系
逻辑回归 二分类问题 输出概率、易解释 特征需独立
决策树 分类/回归 直观、处理非线性 易过拟合
随机森林 分类/回归 鲁棒性强、效果好 训练慢、难解释
XGBoost 分类/回归 精度高、速度快 参数多、易过拟合

4. 模型评估指标 中等

分类任务指标:
  • 准确率(Accuracy):正确预测数/总样本数
  • 精确率(Precision):预测为正类的样本中真正为正类的比例
  • 召回率(Recall):真正为正类的样本中被预测为正类的比例
  • F1 分数:精确率和召回率的调和平均数
  • 混淆矩阵:TP、TN、FP、FN 的矩阵表示
回归任务指标:
  • MSE(均方误差):预测值与真实值差的平方的平均值
  • RMSE(均方根误差):MSE 的平方根
  • MAE(平均绝对误差):预测值与真实值差的绝对值的平均值
  • R²(决定系数):模型解释方差的比例

5. 数据不平衡处理 中等

处理方法:
  • 过采样(Oversampling):增加少数类样本(SMOTE 算法)
  • 欠采样(Undersampling):减少多数类样本
  • 合成样本:SMOTE、ADASYN 等算法生成合成样本
  • 类别权重:在模型训练时给少数类更高权重
  • 集成方法:使用多个模型组合处理不平衡数据

📊 考试题型分布与考点总结

章节 题号范围 题型 题量 主要考点 难度等级 分值占比
第一章 1.1.1 - 1.1.5 数据处理编程题 5 题 Pandas 数据读取、清洗、分组聚合、数据透视、分箱、异常值处理 中等 12.5%
第一章 1.2.1 - 1.2.5 简答题 5 题 数据处理流程设计、业务理解 中等 12.5%
第二章 2.1.1 - 2.1.5 机器学习编程题 5 题 数据预处理、特征工程、数据集划分、可视化 中等 12.5%
第二章 2.2.1 - 2.2.5 机器学习编程题 5 题 模型训练(Logistic、线性回归、随机森林、XGBoost、决策树)、模型评估、数据不平衡处理 中等 12.5%
第三章 3.1.1 - 3.1.5 简答题 5 题 AI 应用场景设计、系统架构 中等 12.5%
第三章 3.2.1 - 3.2.5 深度学习编程题 5 题 ONNX 模型加载、图像预处理、模型推理、目标检测 困难 12.5%
第四章 4.1.1 - 4.1.5 简答题 5 题 综合应用题、方案设计 困难 12.5%
第四章 4.2.1 - 4.2.5 简答题 5 题 综合应用题、方案设计 困难 12.5%

💡 高分备考策略

🎯 编程题高分技巧(25 分)

  • Pandas 核心函数必须形成肌肉记忆:read_csv/read_excel、head、info、describe、groupby、agg、pivot_table、cut、isnull、dropna、fillna、drop_duplicates、to_csv
  • 数据预处理标准流程
    1. 读取数据 → pd.read_csv()
    2. 数据探索 → head()info()describe()
    3. 缺失值处理 → isnull().sum()dropna()fillna()
    4. 重复值处理 → duplicated().sum()drop_duplicates()
    5. 异常值处理 → IQR 方法、条件过滤
    6. 数据类型转换 → astype()to_numeric()
    7. 特征编码 → get_dummies()LabelEncoder
    8. 数据标准化 → StandardScalerMinMaxScaler
    9. 保存结果 → to_csv(index=False)
  • 机器学习建模模板
    1. 导入模型 → from sklearn.xxx import XXX
    2. 定义特征和目标 → X = data.drop()y = data[]
    3. 数据集划分 → train_test_split(X, y, test_size=0.2, random_state=42)
    4. 模型实例化 → model = XXX(n_estimators=100, random_state=42)
    5. 训练模型 → model.fit(X_train, y_train)
    6. 模型预测 → y_pred = model.predict(X_test)
    7. 模型评估 → accuracy_scoreclassification_reportmean_squared_errorr2_score
    8. 模型保存 → pickle.dump()joblib.dump()
  • ONNX 推理模板必须背下来
    1. 加载模型 → ort.InferenceSession('model.onnx')
    2. 获取输入输出名 → get_inputs()[0].nameget_outputs()[0].name
    3. 加载图片 → Image.open().convert('RGB')
    4. 图像预处理 → resize → crop → to_array → normalize → transpose → expand_dims
    5. 执行推理 → session.run([output_name], {input_name: image})
    6. 概率计算 → scipy.special.softmax(output, axis=-1)
    7. 获取结果 → np.argmax()np.argsort()[-5:][::-1]
    8. 标签映射 → labels[predicted_idx]
  • 注意细节避免丢分
    • 保存 CSV 时记得 index=False
    • 数据类型转换使用 astype(int/float)
    • 维度变换注意顺序 transpose((2,0,1))
    • 添加维度 reshape((1,)+shape)expand_dims(axis=0)
    • 确保数据类型 astype(np.float32)

📝 简答题高分技巧(15 分)

  • 数据处理流程题
    • 明确写出每个步骤:数据采集 → 数据清洗 → 数据预处理 → 特征工程 → 模型选择 → 训练评估
    • 说明每个步骤的目的和常用方法
    • 结合具体业务场景举例
  • AI 系统设计题
    • 系统架构图:数据采集层 → 数据处理层 → 模型层 → 应用层
    • 说明使用的具体技术和算法
    • 考虑实际部署和优化问题
  • 算法原理题
    • 算法的基本思想和工作流程
    • 优缺点分析
    • 适用场景

⏰ 时间分配建议(2 小时上机)

  • 编程题(25 分):建议 60-70 分钟
    • 数据处理题(1.1.x):10-12 分钟/题
    • 机器学习题(2.1.x, 2.2.x):12-15 分钟/题
    • 深度学习题(3.2.x):15-18 分钟/题
  • 简答题(15 分):建议 40-50 分钟
    • 每题 8-10 分钟
    • 先列提纲再详细作答
  • 检查时间:预留 10 分钟
    • 检查代码是否有语法错误
    • 检查输出文件是否正确保存
    • 检查简答题是否完整

🔥 考前冲刺建议

  • 第 1-2 天:集中练习 Pandas 数据处理题(1.1.x),熟练掌握所有核心函数
  • 第 3-4 天:练习机器学习建模题(2.1.x, 2.2.x),背下模型训练模板
  • 第 5 天:专攻 ONNX 深度学习题(3.2.x),背下图像预处理和推理流程
  • 第 6 天:复习简答题,理解完整的数据处理和 AI 项目流程
  • 第 7 天:全真模拟,按考试时间完成一套完整试题

📌 万能代码模板(考前必背)

# ===== 1. Pandas 数据处理模板 =====
import pandas as pd
import numpy as np

# 读取数据
data = pd.read_csv('data.csv')

# 数据探索
print(data.head())
print(data.info())
print(data.describe())

# 缺失值处理
print(data.isnull().sum())
data = data.dropna()
# 或 data['col'].fillna(method='ffill', inplace=True)

# 重复值处理
print(data.duplicated().sum())
data = data.drop_duplicates()

# 异常值处理(IQR 方法)
Q1 = data.quantile(0.25)
Q3 = data.quantile(0.75)
IQR = Q3 - Q1
data = data[~((data < (Q1 - 1.5 * IQR)) | (data > (Q3 + 1.5 * IQR))).any(axis=1)]

# 数据分箱
bins = [0, 18, 35, 60, np.inf]
labels = ['青年', '中年', '中老年', '老年']
data['age_group'] = pd.cut(data['age'], bins, labels=labels, right=False)

# 分组统计
result = data.groupby('category')['value'].agg(['count', 'mean', 'sum'])

# 保存结果
data.to_csv('output.csv', index=False)


# ===== 2. 机器学习建模模板 =====
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, classification_report
import pickle

# 定义特征和目标
X = data.drop(['target'], axis=1)
y = data['target']

# 数据集划分
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42
)

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

# 模型预测
y_pred = model.predict(X_test)

# 模型评估
accuracy = accuracy_score(y_test, y_pred)
print(f"Accuracy: {accuracy:.2f}")
print(classification_report(y_test, y_pred))

# 模型保存
with open('model.pkl', 'wb') as f:
    pickle.dump(model, f)


# ===== 3. ONNX 推理模板 =====
import onnxruntime as ort
from PIL import Image
import numpy as np
import scipy.special

# 加载模型
session = ort.InferenceSession('model.onnx')
input_name = session.get_inputs()[0].name
output_name = session.get_outputs()[0].name

# 加载并预处理图像
image = Image.open('test.jpg').convert('RGB')
image = image.resize((256, 256), Image.BILINEAR)
image = np.array(image, dtype=np.float32) / 255.0
image = np.transpose(image, (2, 0, 1))
image = image.reshape((1,) + image.shape)

# 模型推理
output = session.run([output_name], {input_name: image})[0]

# 获取预测结果
probabilities = scipy.special.softmax(output, axis=-1)
predicted_idx = np.argmax(probabilities)
predicted_label = labels[predicted_idx]
print(f"Predicted: {predicted_label}")

🎓 祝您考试顺利,取得好成绩!

熟练掌握以上 150+ 语法点,上机考试无忧!