更新 function.py
Gitea Actions Experiment Test / Experiment-Actions (push) Successful in 11s

This commit is contained in:
2024-11-03 04:27:56 +08:00
parent 8c88b6c5b9
commit 90e2759dcd
+8 -11
View File
@@ -16,16 +16,16 @@ import numpy as np
id = "202210423208"
name = "刘义天"
# 加载数据并添加特征交互项
# 加载数据并添加非线性特征
def load_data(filepath):
"""
从文件中加载数据并生成特征交互项。
从文件中加载数据并生成非线性特征。
Args:
- filepath (str): 数据文件路径
Returns:
- X (numpy array): 包含特征交互项的特征数据
- X (numpy array): 包含非线性特征的特征数据
- y (numpy array): 标签数据
"""
# 读取数据,指定分隔符为空格,缺失值符号为 '?'
@@ -44,15 +44,12 @@ def load_data(filepath):
X = data[:, :-1]
y = data[:, -1]
# 生成特征交互项
n = X.shape[1]
interaction_features = []
for i in range(n):
for j in range(i + 1, n):
interaction_features.append((X[:, i] * X[:, j]).reshape(-1, 1))
# 生成非线性特征 (平方和对数)
square_features = X ** 2
log_features = np.log1p(X) # 使用 log1p 避免 log(0)
# 将交互特征添加到原特征集
X = np.hstack([X] + interaction_features)
# 将非线性特征添加到原特征集
X = np.hstack([X, square_features, log_features])
return X, y