In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
SVC(kernel='linear')
"
]
},
"metadata": {},
"execution_count": 14
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "UV4-CAfquiyP"
},
"source": [
"Model Evaluation"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "yhAjGPJWunXa"
},
"source": [
"Accuracy Score"
]
},
{
"cell_type": "code",
"metadata": {
"id": "fJLEPQK7ueXp"
},
"source": [
"# accuracy score on the training data\n",
"X_train_prediction = classifier.predict(X_train)\n",
"training_data_accuracy = accuracy_score(X_train_prediction, Y_train)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "mmJ22qhVvNwj",
"outputId": "7540f8ca-5527-4612-d5cd-8746d711220e"
},
"source": [
"print('Accuracy score of the training data : ', training_data_accuracy)"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Accuracy score of the training data : 0.7833876221498371\n"
]
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "G2CICFMEvcCl"
},
"source": [
"# accuracy score on the test data\n",
"X_test_prediction = classifier.predict(X_test)\n",
"test_data_accuracy = accuracy_score(X_test_prediction, Y_test)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "i2GcW_t_vz7C",
"outputId": "e2b18fd9-f005-42fa-9444-81e8eb57d947"
},
"source": [
"print('Accuracy score of the test data : ', test_data_accuracy)"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Accuracy score of the test data : 0.7727272727272727\n"
]
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "gq8ZX1xpwPF5"
},
"source": [
"Making a Predictive System"
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "U-ULRe4yv5tH",
"outputId": "c218e6cf-ac30-4246-9bc6-cc09ac9d81ae"
},
"source": [
"input_data = (5,166,72,19,175,25.8,0.587,51)\n",
"\n",
"# changing the input_data to numpy array\n",
"input_data_as_numpy_array = np.asarray(input_data)\n",
"\n",
"# reshape the array as we are predicting for one instance\n",
"input_data_reshaped = input_data_as_numpy_array.reshape(1,-1)\n",
"\n",
"prediction = classifier.predict(input_data_reshaped)\n",
"print(prediction)\n",
"\n",
"if (prediction[0] == 0):\n",
" print('The person is not diabetic')\n",
"else:\n",
" print('The person is diabetic')"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"[1]\n",
"The person is diabetic\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"/usr/local/lib/python3.10/dist-packages/sklearn/base.py:439: UserWarning: X does not have valid feature names, but SVC was fitted with feature names\n",
" warnings.warn(\n"
]
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "vgL6wblpQUtX"
},
"source": [
"Saving the trained model"
]
},
{
"cell_type": "code",
"metadata": {
"id": "Nn60MdxByjgz"
},
"source": [
"import pickle"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "cWzPQs4mQZN_"
},
"source": [
"filename = 'trained_model.sav'\n",
"pickle.dump(classifier, open(filename, 'wb'))"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "Wk1T2sMcQ6_U"
},
"source": [
"# loading the saved model\n",
"loaded_model = pickle.load(open('trained_model.sav', 'rb'))"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Bd5OpxHnRPyy",
"outputId": "daa664c6-683c-4ac6-986d-46654598fac6"
},
"source": [
"input_data = (5,166,72,19,175,25.8,0.587,51)\n",
"\n",
"# changing the input_data to numpy array\n",
"input_data_as_numpy_array = np.asarray(input_data)\n",
"\n",
"# reshape the array as we are predicting for one instance\n",
"input_data_reshaped = input_data_as_numpy_array.reshape(1,-1)\n",
"\n",
"prediction = loaded_model.predict(input_data_reshaped)\n",
"print(prediction)\n",
"\n",
"if (prediction[0] == 0):\n",
" print('The person is not diabetic')\n",
"else:\n",
" print('The person is diabetic')"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"[1]\n",
"The person is diabetic\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"/usr/local/lib/python3.10/dist-packages/sklearn/base.py:439: UserWarning: X does not have valid feature names, but SVC was fitted with feature names\n",
" warnings.warn(\n"
]
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "iGRhGvgfRkvm"
},
"source": [],
"execution_count": null,
"outputs": []
}
]
}