【发布时间】:2022-01-09 14:35:35
【问题描述】:
我正在尝试使用 tensorflow 和 keras 训练 NLTK 分类器模型,有人知道这是否可以使用 sklearn 神经工作 MLP 分类器重新创建吗?对于我使用 ML 的目的,我认为我不需要 tensorflow,而是需要更简单、更易于安装/部署的东西。
这里没有太多关于机器学习的智慧,任何技巧都非常感谢,即使描述了这个深度学习 tensorflow keras 模型也非常感谢。
所以我的 tf keras 模型架构如下所示:
training = []
random.shuffle(training)
training = np.array(training)
# create train and test lists. X - patterns, Y - intents
train_x = list(training[:,0])
train_y = list(training[:,1])
# Create model - 3 layers. First layer 128 neurons, second layer 64 neurons and 3rd output layer contains number of neurons
# equal to number of intents to predict output intent with softmax
model = Sequential()
model.add(Dense(128, input_shape=(len(train_x[0]),), activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(len(train_y[0]), activation='softmax'))
# Compile model. Stochastic gradient descent with Nesterov accelerated gradient gives good results for this model
sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
# Fit the model
model.fit(np.array(train_x), np.array(train_y), epochs=200, batch_size=5, verbose=1)
那么sklearn neural network,我在下面这个问题上完全正确吗?有人可以帮我理解什么是 tensorflow 模型架构,什么是 sklearn 无法复制的。我有点理解 tensorflow 可能比更简单的 sklearn 更强大。
#Importing MLPClassifier
from sklearn.neural_network import MLPClassifier
model = MLPClassifier(hidden_layer_sizes=(128,64),activation ='relu',solver='sgd',random_state=1)
【问题讨论】:
标签: python tensorflow machine-learning keras scikit-learn