为什么我的逻辑回归模型获得100%的准确性?

问题描述 投票:0回答:1

导入库

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import sklearn 
from sklearn import preprocessing
import seaborn as sns
%matplotlib inline

读取数据

 df =pd.read_csv('./EngineeredData_2.csv')
    df =df.dropna()

将数据拆分为x和y:

X= df.drop (['Week','Div', 'Date', 'HomeTeam', 'AwayTeam','HTHG', 'HTAG','HTR', 
            'FTAG', 'FTHG','HGKPP', 'AGKPP', 'FTR'], axis =1)

将y转换为整数:

 L = preprocessing.LabelEncoder ()
    matchresults = L.fit_transform (list (df['FTR']))
    y =list(matchresults)

将数据拆分为训练并进行测试:

from sklearn.model_selection import train_test_split
X_tng,X_tst, y_tng, y_tst =train_test_split (X, y, test_size = 50, shuffle=False)
X_tng.head()

导入类

from sklearn.linear_model import LogisticRegression

实例化模型

logreg = LogisticRegression ()

使模型与数据匹配

 logreg.fit (X_tng, y_tng)

预测测试数据y_pred = logreg.predict(X_tst)

    acc = logreg. score (X_tst, y_tst)
    print (acc)

准确度达到100%是否有意义?

python pandas scikit-learn logistic-regression
1个回答
0
投票
X= df.drop('FTR', axis =1)
© www.soinside.com 2019 - 2024. All rights reserved.