Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tensorflow InvalidArgumentError:断言失败:[标签必须是<;=n_类-1] 将熊猫作为pd导入 将matplotlib.pyplot作为plt导入 导入tensorflow作为tf df=pd.read\u csv('pokemon\u data.csv') df['Total']=df['HP']+df['Attack']+df['Defense']+df['Sp.Atk']+df['Sp.Def']+df['Speed'] df=df.loc[df['Total']>450] df=df.loc[~df['Name'].str.contains('Mega')] df=df.loc[~df['Name'].str.contains('Primal')] df=df.drop(列=['Name']) df=df.drop(列=['Generation']) df=df.drop(列=['Legendary']) df=df.drop(列=['type2']) df=df.drop(列=['#'])) df.loc[df['Type 1']='Fire','Type 1']=0 df.loc[df['Type 1']=='Normal','Type 1']=1 df.loc[df['Type 1']=='Water','Type 1']=2 df.loc[df['Type 1']='Grass','Type 1']=3 df.loc[df['Type 1']='Electric','Type 1']=4 df.loc[df['Type 1']='Ice','Type 1']=5 df.loc[df['Type 1']='Fighting','Type 1']=6 df.loc[df['Type 1']='Poison','Type 1']=7 df.loc[df['Type 1']='Ground','Type 1']=8 df.loc[df['Type 1']='Flying','Type 1']=9 df.loc[df['type1']='psycholic','type1']=10 df.loc[df['Type 1']='Rock','Type 1']=11 df.loc[df['type1']='Bug','type1']=12 df.loc[df['Type 1']='Ghost','Type 1']=13 df.loc[df['Type 1']='Dark','Type 1']=14 df.loc[df['Type 1']='Dragon','Type 1']=15 df.loc[df['Type 1']='Steel','Type 1']=16 df.loc[df['type1']='Fairy','type1']=17 温度=['Type 1'] 对于col in TEMP: df[col]=pd.to_numeric(df[col]) df_eval_sub=df.loc[df['Total']500] y_列=df.pop('1类') y_eval_sub=df_eval_sub.pop('Type 1')) y_eval_over=df_eval_over.pop('Type 1')) 功能_列=[] TO_INT=['HP'、'Attack'、'defence'、'Sp.Atk'、'Sp.Def'、'Speed'、'Total'] 对于col in TO_INT: df[col]=pd.to_numeric(df[col]) 数值_列=[“HP”、“攻击”、“防御”、“Sp.Atk”、“Sp.Def”、“速度”、“总数”] 对于数字列中的要素名称: feature\u columns.append(tf.feature\u column.numeric\u column(feature\u name,dtype=tf.float32)) def make_input_fn(数据_df、标签_df、数字时代=10、随机播放=True、批次大小=32): def input_函数(): ds=tf.data.Dataset.from_tensor_切片((dict(data_df),label_df)) 如果随机播放: ds=ds.shuffle(1000) ds=ds.batch(批大小)。重复(num\u历元) 返回ds 返回输入函数 列车输入\u fn=接通输入\u fn(df,y\u列车) eval_input_fn=make_input_fn(df_eval_sub,y_eval_sub,num_epochs=1,shuffle=False) 线性估计=tf.estimator.LinearClassifier(特征列=特征列) 线性测试序列(序列输入) 结果=线性测试评估(评估输入)_Python_Pandas_Tensorflow - Fatal编程技术网

Python Tensorflow InvalidArgumentError:断言失败:[标签必须是<;=n_类-1] 将熊猫作为pd导入 将matplotlib.pyplot作为plt导入 导入tensorflow作为tf df=pd.read\u csv('pokemon\u data.csv') df['Total']=df['HP']+df['Attack']+df['Defense']+df['Sp.Atk']+df['Sp.Def']+df['Speed'] df=df.loc[df['Total']>450] df=df.loc[~df['Name'].str.contains('Mega')] df=df.loc[~df['Name'].str.contains('Primal')] df=df.drop(列=['Name']) df=df.drop(列=['Generation']) df=df.drop(列=['Legendary']) df=df.drop(列=['type2']) df=df.drop(列=['#'])) df.loc[df['Type 1']='Fire','Type 1']=0 df.loc[df['Type 1']=='Normal','Type 1']=1 df.loc[df['Type 1']=='Water','Type 1']=2 df.loc[df['Type 1']='Grass','Type 1']=3 df.loc[df['Type 1']='Electric','Type 1']=4 df.loc[df['Type 1']='Ice','Type 1']=5 df.loc[df['Type 1']='Fighting','Type 1']=6 df.loc[df['Type 1']='Poison','Type 1']=7 df.loc[df['Type 1']='Ground','Type 1']=8 df.loc[df['Type 1']='Flying','Type 1']=9 df.loc[df['type1']='psycholic','type1']=10 df.loc[df['Type 1']='Rock','Type 1']=11 df.loc[df['type1']='Bug','type1']=12 df.loc[df['Type 1']='Ghost','Type 1']=13 df.loc[df['Type 1']='Dark','Type 1']=14 df.loc[df['Type 1']='Dragon','Type 1']=15 df.loc[df['Type 1']='Steel','Type 1']=16 df.loc[df['type1']='Fairy','type1']=17 温度=['Type 1'] 对于col in TEMP: df[col]=pd.to_numeric(df[col]) df_eval_sub=df.loc[df['Total']500] y_列=df.pop('1类') y_eval_sub=df_eval_sub.pop('Type 1')) y_eval_over=df_eval_over.pop('Type 1')) 功能_列=[] TO_INT=['HP'、'Attack'、'defence'、'Sp.Atk'、'Sp.Def'、'Speed'、'Total'] 对于col in TO_INT: df[col]=pd.to_numeric(df[col]) 数值_列=[“HP”、“攻击”、“防御”、“Sp.Atk”、“Sp.Def”、“速度”、“总数”] 对于数字列中的要素名称: feature\u columns.append(tf.feature\u column.numeric\u column(feature\u name,dtype=tf.float32)) def make_input_fn(数据_df、标签_df、数字时代=10、随机播放=True、批次大小=32): def input_函数(): ds=tf.data.Dataset.from_tensor_切片((dict(data_df),label_df)) 如果随机播放: ds=ds.shuffle(1000) ds=ds.batch(批大小)。重复(num\u历元) 返回ds 返回输入函数 列车输入\u fn=接通输入\u fn(df,y\u列车) eval_input_fn=make_input_fn(df_eval_sub,y_eval_sub,num_epochs=1,shuffle=False) 线性估计=tf.estimator.LinearClassifier(特征列=特征列) 线性测试序列(序列输入) 结果=线性测试评估(评估输入)

Python Tensorflow InvalidArgumentError:断言失败:[标签必须是<;=n_类-1] 将熊猫作为pd导入 将matplotlib.pyplot作为plt导入 导入tensorflow作为tf df=pd.read\u csv('pokemon\u data.csv') df['Total']=df['HP']+df['Attack']+df['Defense']+df['Sp.Atk']+df['Sp.Def']+df['Speed'] df=df.loc[df['Total']>450] df=df.loc[~df['Name'].str.contains('Mega')] df=df.loc[~df['Name'].str.contains('Primal')] df=df.drop(列=['Name']) df=df.drop(列=['Generation']) df=df.drop(列=['Legendary']) df=df.drop(列=['type2']) df=df.drop(列=['#'])) df.loc[df['Type 1']='Fire','Type 1']=0 df.loc[df['Type 1']=='Normal','Type 1']=1 df.loc[df['Type 1']=='Water','Type 1']=2 df.loc[df['Type 1']='Grass','Type 1']=3 df.loc[df['Type 1']='Electric','Type 1']=4 df.loc[df['Type 1']='Ice','Type 1']=5 df.loc[df['Type 1']='Fighting','Type 1']=6 df.loc[df['Type 1']='Poison','Type 1']=7 df.loc[df['Type 1']='Ground','Type 1']=8 df.loc[df['Type 1']='Flying','Type 1']=9 df.loc[df['type1']='psycholic','type1']=10 df.loc[df['Type 1']='Rock','Type 1']=11 df.loc[df['type1']='Bug','type1']=12 df.loc[df['Type 1']='Ghost','Type 1']=13 df.loc[df['Type 1']='Dark','Type 1']=14 df.loc[df['Type 1']='Dragon','Type 1']=15 df.loc[df['Type 1']='Steel','Type 1']=16 df.loc[df['type1']='Fairy','type1']=17 温度=['Type 1'] 对于col in TEMP: df[col]=pd.to_numeric(df[col]) df_eval_sub=df.loc[df['Total']500] y_列=df.pop('1类') y_eval_sub=df_eval_sub.pop('Type 1')) y_eval_over=df_eval_over.pop('Type 1')) 功能_列=[] TO_INT=['HP'、'Attack'、'defence'、'Sp.Atk'、'Sp.Def'、'Speed'、'Total'] 对于col in TO_INT: df[col]=pd.to_numeric(df[col]) 数值_列=[“HP”、“攻击”、“防御”、“Sp.Atk”、“Sp.Def”、“速度”、“总数”] 对于数字列中的要素名称: feature\u columns.append(tf.feature\u column.numeric\u column(feature\u name,dtype=tf.float32)) def make_input_fn(数据_df、标签_df、数字时代=10、随机播放=True、批次大小=32): def input_函数(): ds=tf.data.Dataset.from_tensor_切片((dict(data_df),label_df)) 如果随机播放: ds=ds.shuffle(1000) ds=ds.batch(批大小)。重复(num\u历元) 返回ds 返回输入函数 列车输入\u fn=接通输入\u fn(df,y\u列车) eval_input_fn=make_input_fn(df_eval_sub,y_eval_sub,num_epochs=1,shuffle=False) 线性估计=tf.estimator.LinearClassifier(特征列=特征列) 线性测试序列(序列输入) 结果=线性测试评估(评估输入),python,pandas,tensorflow,Python,Pandas,Tensorflow,错误: import pandas as pd import matplotlib.pyplot as plt import tensorflow as tf df = pd.read_csv('pokemon_data.csv') df['Total'] = df['HP'] + df['Attack'] + df['Defense'] + df['Sp. Atk'] + df['Sp. Def'] + df['Speed'] df = df.loc[df['Total'] > 45

错误:

import pandas as pd
import matplotlib.pyplot as plt
import tensorflow as tf
df = pd.read_csv('pokemon_data.csv')

df['Total'] = df['HP'] + df['Attack'] + df['Defense'] + df['Sp. Atk'] + df['Sp. Def'] + df['Speed']

df = df.loc[df['Total'] > 450]
df = df.loc[~df['Name'].str.contains('Mega')]
df = df.loc[~df['Name'].str.contains('Primal')]

df = df.drop(columns = ['Name'])
df = df.drop(columns = ['Generation'])
df = df.drop(columns = ['Legendary'])
df = df.drop(columns = ['Type 2'])
df = df.drop(columns = ['#'])

df.loc[df['Type 1'] == 'Fire', 'Type 1'] = 0
df.loc[df['Type 1'] == 'Normal', 'Type 1'] = 1
df.loc[df['Type 1'] == 'Water', 'Type 1'] = 2
df.loc[df['Type 1'] == 'Grass', 'Type 1'] = 3
df.loc[df['Type 1'] == 'Electric', 'Type 1'] = 4
df.loc[df['Type 1'] == 'Ice', 'Type 1'] = 5
df.loc[df['Type 1'] == 'Fighting', 'Type 1'] = 6
df.loc[df['Type 1'] == 'Poison', 'Type 1'] = 7
df.loc[df['Type 1'] == 'Ground', 'Type 1'] = 8
df.loc[df['Type 1'] == 'Flying', 'Type 1'] = 9
df.loc[df['Type 1'] == 'Psychic', 'Type 1'] = 10
df.loc[df['Type 1'] == 'Rock', 'Type 1'] = 11
df.loc[df['Type 1'] == 'Bug', 'Type 1'] = 12
df.loc[df['Type 1'] == 'Ghost', 'Type 1'] = 13
df.loc[df['Type 1'] == 'Dark', 'Type 1'] = 14
df.loc[df['Type 1'] == 'Dragon', 'Type 1'] = 15
df.loc[df['Type 1'] == 'Steel', 'Type 1'] = 16
df.loc[df['Type 1'] == 'Fairy', 'Type 1'] = 17

TEMP = ['Type 1']
for col in TEMP:
    df[col] = pd.to_numeric(df[col])

df_eval_sub = df.loc[df['Total'] < 500]
df_eval_over = df.loc[df['Total'] > 500]                      
y_train = df.pop('Type 1')
y_eval_sub = df_eval_sub.pop('Type 1')
y_eval_over = df_eval_over.pop('Type 1')                     
                      
feature_columns = []

TO_INT = ['HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def', 'Speed', 'Total']
for col in TO_INT:
    df[col] = pd.to_numeric(df[col])


NUMERIC_COLUMNS = ['HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def', 'Speed', 'Total']
for feature_name in NUMERIC_COLUMNS:
    feature_columns.append(tf.feature_column.numeric_column(feature_name, dtype=tf.float32))

def make_input_fn(data_df, label_df, num_epochs = 10, shuffle = True, batch_size=32):
    def input_function():
        ds = tf.data.Dataset.from_tensor_slices((dict(data_df), label_df))
        if shuffle:
            ds = ds.shuffle(1000)
        ds = ds.batch(batch_size).repeat(num_epochs)
        return ds
    return input_function

train_input_fn = make_input_fn(df, y_train)
eval_input_fn = make_input_fn(df_eval_sub, y_eval_sub, num_epochs = 1, shuffle = False)

linear_est = tf.estimator.LinearClassifier(feature_columns=feature_columns)
linear_est.train(train_input_fn)
result = linear_est.evaluate(eval_input_fn)

InvalidArgumentError:assertion failed:[标签必须是n_类
这不是指列数,而是您必须指定的参数,标签中的类必须是
InvalidArgumentError: assertion failed: [Labels must be <= n_classes - 1] [Condition x <= y did not hold element-wise:] [x (head/losses/Cast:0) = ] [[16][0][11]...] [y (head/losses/check_label_range/Const:0) = ] [1]
     [[{{node Assert}}]]