{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Autism" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Autism, also known as Autism Spectrum Disorder (ASD), is a neurodevelopmental condition characterized by challenges in social interaction, communication, and repetitive behaviors. Individuals with autism may exhibit a wide range of abilities and symptoms, forming a spectrum. Understanding and accurately classifying autism can be a complex task due to the diversity within the spectrum. Machine Learning (ML) plays a vital role in addressing this challenge by leveraging algorithms to analyze patterns and make predictions based on data." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Data\n", "\n", "ID - ID of the patient\n", "\n", "A1_Score to A10_Score - Score based on Autism Spectrum Quotient (AQ) 10 item screening tool\n", "\n", "age - Age of the patient in years\n", "\n", "gender - Gender of the patient\n", "\n", "ethnicity - Ethnicity of the patient\n", "\n", "jaundice - Whether the patient had jaundice at the time of birth\n", "\n", "autism - Whether an immediate family member has been diagnosed with autism\n", "\n", "contry_of_res - Country of residence of the patient\n", "\n", "used_app_before - Whether the patient has undergone a screening test before\n", "\n", "result - Score for AQ1-10 screening test\n", "\n", "age_desc - Age of the patient\n", "\n", "relation - Relation of patient who completed the test\n", "\n", "Class/ASD - Classified result as 0 or 1. Here 0 represents No and 1 represents Yes. This is the target column, and during submission submit the values as 0 or 1 only." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "from sklearn.model_selection import train_test_split\n", "from sklearn.preprocessing import StandardScaler\n", "from sklearn.metrics import confusion_matrix, accuracy_score, classification_report\n", "from sklearn.linear_model import LogisticRegression \n", "import joblib\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "data=pd.read_csv(\"data.csv\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
IDgenderA1_ScoreA2_ScoreA3_ScoreA4_ScoreA5_ScoreA6_ScoreA7_ScoreA8_Score...jaundiceaustimageethnicitycontry_of_resused_app_beforeresultrelationage_descClass/ASD
01f10111101...nono18.605397White-EuropeanUnited Statesno7.819715Self18 and more0
12f00000000...nono13.829369South AsianAustraliano10.544296?18 and more0
23f11111100...nono14.679893White-EuropeanUnited Kingdomno13.167506Self18 and more1
34f00010000...nono61.035288South AsianNew Zealandno1.530098?18 and more0
45m00001000...noyes14.256686BlackItalyno7.949723Self18 and more0
..................................................................
795796f11111111...noyes42.084907White-EuropeanUnited Statesno13.390868Self18 and more1
796797f11001000...nono17.669291AsianNew Zealandno9.454201Self18 and more0
797798m00000010...yesno18.242557White-EuropeanJordanno6.805509Self18 and more1
798799f11111101...noyes19.241473Middle EasternUnited Statesno3.682732Relative18 and more0
799800f10011001...nono32.170098AsianNew Zealandno12.060168Self18 and more0
\n", "

800 rows × 22 columns

\n", "
" ], "text/plain": [ " ID gender A1_Score A2_Score A3_Score A4_Score A5_Score A6_Score \\\n", "0 1 f 1 0 1 1 1 1 \n", "1 2 f 0 0 0 0 0 0 \n", "2 3 f 1 1 1 1 1 1 \n", "3 4 f 0 0 0 1 0 0 \n", "4 5 m 0 0 0 0 1 0 \n", ".. ... ... ... ... ... ... ... ... \n", "795 796 f 1 1 1 1 1 1 \n", "796 797 f 1 1 0 0 1 0 \n", "797 798 m 0 0 0 0 0 0 \n", "798 799 f 1 1 1 1 1 1 \n", "799 800 f 1 0 0 1 1 0 \n", "\n", " A7_Score A8_Score ... jaundice austim age ethnicity \\\n", "0 0 1 ... no no 18.605397 White-European \n", "1 0 0 ... no no 13.829369 South Asian \n", "2 0 0 ... no no 14.679893 White-European \n", "3 0 0 ... no no 61.035288 South Asian \n", "4 0 0 ... no yes 14.256686 Black \n", ".. ... ... ... ... ... ... ... \n", "795 1 1 ... no yes 42.084907 White-European \n", "796 0 0 ... no no 17.669291 Asian \n", "797 1 0 ... yes no 18.242557 White-European \n", "798 0 1 ... no yes 19.241473 Middle Eastern \n", "799 0 1 ... no no 32.170098 Asian \n", "\n", " contry_of_res used_app_before result relation age_desc \\\n", "0 United States no 7.819715 Self 18 and more \n", "1 Australia no 10.544296 ? 18 and more \n", "2 United Kingdom no 13.167506 Self 18 and more \n", "3 New Zealand no 1.530098 ? 18 and more \n", "4 Italy no 7.949723 Self 18 and more \n", ".. ... ... ... ... ... \n", "795 United States no 13.390868 Self 18 and more \n", "796 New Zealand no 9.454201 Self 18 and more \n", "797 Jordan no 6.805509 Self 18 and more \n", "798 United States no 3.682732 Relative 18 and more \n", "799 New Zealand no 12.060168 Self 18 and more \n", "\n", " Class/ASD \n", "0 0 \n", "1 0 \n", "2 1 \n", "3 0 \n", "4 0 \n", ".. ... \n", "795 1 \n", "796 0 \n", "797 1 \n", "798 0 \n", "799 0 \n", "\n", "[800 rows x 22 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
IDA1_ScoreA2_ScoreA3_ScoreA4_ScoreA5_ScoreA6_ScoreA7_ScoreA8_ScoreA9_ScoreA10_ScoreageresultClass/ASD
count800.0000800.000000800.00000800.000000800.00000800.000000800.00000800.000000800.000000800.000000800.000000800.000000800.000000800.000000
mean400.50000.5825000.286250.3212500.415000.4575000.208750.2737500.7175000.3162500.46000028.6123067.0585300.231250
std231.08440.4934550.452290.4672490.493030.4985020.406670.4461610.4504970.4653030.49870912.8723733.7889690.421896
min1.00000.0000000.000000.0000000.000000.0000000.000000.0000000.0000000.0000000.0000009.560505-2.5946540.000000
25%200.75000.0000000.000000.0000000.000000.0000000.000000.0000000.0000000.0000000.00000019.2820824.5275560.000000
50%400.50001.0000000.000000.0000000.000000.0000000.000000.0000001.0000000.0000000.00000025.4799606.8934720.000000
75%600.25001.0000001.000001.0000001.000001.0000000.000001.0000001.0000001.0000001.00000033.1547559.8929810.000000
max800.00001.0000001.000001.0000001.000001.0000001.000001.0000001.0000001.0000001.00000072.40248813.3908681.000000
\n", "
" ], "text/plain": [ " ID A1_Score A2_Score A3_Score A4_Score A5_Score \\\n", "count 800.0000 800.000000 800.00000 800.000000 800.00000 800.000000 \n", "mean 400.5000 0.582500 0.28625 0.321250 0.41500 0.457500 \n", "std 231.0844 0.493455 0.45229 0.467249 0.49303 0.498502 \n", "min 1.0000 0.000000 0.00000 0.000000 0.00000 0.000000 \n", "25% 200.7500 0.000000 0.00000 0.000000 0.00000 0.000000 \n", "50% 400.5000 1.000000 0.00000 0.000000 0.00000 0.000000 \n", "75% 600.2500 1.000000 1.00000 1.000000 1.00000 1.000000 \n", "max 800.0000 1.000000 1.00000 1.000000 1.00000 1.000000 \n", "\n", " A6_Score A7_Score A8_Score A9_Score A10_Score age \\\n", "count 800.00000 800.000000 800.000000 800.000000 800.000000 800.000000 \n", "mean 0.20875 0.273750 0.717500 0.316250 0.460000 28.612306 \n", "std 0.40667 0.446161 0.450497 0.465303 0.498709 12.872373 \n", "min 0.00000 0.000000 0.000000 0.000000 0.000000 9.560505 \n", "25% 0.00000 0.000000 0.000000 0.000000 0.000000 19.282082 \n", "50% 0.00000 0.000000 1.000000 0.000000 0.000000 25.479960 \n", "75% 0.00000 1.000000 1.000000 1.000000 1.000000 33.154755 \n", "max 1.00000 1.000000 1.000000 1.000000 1.000000 72.402488 \n", "\n", " result Class/ASD \n", "count 800.000000 800.000000 \n", "mean 7.058530 0.231250 \n", "std 3.788969 0.421896 \n", "min -2.594654 0.000000 \n", "25% 4.527556 0.000000 \n", "50% 6.893472 0.000000 \n", "75% 9.892981 0.000000 \n", "max 13.390868 1.000000 " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.describe()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "ID 0\n", "gender 0\n", "A1_Score 0\n", "A2_Score 0\n", "A3_Score 0\n", "A4_Score 0\n", "A5_Score 0\n", "A6_Score 0\n", "A7_Score 0\n", "A8_Score 0\n", "A9_Score 0\n", "A10_Score 0\n", "jaundice 0\n", "austim 0\n", "age 0\n", "ethnicity 0\n", "contry_of_res 0\n", "used_app_before 0\n", "result 0\n", "relation 0\n", "age_desc 0\n", "Class/ASD 0\n", "dtype: int64" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.isna().sum()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Preprocessing" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1.Data dosen't have a null value" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 2.Data Encoding" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
IDgenderA1_ScoreA2_ScoreA3_ScoreA4_ScoreA5_ScoreA6_ScoreA7_ScoreA8_Score...jaundiceaustimageethnicitycontry_of_resused_app_beforeresultrelationage_descClass/ASD
01f10111101...nono18.605397White-EuropeanUnited Statesno7.819715Self18 and more0
12f00000000...nono13.829369South AsianAustraliano10.544296?18 and more0
23f11111100...nono14.679893White-EuropeanUnited Kingdomno13.167506Self18 and more1
34f00010000...nono61.035288South AsianNew Zealandno1.530098?18 and more0
45m00001000...noyes14.256686BlackItalyno7.949723Self18 and more0
\n", "

5 rows × 22 columns

\n", "
" ], "text/plain": [ " ID gender A1_Score A2_Score A3_Score A4_Score A5_Score A6_Score \\\n", "0 1 f 1 0 1 1 1 1 \n", "1 2 f 0 0 0 0 0 0 \n", "2 3 f 1 1 1 1 1 1 \n", "3 4 f 0 0 0 1 0 0 \n", "4 5 m 0 0 0 0 1 0 \n", "\n", " A7_Score A8_Score ... jaundice austim age ethnicity \\\n", "0 0 1 ... no no 18.605397 White-European \n", "1 0 0 ... no no 13.829369 South Asian \n", "2 0 0 ... no no 14.679893 White-European \n", "3 0 0 ... no no 61.035288 South Asian \n", "4 0 0 ... no yes 14.256686 Black \n", "\n", " contry_of_res used_app_before result relation age_desc Class/ASD \n", "0 United States no 7.819715 Self 18 and more 0 \n", "1 Australia no 10.544296 ? 18 and more 0 \n", "2 United Kingdom no 13.167506 Self 18 and more 1 \n", "3 New Zealand no 1.530098 ? 18 and more 0 \n", "4 Italy no 7.949723 Self 18 and more 0 \n", "\n", "[5 rows x 22 columns]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.head()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "cat = {'ethnicity':'category',\n", " 'gender':'category', \n", " 'jaundice':'category',\n", " 'austim':'category',\n", " 'contry_of_res':'category', \n", " 'used_app_before':'category',\n", " 'age_desc':'category',\n", " 'relation':'category'}\n", "data = data.astype(cat)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "cat_columns = ['ethnicity', 'gender', 'jaundice', 'austim', 'contry_of_res', 'used_app_before', 'age_desc', 'relation']\n", "\n", "for col in cat_columns:\n", " data[col] = data[col].cat.codes\n" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
IDgenderA1_ScoreA2_ScoreA3_ScoreA4_ScoreA5_ScoreA6_ScoreA7_ScoreA8_Score...jaundiceaustimageethnicitycontry_of_resused_app_beforeresultrelationage_descClass/ASD
01010111101...0018.605397105807.819715500
12000000000...0013.82936986010.544296000
23011111100...0014.6798931057013.167506501
34000010000...0061.03528883901.530098000
45100001000...0114.25668623207.949723500
\n", "

5 rows × 22 columns

\n", "
" ], "text/plain": [ " ID gender A1_Score A2_Score A3_Score A4_Score A5_Score A6_Score \\\n", "0 1 0 1 0 1 1 1 1 \n", "1 2 0 0 0 0 0 0 0 \n", "2 3 0 1 1 1 1 1 1 \n", "3 4 0 0 0 0 1 0 0 \n", "4 5 1 0 0 0 0 1 0 \n", "\n", " A7_Score A8_Score ... jaundice austim age ethnicity \\\n", "0 0 1 ... 0 0 18.605397 10 \n", "1 0 0 ... 0 0 13.829369 8 \n", "2 0 0 ... 0 0 14.679893 10 \n", "3 0 0 ... 0 0 61.035288 8 \n", "4 0 0 ... 0 1 14.256686 2 \n", "\n", " contry_of_res used_app_before result relation age_desc Class/ASD \n", "0 58 0 7.819715 5 0 0 \n", "1 6 0 10.544296 0 0 0 \n", "2 57 0 13.167506 5 0 1 \n", "3 39 0 1.530098 0 0 0 \n", "4 32 0 7.949723 5 0 0 \n", "\n", "[5 rows x 22 columns]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.head()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ID int64\n", "gender int8\n", "A1_Score int64\n", "A2_Score int64\n", "A3_Score int64\n", "A4_Score int64\n", "A5_Score int64\n", "A6_Score int64\n", "A7_Score int64\n", "A8_Score int64\n", "A9_Score int64\n", "A10_Score int64\n", "jaundice int8\n", "austim int8\n", "age float64\n", "ethnicity int8\n", "contry_of_res int8\n", "used_app_before int8\n", "result float64\n", "relation int8\n", "age_desc int8\n", "Class/ASD int64\n", "dtype: object\n" ] } ], "source": [ "print(data.dtypes)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 3.Drob unusiful data" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "data=data.drop('ID', axis=1)\n", "data=data.drop('used_app_before', axis=1)\n", "data=data.drop('relation', axis=1)\n", "data=data.drop('result', axis=1)\n", "data=data.drop('age_desc', axis=1)\n", "data=data.drop('contry_of_res', axis=1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 4.Split Data" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "X = data.drop('Class/ASD', axis=1)\n", "y = data['Class/ASD']\n", "X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 5.Standard Scaler\n" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "scaler = StandardScaler()\n", "X_train = scaler.fit_transform(X_train)\n", "X_val = scaler.transform(X_val)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Classification" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "model = LogisticRegression()" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
LogisticRegression()
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.
" ], "text/plain": [ "LogisticRegression()" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model.fit(X_train, y_train)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "y_pred = model.predict(X_val)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Accuracy: 0.9\n" ] } ], "source": [ "accuracy = accuracy_score(y_val, y_pred)\n", "print(\"Accuracy:\", accuracy)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
genderA1_ScoreA2_ScoreA3_ScoreA4_ScoreA5_ScoreA6_ScoreA7_ScoreA8_ScoreA9_ScoreA10_ScorejaundiceaustimageethnicityClass/ASD
0010111101110018.605397100
1000000000010013.82936980
2011111100110014.679893101
3000010000000061.03528880
4100001000110114.25668620
...................................................
795011111111110142.084907101
796011001000110017.66929110
797100000010111018.242557101
798011111101110119.24147350
799010011001110032.17009810
\n", "

800 rows × 16 columns

\n", "
" ], "text/plain": [ " gender A1_Score A2_Score A3_Score A4_Score A5_Score A6_Score \\\n", "0 0 1 0 1 1 1 1 \n", "1 0 0 0 0 0 0 0 \n", "2 0 1 1 1 1 1 1 \n", "3 0 0 0 0 1 0 0 \n", "4 1 0 0 0 0 1 0 \n", ".. ... ... ... ... ... ... ... \n", "795 0 1 1 1 1 1 1 \n", "796 0 1 1 0 0 1 0 \n", "797 1 0 0 0 0 0 0 \n", "798 0 1 1 1 1 1 1 \n", "799 0 1 0 0 1 1 0 \n", "\n", " A7_Score A8_Score A9_Score A10_Score jaundice austim age \\\n", "0 0 1 1 1 0 0 18.605397 \n", "1 0 0 0 1 0 0 13.829369 \n", "2 0 0 1 1 0 0 14.679893 \n", "3 0 0 0 0 0 0 61.035288 \n", "4 0 0 1 1 0 1 14.256686 \n", ".. ... ... ... ... ... ... ... \n", "795 1 1 1 1 0 1 42.084907 \n", "796 0 0 1 1 0 0 17.669291 \n", "797 1 0 1 1 1 0 18.242557 \n", "798 0 1 1 1 0 1 19.241473 \n", "799 0 1 1 1 0 0 32.170098 \n", "\n", " ethnicity Class/ASD \n", "0 10 0 \n", "1 8 0 \n", "2 10 1 \n", "3 8 0 \n", "4 2 0 \n", ".. ... ... \n", "795 10 1 \n", "796 1 0 \n", "797 10 1 \n", "798 5 0 \n", "799 1 0 \n", "\n", "[800 rows x 16 columns]" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Test the model" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[0]\n" ] } ], "source": [ "input_data = np.array([1\t,0\t,0\t,0\t,0\t,0\t,0\t,1\t,0\t,1\t,1\t,1\t,0\t,18.242557\t,10])\n", "input_data_reshaped = input_data.reshape(1, -1)\n", "predication = model.predict(input_data_reshaped)\n", "print(predication)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Save the model and the scaler\n" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['scaler.pkl']" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "joblib.dump(model, 'autism_model.pkl')\n", "joblib.dump(scaler, 'scaler.pkl')" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "import joblib\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "model = joblib.load(\"autism_model.pkl\")" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "sample_input ={\n", " \"A1_Score\": 1,\n", " \"A2_Score\": 0,\n", " \"A3_Score\": 0,\n", " \"A4_Score\": 0,\n", " \"A5_Score\": 0,\n", " \"A6_Score\": 0,\n", " \"A7_Score\": 0,\n", " \"A8_Score\": 1,\n", " \"A9_Score\": 0,\n", " \"A10_Score\": 1,\n", " \"jaundice\": 1,\n", " \"autism\": 1,\n", " \"age\": 18.242557,\n", " \"gender\": 1,\n", " \"ethnicity\":1\n", "}" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[ 1. 0. 0. 0. 0. 0. 0.\n", " 1. 0. 1. 1. 1. 18.242557 1.\n", " 1. ]]\n" ] } ], "source": [ "import numpy as np\n", "\n", "# Given dictionary\n", "data = {\n", " 'A1_Score': 1, 'A2_Score': 0, 'A3_Score': 0, 'A4_Score': 0, 'A5_Score': 0, \n", " 'A6_Score': 0, 'A7_Score': 0, 'A8_Score': 1, 'A9_Score': 0, 'A10_Score': 1, \n", " 'jaundice': 1, 'autism': 1, 'age': 18.242557, \"gender\": 1,\n", " \"ethnicity\":1\n", "}\n", "\n", "# Convert the dictionary values to a list\n", "data_list = list(data.values())\n", "\n", "# Convert the list to a 2D numpy array\n", "data_array = np.array(data_list).reshape(1, -1)\n", "\n", "print(data_array)\n" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model.predict(data_array)[0]" ] } ], "metadata": { "kernelspec": { "display_name": "base", "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.12.4" } }, "nbformat": 4, "nbformat_minor": 2 }