Home>

I get the following error in machine learning.
/Users/idaryuunosuke/.pyenv/versions/anaconda3-5.3.1/envs/py35/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: compiletime version 3.6 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.5
return f (* args, ** kwds)
WARNING: tensorflow: From /Users/idaryuunosuke/.pyenv/versions/anaconda3-5.3.1/envs/py35/lib/python3.5/site-packages/tensorflow/python/keras/_impl/keras/backend.py:3086 : calling reduce_sum (from tensorflow.python.ops.math_ops) with keep_dims is deprecated and will be removed in a future version.
Instructions for updating:
keep_dims is deprecated, use keepdims instead
WARNING: tensorflow: From /Users/idaryuunosuke/.pyenv/versions/anaconda3-5.3.1/envs/py35/lib/python3.5/site-packages/tensorflow/python/keras/_impl/keras/backend.py:1557 : calling reduce_mean (from tensorflow.python.ops.math_ops) with keep_dims is deprecated and will be removed in a future version.
Instructions for updating:
keep_dims is deprecated, use keepdims instead
Traceback (most recent call last):
File "deep2.py", line 33, in
epochs = 300)
File "/Users/idaryuunosuke/.pyenv/versions/anaconda3-5.3.1/envs/py35/lib/python3.5/site-packages/tensorflow/python/keras/_impl/keras/models.py", line 920, in fit
validation_steps = validation_steps)
File "/Users/idaryuunosuke/.pyenv/versions/anaconda3-5.3.1/envs/py35/lib/python3.5/site-packages/tensorflow/python/keras/_impl/keras/engine/training.py", line 1592, in fit
batch_size = batch_size)
File "/Users/idaryuunosuke/.pyenv/versions/anaconda3-5.3.1/envs/py35/lib/python3.5/site-packages/tensorflow/python/keras/_impl/keras/engine/training.py", line 1431, in _standardize_user_data
exception_prefix = 'input')
File "/Users/idaryuunosuke/.pyenv/versions/anaconda3-5.3.1/envs/py35/lib/python3.5/site-packages/tensorflow/python/keras/_impl/keras/engine/training.py", line 132, in _standardize_input_data
arrays [i] = array
ValueError: could not broadcast input array from shape (2,1) into shape (2)

Here is the code

import tensorflow as tf
import tensorflow.contrib.keras as keras
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
# Load data --- (* 1)
analysisresults_data = pd.read_csv ("analysis_resultstable_BX.csv", encoding = "utf-8")
# Separate data into labels and input data
y = analysisresults_data.loc [:, ["Result"]]
x = analysisresults_data.loc [:, ["Signatures_id", "Hit_count"]]

# Divide for learning and testing --- (* 2)
x_train, x_test, y_train, y_test = train_test_split (x, y, test_size = 0.2, train_size = 0.8, shuffle = True)
# Define model structure --- (* 3)
Dense = keras.layers.Dense
model = keras.models.Sequential ()
model.add (Dense (10, activation = 'relu', input_shape = (1,)))
model.add (Dense (1, activation = 'sigmoid')) # --- (* 3a)
# Build model --- (* 4)
model.compile (
    loss = 'categorical_crossentropy',
    optimizer = 'adam',
    metrics = ['accuracy'])
# Run learning --- (* 5)
model.fit (x_train, y_train,
    batch_size = 20,
    epochs = 300)
# Evaluate the model --- (* 6)
score = model.evaluate (x_test, y_test, verbose = 1)
print ('Accuracy rate =', score [1], 'loss =', score [0])

If i know something, please let me know.

  • Answer # 1

    Tensor dimensions seem to be different.
    Perhaps the label must have one dimension.

    y = analysisresults_data.loc [:, ["Result"]]. flatten ()


    Please try as.

  • Answer # 2

    y = analysisresults_data.loc [:, ["Result"]]. to_numpy ()
    x = analysisresults_data.loc [:, ["Signatures_id", "Hit_count"]]. to_numpy ()
    model.add (Dense (10, activation = 'relu', input_shape = (2,)))
    Is it

    ?