我的第一个深度网络
my first deep network
这是我的第一个深度神经网络,我在这段代码中遇到了问题
在实施的同时。
除了错误之外,代码很慢,这是另一回事。
代码如下:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import SGD, Adam
from sklearn.datasets import make_moons
from sklearn.model_selection import train_test_split
x, y = make_moons(n_samples=1000, noise=0.1, random_state=0)
plt.plot(x[y == 0, 0], x[y == 0, 1], 'ob', alpha=0.5)
plt.plot(x[y == 1, 0], x[y == 1, 1], 'xr', alpha=0.5)
plt.legend(['0', '1'])
plt.show()
print(x.shape)
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=.3, random_state=42)
model = Sequential
model.add(Dense(1, input_shape=(2,), activation='sigmoid'))
model.compile(Adam(lr=0.5), 'binary_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train,epochs=200, verbose=0)
results = model.evaluate(x_test, y_test)
print('The Accuracy score on the Train set is:\t{:0.3f}'.format(results[1]))
这里是错误
> Using TensorFlow backend. 2017-11-24 17:03:32.402292: W
> C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but
> these are available on your machine and could speed up CPU
> computations. 2017-11-24 17:03:32.402768: W
> C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but
> these are available on your machine and could speed up CPU
> computations. (1000, 2) Traceback (most recent call last): File
> "E:/Tutorial/Deep Learning.py", line 18, in <module>
> model.add(Dense(1, input_shape=(2,), activation='sigmoid')) TypeError: add() missing 1 required positional argument: 'layer'
您在 Sequential
:
后缺少括号
model = Sequential()
如果您想编译 tensorflow 以使用特殊的 x86 指令(例如 AVX),请参阅 How to compile Tensorflow with SSE4.2 and AVX instructions? 但这可能比它值得的更多努力。
这是我的第一个深度神经网络,我在这段代码中遇到了问题 在实施的同时。 除了错误之外,代码很慢,这是另一回事。
代码如下:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import SGD, Adam
from sklearn.datasets import make_moons
from sklearn.model_selection import train_test_split
x, y = make_moons(n_samples=1000, noise=0.1, random_state=0)
plt.plot(x[y == 0, 0], x[y == 0, 1], 'ob', alpha=0.5)
plt.plot(x[y == 1, 0], x[y == 1, 1], 'xr', alpha=0.5)
plt.legend(['0', '1'])
plt.show()
print(x.shape)
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=.3, random_state=42)
model = Sequential
model.add(Dense(1, input_shape=(2,), activation='sigmoid'))
model.compile(Adam(lr=0.5), 'binary_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train,epochs=200, verbose=0)
results = model.evaluate(x_test, y_test)
print('The Accuracy score on the Train set is:\t{:0.3f}'.format(results[1]))
这里是错误
> Using TensorFlow backend. 2017-11-24 17:03:32.402292: W
> C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but
> these are available on your machine and could speed up CPU
> computations. 2017-11-24 17:03:32.402768: W
> C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but
> these are available on your machine and could speed up CPU
> computations. (1000, 2) Traceback (most recent call last): File
> "E:/Tutorial/Deep Learning.py", line 18, in <module>
> model.add(Dense(1, input_shape=(2,), activation='sigmoid')) TypeError: add() missing 1 required positional argument: 'layer'
您在 Sequential
:
model = Sequential()
如果您想编译 tensorflow 以使用特殊的 x86 指令(例如 AVX),请参阅 How to compile Tensorflow with SSE4.2 and AVX instructions? 但这可能比它值得的更多努力。