generated from LufsX/Experiment-LogReg
This commit is contained in:
+2
-11
@@ -55,19 +55,10 @@ def predict_logreg(inX, weights):
|
|||||||
# 从文件中加载数据
|
# 从文件中加载数据
|
||||||
def load_data(filepath):
|
def load_data(filepath):
|
||||||
data = pd.read_csv(filepath, header=None, na_values='?', delim_whitespace=True)
|
data = pd.read_csv(filepath, header=None, na_values='?', delim_whitespace=True)
|
||||||
|
data.fillna(0, inplace=True)
|
||||||
# 使用SimpleImputer进行中位数填充
|
|
||||||
imputer = SimpleImputer(strategy='median')
|
|
||||||
data_imputed = imputer.fit_transform(data)
|
|
||||||
data = pd.DataFrame(data_imputed)
|
|
||||||
|
|
||||||
X = data.iloc[:, :-1].to_numpy() # 特征
|
X = data.iloc[:, :-1].to_numpy() # 特征
|
||||||
y = data.iloc[:, -1].to_numpy() # 标签
|
y = data.iloc[:, -1].to_numpy() # 标签
|
||||||
# 使用MinMaxScaler进行特征缩放
|
return X, y
|
||||||
scaler = MinMaxScaler()
|
|
||||||
X = scaler.fit_transform(X)
|
|
||||||
return X, y
|
|
||||||
|
|
||||||
# 准确率计算函数
|
# 准确率计算函数
|
||||||
def calculate_accuracy(X, y, weights):
|
def calculate_accuracy(X, y, weights):
|
||||||
predictions = np.array([predict_logreg(x, weights) for x in X])
|
predictions = np.array([predict_logreg(x, weights) for x in X])
|
||||||
|
|||||||
Reference in New Issue
Block a user