Я пытаюсь написать код линейной регрессии, но - PullRequest
0 голосов
/ 10 апреля 2020

Я пытался запустить этот код, но каждый раз получаю одну и ту же ошибку. Дело в том, что я получил этот блок кода из оригинального источника тензорного потока. В этом примере он работает нормально, но выдает ошибку в моем наборе данных. Я только что изменил свой набор данных.

Вот код:

dftrain = pd.read_csv('googledata.csv')  # training data
dfeval = pd.read_csv('predictingdata.csv')  # testing data
y_train = dftrain.pop('Close')
y_eval = dfeval.pop('Close')
NUMERIC_COLUMNS = ['Open', 'High', 'Low', 'Volume']
feature_columns = []

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():  # inner function, this will be returned
        # create tf.data.Dataset object with data and its label
        ds = tf.data.Dataset.from_tensor_slices((dict(data_df), label_df))  
        if shuffle:
            ds = ds.shuffle(1000)  # randomize order of data
        # split dataset into batches of 32 and repeat process for number of epochs
        ds = ds.batch(batch_size).repeat(num_epochs)
        return ds  # return a batch of the dataset
    return input_function  # return a function object for use

# here we will call the input_function that was returned to us to get a dataset
# object we can feed to the model
train_input_fn = make_input_fn(dftrain, y_train)  
eval_input_fn = make_input_fn(dfeval, y_eval, num_epochs=1, shuffle=False)

linear_est = tf.estimator.LinearClassifier(feature_columns=feature_columns)
linear_est.train(train_input_fn)  # train

# get model metrics/stats by testing on testing data
result = linear_est.evaluate(eval_input_fn)

clear_output()  # clears console output
# the result variable is simply a dict of stats about our model
print(result['accuracy'])

Это дает следующие ошибки:

I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports
    instructions that this TensorFlow binary was not compiled to use: AVX2

W tensorflow/core/framework/op_kernel.cc:1599] OP_REQUIRES failed at 
    cast_op.cc:123 : Unimplemented: Cast string to float is not supported

E tensorflow/core/common_runtime/executor.cc:642] Executor failed to create kernel.
    Unimplemented: Cast string to float is not supported

tensorflow.python.framework.errors_impl.UnimplementedError: Cast string to float is
    not supported

File "C:/Users/merte/PycharmProjects/stockmarket/stock.py", line 36, in <module>
    linear_est.train(train_input_fn)  # train
tensorflow.python.framework.errors_impl.UnimplementedError: Cast string to float is
    not supported

Как вы думаете, это не все блоки ошибок, но я просто не хотел спамить.

У меня есть профессионалы, которые могут мне помочь? Я благодарен!

...