Python:如何使用SKlearn使用多项式Lo​​gistic回归 [英] Python : How to use Multinomial Logistic Regression using SKlearn

查看:449
本文介绍了Python:如何使用SKlearn使用多项式Lo​​gistic回归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个测试数据集和一个训练数据集,如下所示.我提供了带有最小记录的样本数据,但是我的数据有1000多个记录.这里E是我需要使用算法预测的目标变量.它只有四个类别,例如1,2,3,4.它只能使用这些值中的任何一个.

I have a test dataset and train dataset as below. I have provided a sample data with min records, but my data has than 1000's of records. Here E is my target variable which I need to predict using an algorithm. It has only four categories like 1,2,3,4. It can take only any of these values.

训练数据集:

A    B    C    D    E
1    20   30   1    1
2    22   12   33   2
3    45   65   77   3
12   43   55   65   4
11   25   30   1    1
22   23   19   31   2
31   41   11   70   3
1    48   23   60   4

测试数据集:

A    B    C    D    E
11   21   12   11
1    2    3    4
5    6    7    8 
99   87   65   34 
11   21   24   12

由于E只有4个类别,所以我想到了使用多项逻辑回归(1 vs Rest Logic)来预测这一点.我正在尝试使用python来实现它.

Since E has only 4 categories, I thought of predicting this using Multinomial Logistic Regression (1 vs Rest Logic). I am trying to implement it using python.

我知道我们需要在变量中设置这些目标并使用算法来预测以下任何一个值的逻辑:

I know the logic that we need to set these targets in a variable and use an algorithm to predict any of these values:

output = [1,2,3,4]

但是我在如何使用python(sklearn)来遍历这些值的问题上陷入了困境,我应该使用哪种算法来预测输出值?任何帮助将不胜感激

But I am stuck at a point on how to use it using python (sklearn) to loop through these values and what algorithm should I use to predict the output values? Any help would be greatly appreciated

推荐答案

LogisticRegression can handle multiple classes out-of-the-box.

X = df[['A', 'B', 'C', 'D']]
y = df['E']
lr = LogisticRegression()
lr.fit(X, y)
preds = lr.predict(X)  # will output array with integer values.

这篇关于Python:如何使用SKlearn使用多项式Lo​​gistic回归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆