{ "cells": [ { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.31647940074906367\n", "[[42 0 0 0 0 0 0 0 0 0 0 0 0]\n", " [ 0 33 0 0 0 0 0 0 0 0 0 0 0]\n", " [ 0 8 25 0 0 0 0 0 0 20 0 0 0]\n", " [ 0 0 0 1 0 0 0 0 0 36 0 0 0]\n", " [ 0 0 0 0 5 0 0 0 0 31 0 0 0]\n", " [ 0 0 0 0 0 0 0 0 1 37 0 0 0]\n", " [ 0 0 0 0 0 0 0 0 0 51 0 0 0]\n", " [ 0 0 0 0 0 0 0 0 0 28 0 0 0]\n", " [ 0 0 0 0 0 0 0 0 11 27 0 0 0]\n", " [ 0 0 0 0 0 0 0 0 0 52 0 0 0]\n", " [ 0 0 0 0 0 0 0 0 0 46 0 0 0]\n", " [ 0 0 0 0 0 0 0 0 0 38 0 0 0]\n", " [ 0 0 0 0 0 0 0 0 0 42 0 0 0]]\n", " precision recall f1-score support\n", "\n", " 0 1.00 1.00 1.00 42\n", " 1 0.80 1.00 0.89 33\n", " 2 1.00 0.47 0.64 53\n", " 3 1.00 0.03 0.05 37\n", " 4 1.00 0.14 0.24 36\n", " 5 0.00 0.00 0.00 38\n", " 6 0.00 0.00 0.00 51\n", " 7 0.00 0.00 0.00 28\n", " 8 0.92 0.29 0.44 38\n", " 9 0.13 1.00 0.23 52\n", " 10 0.00 0.00 0.00 46\n", " 11 0.00 0.00 0.00 38\n", " 12 0.00 0.00 0.00 42\n", "\n", " accuracy 0.32 534\n", " macro avg 0.45 0.30 0.27 534\n", "weighted avg 0.44 0.32 0.27 534\n", "\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\pc\\anaconda3\\lib\\site-packages\\sklearn\\metrics\\_classification.py:1272: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n", " _warn_prf(average, modifier, msg_start, len(result))\n" ] } ], "source": [ "import sklearn\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\\chisquare\\feature\\full\\chi13.xlsx')\n", "#dfn=shuffle(df)#shuffle\n", "#dfn.to_excel(r'C:\\Users\\pc\\Documents\\chisquare\\feature\\full\\shuffle13.xlsx')\n", "sdf=pd.read_excel(r'C:\\Users\\pc\\Documents\\chisquare\\feature\\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=(503), max_iter=1000) \n", "#mlp=KNeighborsClassifier(n_neighbors=1)\n", "mlp.fit(X_train,Y_train)\n", "#filename1='chi92.sav'\n", "#filename2='chi3.sav'\n", "#filename3='chi61.sav'\n", "filename4='ch13.sav'\n", "joblib.dump(mlp,filename4)\n", "load=joblib.load(filename4)\n", "result=load.score(X_test,Y_test)\n", "print(result)\n", "predictions = load.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": [] } ], "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 }