我目前正在与既有分类和连续特征的数据帧的工作多分类,看起来像这样:Logistic回归 - 与分类变量
我想运行一个逻辑回归预测目标值。在这种情况下的目标值是种族,可以是“A”,“W”,“B”,“H”,“N”或“O”,代表“亚洲”,“白色”,“黑色“,”西班牙裔“,”美洲原住民“或”其他“。
我已经将所有功能转换为虚拟变量(除了来自“比赛”栏),在一个名为“傻瓜”的新数据框中。训练模式,我用这个代码:
from sklearn import linear_model, metrics
X = dummies.drop("race", axis=1)
y = dummies["race"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=101)
from sklearn.linear_model import LogisticRegression
logmodel = LogisticRegression()
logmodel.fit(X_train, y_train)
predictions = logmodel.predict(X_test)
我没有得到任何错误,但是,当我在看分类矩阵我得到的1.00都准确率,召回和f1-分满分。这似乎有点太好,不能成为真的...我做错了什么?
这是我用假人转换代码:
dummies = pd.get_dummies(df[["date", "armed", "age", "gender", "city", "state", "signs_of_mental_illness", "threat_level", "flee", "body_camera", "total_population"]], drop_first=True)
dummies = pd.concat([df, dummies], axis=1)
dummies.drop(df[["date", "armed", "age", "gender", "city", "state", "signs_of_mental_illness", "threat_level", "flee", "body_camera", "total_population"]], axis=1, inplace=True)
你可以分享你的数据,你使用的代码将其转换为虚拟变量? –
@VivekKumar,把它放在问题的最后。 –
和数据?请做一个完整的[mvce示例](https://stackoverflow.com/help/mcve) –