Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
cclarke411 authored Aug 9, 2019
1 parent 00d8957 commit 98fef9b
Showing 1 changed file with 76 additions and 34 deletions.
110 changes: 76 additions & 34 deletions Data Science Bootcamp/LSTM Test Generator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@
"y = np_utils.to_categorical(dataY)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model = Sequential()\n",
"model.add(LSTM(256, input_shape=(X.shape[1], X.shape[2])))\n",
"model.add(Dropout(0.2))\n",
"model.add(Dense(y.shape[1], activation='relu'))\n",
"model.add(Dropout(0.2))\n",
"model.add(Dense(60,activation='softmax'))\n",
"model.compile(loss='categorical_crossentropy', optimizer='adam',metrics=['accuracy'])\n",
"model.summary"
]
},
{
"cell_type": "code",
"execution_count": 30,
Expand Down Expand Up @@ -131,13 +147,6 @@
}
],
"source": [
"model = Sequential()\n",
"model.add(LSTM(256, input_shape=(X.shape[1], X.shape[2])))\n",
"model.add(Dropout(0.2))\n",
"model.add(Dense(y.shape[1], activation='relu'))\n",
"model.add(Dropout(0.2))\n",
"model.add(Dense(60,activation='softmax'))\n",
"model.compile(loss='categorical_crossentropy', optimizer='adam',metrics=['accuracy'])\n",
"model.fit(X, y, epochs=1, batch_size=128)"
]
},
Expand Down Expand Up @@ -180,6 +189,49 @@
"print(\"\\nDone.\")"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"_________________________________________________________________\n",
"Layer (type) Output Shape Param # \n",
"=================================================================\n",
"lstm_20 (LSTM) (None, 100, 256) 264192 \n",
"_________________________________________________________________\n",
"dropout_18 (Dropout) (None, 100, 256) 0 \n",
"_________________________________________________________________\n",
"lstm_21 (LSTM) (None, 256) 525312 \n",
"_________________________________________________________________\n",
"dense_21 (Dense) (None, 60) 15420 \n",
"_________________________________________________________________\n",
"dropout_19 (Dropout) (None, 60) 0 \n",
"_________________________________________________________________\n",
"dense_22 (Dense) (None, 60) 3660 \n",
"=================================================================\n",
"Total params: 808,584\n",
"Trainable params: 808,584\n",
"Non-trainable params: 0\n",
"_________________________________________________________________\n"
]
}
],
"source": [
"model = Sequential()\n",
"model.add(LSTM(256, input_shape=(X.shape[1], X.shape[2]),return_sequences=True))\n",
"model.add(Dropout(0.2))\n",
"model.add(LSTM(256))\n",
"model.add(Dense(y.shape[1], activation='relu'))\n",
"model.add(Dropout(0.2))\n",
"model.add(Dense(60,activation='softmax'))\n",
"model.compile(loss='categorical_crossentropy', optimizer='adam',metrics=['accuracy'])\n",
"model.summary()"
]
},
{
"cell_type": "code",
"execution_count": 38,
Expand All @@ -205,20 +257,12 @@
}
],
"source": [
"model = Sequential()\n",
"model.add(LSTM(256, input_shape=(X.shape[1], X.shape[2]),return_sequences=True))\n",
"model.add(Dropout(0.2))\n",
"model.add(LSTM(256))\n",
"model.add(Dense(y.shape[1], activation='relu'))\n",
"model.add(Dropout(0.2))\n",
"model.add(Dense(60,activation='softmax'))\n",
"model.compile(loss='categorical_crossentropy', optimizer='adam',metrics=['accuracy'])\n",
"model.fit(X, y, epochs=1, batch_size=128)"
]
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 43,
"metadata": {},
"outputs": [
{
Expand All @@ -228,41 +272,39 @@
"_________________________________________________________________\n",
"Layer (type) Output Shape Param # \n",
"=================================================================\n",
"lstm_15 (LSTM) (None, 100, 128) 66560 \n",
"lstm_19 (LSTM) (None, 128) 66560 \n",
"_________________________________________________________________\n",
"dropout_13 (Dropout) (None, 100, 128) 0 \n",
"dropout_17 (Dropout) (None, 128) 0 \n",
"_________________________________________________________________\n",
"dense_16 (Dense) (None, 100, 60) 7740 \n",
"dense_20 (Dense) (None, 60) 7740 \n",
"=================================================================\n",
"Total params: 74,300\n",
"Trainable params: 74,300\n",
"Non-trainable params: 0\n",
"_________________________________________________________________\n"
"_________________________________________________________________\n",
"Epoch 1/1\n",
"163715/163715 [==============================] - 839s 5ms/step - loss: 3.7603 - acc: 0.1134\n"
]
},
{
"ename": "ValueError",
"evalue": "Error when checking target: expected dense_16 to have 3 dimensions, but got array with shape (163715, 60)",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-39-4b3804cf3b45>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mmodel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcompile\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mloss\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'categorical_crossentropy'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0moptimizer\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'adam'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mmetrics\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'accuracy'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[0mmodel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msummary\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[0mmodel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mX\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mepochs\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbatch_size\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1000\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;32mC:\\Users\\Clyde\\Anaconda3\\lib\\site-packages\\keras\\engine\\training.py\u001b[0m in \u001b[0;36mfit\u001b[1;34m(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)\u001b[0m\n\u001b[0;32m 950\u001b[0m \u001b[0msample_weight\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0msample_weight\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 951\u001b[0m \u001b[0mclass_weight\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mclass_weight\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 952\u001b[1;33m batch_size=batch_size)\n\u001b[0m\u001b[0;32m 953\u001b[0m \u001b[1;31m# Prepare validation data.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 954\u001b[0m \u001b[0mdo_validation\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mC:\\Users\\Clyde\\Anaconda3\\lib\\site-packages\\keras\\engine\\training.py\u001b[0m in \u001b[0;36m_standardize_user_data\u001b[1;34m(self, x, y, sample_weight, class_weight, check_array_lengths, batch_size)\u001b[0m\n\u001b[0;32m 787\u001b[0m \u001b[0mfeed_output_shapes\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 788\u001b[0m \u001b[0mcheck_batch_axis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;31m# Don't enforce the batch size.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 789\u001b[1;33m exception_prefix='target')\n\u001b[0m\u001b[0;32m 790\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 791\u001b[0m \u001b[1;31m# Generate sample-wise weight values given the `sample_weight` and\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mC:\\Users\\Clyde\\Anaconda3\\lib\\site-packages\\keras\\engine\\training_utils.py\u001b[0m in \u001b[0;36mstandardize_input_data\u001b[1;34m(data, names, shapes, check_batch_axis, exception_prefix)\u001b[0m\n\u001b[0;32m 126\u001b[0m \u001b[1;34m': expected '\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mnames\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m' to have '\u001b[0m \u001b[1;33m+\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 127\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mshape\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m' dimensions, but got array '\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 128\u001b[1;33m 'with shape ' + str(data_shape))\n\u001b[0m\u001b[0;32m 129\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mcheck_batch_axis\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 130\u001b[0m \u001b[0mdata_shape\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdata_shape\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mValueError\u001b[0m: Error when checking target: expected dense_16 to have 3 dimensions, but got array with shape (163715, 60)"
]
"data": {
"text/plain": [
"<keras.callbacks.History at 0x1dc45e744a8>"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model = Sequential()\n",
"model.add(LSTM(128, input_shape=(X.shape[1], X.shape[2]),return_sequences=True))\n",
"model.add(LSTM(128, input_shape=(X.shape[1], X.shape[2])))\n",
"model.add(Dropout(0.2))\n",
"model.add(Dense(y.shape[1], activation='relu'))\n",
"model.compile(loss='categorical_crossentropy', optimizer='adam',metrics=['accuracy'])\n",
"model.summary()\n",
"model.fit(X, y, epochs=1, batch_size=100)"
"model.fit(X, y, epochs=1, batch_size=1000)"
]
},
{
Expand Down

0 comments on commit 98fef9b

Please sign in to comment.