人工智能(Artificial Intelligence,简称AI)是通过计算机模拟人类智能的系统,核心在于学习和推理。
Google Translate:支持实时语音翻译,极大方便国际交流。
机器学习是AI的核心,通过数据训练模型以解决具体任务。
使用线性回归预测房价:
from sklearn.linear_model import LinearRegression
import numpy as np
X = np.array([[1], [2], [3]]) # 房屋面积
y = np.array([150, 200, 250]) # 房价
model = LinearRegression().fit(X, y)
print(model.predict([[2.5]])) # 输出预测值
用折线图展示数据点与模型拟合线。
基于神经网络的学习方法,适合解决复杂任务。
用TensorFlow实现手写数字分类:
import tensorflow as tf
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5)
展示手写数字图片及分类结果。
通过计算机理解和生成自然语言。
使用Hugging Face库进行情感分析:
from transformers import pipeline
classifier = pipeline("sentiment-analysis")
result = classifier("I love AI training!")[0]
print(f"Label: {result['label']}, Score: {result['score']:.2f}")
输入文本与情感分析结果对比。
对比PyTorch与TensorFlow实现简单神经网络。
分析业务需求,如构建用户产品推荐系统。
清理数据并处理缺失值:
import pandas as pd
data = pd.read_csv('sales_data.csv')
data = data.dropna() # 清理缺失数据
print(data.head())
使用推荐系统模型训练用户-产品关系。
评估模型性能,如准确率、召回率。
用FastAPI部署模型:
from fastapi import FastAPI
app = FastAPI()
@app.get("/predict")
def predict(user_id: int):
return {"recommendations": ["product1", "product2"]}
鼓励现场提问,结合学员案例提供针对性指导。