Python TensorFlow维度是不兼容的错误
最近,我决定使用TF模块将我在Excel中完成的一个ML项目翻译成Python。整个主题是相当基本的线性回归的东西,但尽管在TF网站上有一个教程,我还是无法让它工作。我认为原因可能是在教程中只有2种可能的结果0和1,但在我的数据中,包含了一些关于天气如何影响净能源发电厂输出的信息,有更多的可能性。我得到的错误是:尺寸1569和7999不兼容。7999数字的来源很简单,这是我传递给火车数据集的记录数,但1569是我无法真正理解它从何而来的。 你能帮我修一下密码吗Python TensorFlow维度是不兼容的错误,python,tensorflow,linear-regression,Python,Tensorflow,Linear Regression,最近,我决定使用TF模块将我在Excel中完成的一个ML项目翻译成Python。整个主题是相当基本的线性回归的东西,但尽管在TF网站上有一个教程,我还是无法让它工作。我认为原因可能是在教程中只有2种可能的结果0和1,但在我的数据中,包含了一些关于天气如何影响净能源发电厂输出的信息,有更多的可能性。我得到的错误是:尺寸1569和7999不兼容。7999数字的来源很简单,这是我传递给火车数据集的记录数,但1569是我无法真正理解它从何而来的。 你能帮我修一下密码吗 import numpy
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from IPython.display import clear_output
from six.moves import urllib
import tensorflow as tf
import tensorflow .compat.v2.feature_column as fc
df_train = pd.read_csv(r'C:\Users\lukas\Desktop\Elektrownia_train.csv')
df_test = pd.read_csv(r'C:\Users\lukas\Desktop\Elektrownia_test.csv')
df_train = df_train.apply(lambda x: x.str.replace(',','.'))
df_test = df_test.apply(lambda x: x.str.replace(',','.'))
df_train = df_train.astype(str).astype(float)
df_test = df_test.astype(str).astype(float)
wynik_train = df_train.pop('Net hourly energy output [MW]')
wynik_test = df_test.pop('Net hourly energy output [MW]')
wynik_train = wynik_train.astype(int)
wynik_test = wynik_train.astype(int)
NUMERIC_COLUMNS = ['Temperature [C]','Exhaust Vacuume [mm Hg]','Ambient Preassure [milibar]','Relative Humidity [%]']
feature_columns = []
for feature_name in NUMERIC_COLUMNS:
feature_columns.append(tf.feature_column.numeric_column(feature_name,dtype=tf.float64))
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
ds = make_input_fn(df_train, wynik_train, batch_size = 10000)()
train_input_fn = make_input_fn(df_train, wynik_train)
test_input_fn = make_input_fn(df_test, wynik_test, num_epochs = 1, shuffle = False)
linear_est = tf.estimator.LinearClassifier(feature_columns = feature_columns, n_classes = 7999)
linear_est.train(train_input_fn)
result = linear_est.evaluate(test_input_fn)
clear_output() # czyszczę konsole
print(result['accuracy'])
如果你需要进一步的帮助,我很乐意提供
另外,我知道我的阅读csv可以写得更好,我会在下一个项目中提高