-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbd9419
commit 414fe96
Showing
1 changed file
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
{ | ||
"nbformat": 4, | ||
"nbformat_minor": 0, | ||
"metadata": { | ||
"colab": { | ||
"provenance": [] | ||
}, | ||
"kernelspec": { | ||
"name": "python3", | ||
"display_name": "Python 3" | ||
}, | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"id": "zTKyKPBvAGXt" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from keras.models import Sequential\n", | ||
"from keras.layers import Dense\n", | ||
"import keras\n", | ||
"import pandas as pd\n", | ||
"import numpy as np\n", | ||
"from keras.models import load_model\n", | ||
"from keras.layers import Dropout\n", | ||
"from sklearn.model_selection import train_test_split\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import tensorflow as tf" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"path = \"/content/wd.csv\"\n", | ||
"df = pd.read_csv(path,sep=\",\")" | ||
], | ||
"metadata": { | ||
"id": "GgwnEH8cAZ-X" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"df.drop(labels=[\"Unnamed: 0\"],axis=1,inplace=True)" | ||
], | ||
"metadata": { | ||
"id": "7o5tKojYq-8i" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"data = df.iloc[:-1,1:].values\n", | ||
"data = np.transpose(data)\n", | ||
"total = df.iloc[-1][1:].values\n", | ||
"X = np.asarray(data).astype(np.float32)\n", | ||
"Y = np.asarray(total).astype(np.float32)" | ||
], | ||
"metadata": { | ||
"id": "B2V80bNlAhCO" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"X_train, X_test, y_train, y_test = train_test_split(data, total, test_size = 1/5, random_state = 123, shuffle=1)\n", | ||
"X = np.asarray(X_train).astype(np.float32)\n", | ||
"Y = np.asarray(y_train).astype(np.float32)\n", | ||
"X_test = np.asarray(X_test).astype(np.float32)\n", | ||
"Y_test = np.asarray(y_test).astype(np.float32)" | ||
], | ||
"metadata": { | ||
"id": "lplZPLbdAsKP" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"model = Sequential()\n", | ||
"model.add(Dense(512, activation='relu'))\n", | ||
"model.add(Dropout(0.5))\n", | ||
"model.add(Dense(256, activation='relu'))\n", | ||
"model.add(Dropout(0.25))\n", | ||
"model.add(Dense(1))\n", | ||
"model.compile(optimizer='Adam',\n", | ||
" loss='mean_absolute_error',\n", | ||
" metrics=['RootMeanSquaredError'])\n", | ||
"history = model.fit(X,Y,\n", | ||
" batch_size=16,\n", | ||
" epochs=5000,\n", | ||
" verbose=1)\n", | ||
"model.summary()" | ||
], | ||
"metadata": { | ||
"id": "SVa_xfZeEJk-" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"predict = model.predict(X)\n", | ||
"for i in range(len(X)):\n", | ||
" print(int(abs(predict[i]-Y[i])))" | ||
], | ||
"metadata": { | ||
"id": "cjiiE0kS6aob" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"plt.plot(history.history['loss'])\n", | ||
"#plt.plot(history.history['val_loss'])\n", | ||
"plt.title('Mean Absolute Error')\n", | ||
"plt.ylabel('loss')\n", | ||
"plt.xlabel('epoch')\n", | ||
"plt.legend(['train', 'test'], loc='upper left')\n", | ||
"plt.show()" | ||
], | ||
"metadata": { | ||
"id": "WisGZSpFJyHr" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"#model = keras.models.load_model('path/to/location.keras')" | ||
], | ||
"metadata": { | ||
"id": "WLCiSMyIH5xG" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"model.save('model.keras')\n", | ||
"def convert(model):\n", | ||
" converter = tf.lite.TFLiteConverter.from_keras_model(model)\n", | ||
" tflite_model = converter.convert()\n", | ||
"\n", | ||
" with open('app_model.tflite', 'wb') as f:\n", | ||
" f.write(tflite_model)\n", | ||
"convert(model)" | ||
], | ||
"metadata": { | ||
"id": "Yp-jEIQ-PeeG" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
} | ||
] | ||
} |