简体   繁体   English

为什么我的逻辑回归模型准确率达到 100%?

[英]Why am I getting 100% accuracy for my logistic regression model?

Import the libraries导入库

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

Reading the data读取数据

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

Split the data into x and y:将数据拆分为 x 和 y:

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

Trarnsoforming y into integers:将 y 变换为整数:

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

Split the data into train and test:将数据拆分为训练和测试:

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()

import the class导入类

from sklearn.linear_model import LogisticRegression

Instantiate the model实例化模型

logreg = LogisticRegression ()

Fit the model with the data用数据拟合模型

 logreg.fit (X_tng, y_tng)

Predict the test data y_pred = logreg.predict (X_tst)预测测试数据 y_pred = logreg.predict(X_tst)

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

Does the accuracy make sense to be 100%?准确率达到 100% 有意义吗?

The problem is that you unintentionally dropped all of your features and only retained your target value in x .问题是您无意中删除了所有功能,只保留了x中的目标值。 So, you are attempting to explain the target value with the target value itself, which of course will give you 100% accuracy.因此,您试图用目标值本身来解释目标值,这当然会给您 100% 的准确性。 You defined your features columns as:您将功能列定义为:

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

But you should have defined them as:但是您应该将它们定义为:

X= df.drop('FTR', axis =1)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的逻辑回归 model 的准确率 go 超过 100%? - Why does my accuracy go over 100% on my logistic regression model? 为什么该模型在 SVM、随机森林分类器和逻辑回归方面获得 100% 的准确率? - Why is the model getting 100% accuracy for SVM, Random-forest Classifier and Logistic Regression? 为什么我的逻辑回归的准确性这么小? - Why the accuracy of my logistic regression is so small? 我在所有机器学习模型上都获得了 100% 的准确率。 我的模型有什么问题 - I am getting a 100% accuracy on all my machine learning models. What is wrong with my model 为什么在使用线性回归 model 预测 python 中的股票价格时,准确率达到 99%? - Why am I getting 99% accuracy when using a Linear Regression model to predict stock prices in python? 如何提高我的逻辑回归 model 的准确度和精度? - How to Increase accuracy and precision for my logistic regression model? 在我的 DecisionTree 模型上获得 100% 的准确性 - Getting 100% Accuracy on my DecisionTree Model 为什么我得到一条几乎是直线的 model 精度曲线? - Why am I getting an almost straight line model accuracy curve? 为什么在将 RandomSearchCV 或 GridSearchCV 与逻辑回归一起使用时出现错误? - why am i getting an error while using either RandomSearchCV or GridSearchCV with logistic regression? 为什么我在python中使用梯度下降来获得逻辑回归的负成本函数? - Why am I getting a negative cost function for logistic regression using gradient descent in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM