【发布时间】:2019-09-06 15:28:09
【问题描述】:
我正在尝试使用三个与银行历史相关的二元解释变量:违约、住房和贷款,以使用逻辑回归分类器预测二元响应变量。
我有以下数据集:
将文本 no/yes 转换为整数 0/1 的映射函数
convert_to_binary = {'no' : 0, 'yes' : 1}
default = bank['default'].map(convert_to_binary)
housing = bank['housing'].map(convert_to_binary)
loan = bank['loan'].map(convert_to_binary)
response = bank['response'].map(convert_to_binary)
我添加了我的三个解释变量和对数组的响应
data = np.array([np.array(default), np.array(housing), np.array(loan),np.array(response)]).T
kfold = KFold(n_splits=3)
scores = []
for train_index, test_index in kfold.split(data):
X_train, X_test = data[train_index], data[test_index]
y_train, y_test = response[train_index], response[test_index]
model = LogisticRegression().fit(X_train, y_train)
pred = model.predict(data[test_index])
results = model.score(X_test, y_test)
scores.append(results)
print(np.mean(scores))
我的准确率始终是 100%,我知道这是不正确的。准确率应该在 50-65% 左右?
我做错了什么吗?
【问题讨论】:
-
你的数据集有多大?
-
4521 行 × 17 列
-
我想到了几件事,但主要是,
model_data是什么?如果model_data与data相同,则您将响应变量包含在预测变量中,这将解释您的完美模型。
标签: python numpy machine-learning scikit-learn