多变量逻辑回归python_Python:如何使用SKlearn使用多项逻辑回归

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.

Training Dataset:

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

Test Dataset:

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

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]

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.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值