如何解释我的逻辑回归结果?

数据挖掘 Python 分类 scikit-学习 逻辑回归 统计模型
2022-02-26 13:51:13

我很难解释我的逻辑回归结果。

我有几个问题。首先,我如何检查一个功能是否对其他人更重要,例如它是否具有真正的意义。

我有一个0.58非常糟糕的准确度。无论如何,为什么RFECV特征选择器告诉我使用 feature1 来获得最佳结果,但是通过在我使用 hte库的sklearn地方训练我的模型,模型的所有 5 个变量都会稍微好一些?statsmodels

另外,为什么我的两个模型在我训练它时sklearnstatsmodels产生不同的结果? 在此处输入图像描述

这真的让我很困惑。如果有人能告诉我一种简单的方法来解释我的结果并在一个库中完成它,那就太好了。

我的代码片段

import statsmodels.api as sm
X = df_n_4[cols]
y = df_n_4['Survival']

# use train/test split with different random_state values
# we can change the random_state values that changes the accuracy scores
# the scores change a lot, this is why testing scores is a high-variance estimate
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=2)
logit_model = sm.Logit(y_train, X_train).fit()
y_pred = logit_model.predict(X_test)
cf_matrix = confusion_matrix(y_test, y_pred.round())
sns.heatmap(cf_matrix, annot=True)
plt.title('Accuracy:{}'.format(accuracy_score(y_test, y_pred.round())))
plt.ylabel('Actual Szenario');
plt.xlabel('Predicted Szenario');
plt.show()

第2部分

X = df_n_4[cols]
y = df_n_4['Srvival']

# use train/test split with different random_state values
# we can change the random_state values that changes the accuracy scores
# the scores change a lot, this is why testing scores is a high-variance estimate
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=2)
print(len(y_train)," Testdata")

# check classification scores of logistic regression
logreg = LogisticRegression()
logreg.fit(X_train, y_train)
y_pred = logreg.predict(X_test)
print('Train/Test split results:')
print(logreg.__class__.__name__+" accuracy is %2.3f" % accuracy_score(y_test, y_pred))
plt.title('Accuracy Score: {0}, Variablen: feature1'.format(round(accuracy_score(y_test, y_pred),2), size = 15))
cf_matrix = confusion_matrix(y_test, y_pred)
sns.heatmap(cf_matrix, annot=True)
plt.ylabel('Actual Szenario');
plt.xlabel('Predicted Szenario');
plt.show()

我没有太多的统计背景,所以请放轻松!我将提供您需要的任何进一步信息。非常感谢,我被困一周以来,正如我所阅读和进一步所做的那样,让我更加困惑。

0个回答
没有发现任何回复~