导入库
Positioned.fill(
child: Image.asset('images/back.png', fit: BoxFit.cover),
right: 0,
left: 0
);
读取数据
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
将数据分为x和y:
df =pd.read_csv('./EngineeredData_2.csv')
df =df.dropna()
将y整形为整数:
X= df.drop (['Week','Div', 'Date', 'HomeTeam', 'AwayTeam','HTHG', 'HTAG','HTR',
'FTAG', 'FTHG','HGKPP', 'AGKPP', 'FTR'], axis =1)
将数据拆分为训练并进行测试:
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 ()
预测测试数据 y_pred = logreg.predict(X_tst)
logreg.fit (X_tng, y_tng)
准确度达到100%有意义吗?
答案 0 :(得分:0)
问题是您无意中删除了所有功能,而仅将目标值保留在x
中。因此,您试图用目标值本身来解释目标值,这当然会给您100%的准确性。您将功能列定义为:
X= df.drop (['Week','Div', 'Date', 'HomeTeam', 'AwayTeam','HTHG', 'HTAG','HTR',
'FTAG', 'FTHG','HGKPP', 'AGKPP', 'FTR'], axis =1)
但是您应该将它们定义为:
X= df.drop('FTR', axis =1)