{ "cells": [ { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "14.701517343521118\n", "0.8576779026217228\n", "[[42 0 0 0 0 0 0 0 0 0 0 0 0]\n", " [ 0 41 0 0 0 0 0 0 0 0 0 0 0]\n", " [ 0 0 35 1 0 0 0 0 0 0 0 0 0]\n", " [ 0 0 0 44 0 3 0 0 0 0 0 0 0]\n", " [ 0 0 0 0 39 0 0 0 0 0 0 0 0]\n", " [ 0 0 0 0 0 41 0 0 0 2 0 0 0]\n", " [ 0 0 0 0 0 0 27 0 0 14 0 0 0]\n", " [ 0 0 0 0 0 0 0 18 0 2 0 0 1]\n", " [ 0 0 0 0 0 5 0 0 35 2 0 0 0]\n", " [ 0 0 0 0 0 0 2 0 0 49 0 0 2]\n", " [ 0 0 0 0 0 1 0 1 0 26 12 3 2]\n", " [ 0 0 0 0 0 0 0 0 1 4 0 38 0]\n", " [ 0 0 0 0 0 0 0 0 0 4 0 0 37]]\n", " precision recall f1-score support\n", "\n", " 0 1.00 1.00 1.00 42\n", " 1 1.00 1.00 1.00 41\n", " 2 1.00 0.97 0.99 36\n", " 3 0.98 0.94 0.96 47\n", " 4 1.00 1.00 1.00 39\n", " 5 0.82 0.95 0.88 43\n", " 6 0.93 0.66 0.77 41\n", " 7 0.95 0.86 0.90 21\n", " 8 0.97 0.83 0.90 42\n", " 9 0.48 0.92 0.63 53\n", " 10 1.00 0.27 0.42 45\n", " 11 0.93 0.88 0.90 43\n", " 12 0.88 0.90 0.89 41\n", "\n", " accuracy 0.86 534\n", " macro avg 0.92 0.86 0.86 534\n", "weighted avg 0.91 0.86 0.85 534\n", "\n" ] } ], "source": [ "import sklearn\n", "import time\n", "from sklearn import metrics\n", "from sklearn.neural_network import MLPClassifier\n", "from sklearn.utils import shuffle\n", "from sklearn.neighbors import KNeighborsClassifier\n", "from sklearn.externals import joblib\n", "from sklearn.model_selection import train_test_split\n", "import pandas as pd\n", "import sys, os\n", "import numpy as np \n", "from sklearn.metrics import classification_report, confusion_matrix \n", "#df = pd.read_excel (r'C:\\Users\\pc\\Documents\\DF features\\features\\full\\df13.xlsx')\n", "#dfn=shuffle(df)#shuffle\n", "#dfn.to_excel(r'C:\\Users\\pc\\Documents\\DF features\\features\\full\\shuffle13.xlsx')\n", "sdf=pd.read_excel(r'C:\\Users\\pc\\Documents\\DF features\\features\\full\\shuffle13.xlsx')\n", "X=sdf.iloc[:,:-1]\n", "Y=sdf.iloc[:,-1]\n", "X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, shuffle=False)\n", "mlp = MLPClassifier(hidden_layer_sizes=(271), max_iter=1000) \n", "#mlp=KNeighborsClassifier(n_neighbors=10)\n", "start=time.time()\n", "mlp.fit(X_train,Y_train) \n", "stop=time.time()\n", "print(stop-start)\n", "#file3='df13.sav'\n", "#joblib.dump(mlp,file3)\n", "#load=joblib.load(file3)\n", "result=mlp.score(X_test,Y_test)\n", "print(result)\n", "predictions = mlp.predict(X_test) \n", "print(confusion_matrix(Y_test,predictions)) \n", "print(classification_report(Y_test,predictions)) " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 2 }