Python 3.x (Python 3)使用用户输入Elo对数据集进行分类,以建议基于国际象棋数据集的开局动作?

Python 3.x (Python 3)使用用户输入Elo对数据集进行分类,以建议基于国际象棋数据集的开局动作?,python-3.x,pandas,numpy,artificial-intelligence,naivebayes,Python 3.x,Pandas,Numpy,Artificial Intelligence,Naivebayes,我只是想寻求一点帮助。我正在努力弄清楚我所做的是正确的还是错误的,即使天真的Bayes是正确的方法 我希望用户能够输入他们的elo,并且“应用程序”根据该elo的获胜率向他们建议一个开场动作集。为此,我使用以下数据集: 其中重要的数据是开题名(我想建议的)、平均评分(用户可以输入的内容)和获胜者(我们需要看看怀特是否获胜) 这是我目前的代码: %matplotlib inline import numpy as np import matplotlib.pyplot as plt import

我只是想寻求一点帮助。我正在努力弄清楚我所做的是正确的还是错误的,即使天真的Bayes是正确的方法

我希望用户能够输入他们的elo,并且“应用程序”根据该elo的获胜率向他们建议一个开场动作集。为此,我使用以下数据集:

其中重要的数据是开题名(我想建议的)、平均评分(用户可以输入的内容)和获胜者(我们需要看看怀特是否获胜)

这是我目前的代码:

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
import pandas as pd
from sklearn.datasets import fetch_20newsgroups
from matplotlib.colors import ListedColormap
from sklearn import preprocessing
#Import Gaussian Naive Bayes model
from sklearn.naive_bayes import GaussianNB


#Read in dataset
data = pd.read_csv(f"games.csv")

# set new column that is true/false depending on if white wins
data['white_wins'] = (data['winner'] == "white")


# Create new columns, average rating (based on white rating and black rating) and category (categorization of rating for Naive Bayes)
data['average_rating'] = data.apply(lambda row: (row['white_rating'] + row['black_rating']) / 2, axis=1)
data['category'] = data['average_rating'] // 100 + 1

# Drop unneccessary columns
data = data.drop(['turns', 'moves', 'victory_status', 'id', 'winner', 'rated', 'created_at', 'last_move_at', 'opening_ply', 'white_id', 'black_id', 'increment_code', 'opening_eco', 'white_rating', 'black_rating'], axis=1)

#Label Encoder Initialisation
le = preprocessing.LabelEncoder()


# Converting string labels into numbers.
opening_name_encoded=le.fit_transform(data.opening_name)
category_encoded=le.fit_transform(data.category)
label=le.fit_transform(data.white_wins)

#Package features together
features=zip(opening_name_encoded, category_encoded)


#Create a Gaussian Classifier
model = GaussianNB()


# Train the model using the training sets
model.fit(features,label)
我目前得到的错误是:

而且,我甚至不相信这是正确的,如果我继续沿着这条流走下去,我只会根据开场动作集和elo预测怀特是否获胜。我真的不确定该把它带到什么地方,才能达到我需要的程度


谢谢你的帮助

zip
在迭代器中返回,因此您的代码没有达到预期的效果。我的猜测是,您打算将
特性
作为一个2元组列表。如果是这种情况,则将代码调整为
features=list(zip(打开\u name\u编码,类别\u编码))

[31]中的
:zip([1,2,3],'a','b','c'])
出[31]:
在[32]中:列表(zip([1,2,3],'a','b','c']))
Out[32]:[(1,'a'),(2,'b'),(3,'c')]
In [31]: zip([1, 2, 3], ['a', 'b', 'c'])
Out[31]: <zip at 0x25d61abfd80>

In [32]: list(zip([1, 2, 3], ['a', 'b', 'c']))
Out[32]: [(1, 'a'), (2, 'b'), (3, 'c')]