scikit学习用分数预测概率

时间:2019-02-27 22:39:14

标签: python scikit-learn probability

我有此代码:

# example of making multiple probability predictions
from sklearn.linear_model import LogisticRegression
from sklearn.datasets.samples_generator import make_blobs
from sklearn import preprocessing
import numpy as np

f = open("Football.txt", "r")
lines = f.readlines()
XX = []
YY = []
print(len(lines))
for k in range(1,len(lines)):
    D = [float(lines[k].split(' ')[0]), float(lines[k].split(' ')[1]), 
         float(lines[k].split(' ')[3]), float(lines[k].split(' ')[4])]
    p = int(float(lines[k].split(' ')[6]))
    YY.append(p)
    XX.append(D)

# fit final model
model = LogisticRegression()
model.fit(XX, YY)

# new instances where we do not know the answer
Xnew = [[0.4, -0.29, 0, -0.41], 
        [0, -0.41, 0.4, -0.29]]

# make a prediction
ynew = model.predict_proba(Xnew)

# show the inputs and predicted probabilities
for i in range(len(Xnew)):
    print("X=%s, Predicted=%s" % (Xnew[i], ynew[i]))

在YY中,我仅具有有关团队获胜,平局,失败的信息。现在,我想在团队之间添加得分信息。我可以使用函数predict_proba或其他功能吗?

0 个答案:

没有答案