import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression # 确保正确导入 import torch def test_numpy(): print("Testing NumPy...") a = np.array([1, 2, 3]) b = np.array([4, 5, 6]) c = a + b print("NumPy array sum:", c) def test_pandas(): print("\nTesting Pandas...") data = {'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 35]} df = pd.DataFrame(data) print("Pandas DataFrame:") print(df) def test_matplotlib(): print("\nTesting Matplotlib...") x = np.linspace(0, 10, 100) y = np.sin(x) plt.plot(x, y) plt.title("Sine Wave") plt.xlabel("x") plt.ylabel("sin(x)") plt.show() def test_sklearn(): print("\nTesting Scikit-learn (Linear Regression)...") X = np.array([[1], [2], [3]]) # 特征变量 y = np.array([2, 4, 6]) # 目标变量 model = LinearRegression() model.fit(X, y) prediction = model.predict() # 提供输入特征 print("Prediction for x=4:", prediction[0]) def test_torch(): print("\nTesting PyTorch...") x = torch.tensor([1.0, 2.0, 3.0]) y = x * 2 print("Torch tensor result:", y) if __name__ == "__main__": test_numpy() test_pandas() test_matplotlib() # test_sklearn() test_torch()