From 5aaff9711387ce1ea1ec8ee5c5b4ecd9e1ea3dd1 Mon Sep 17 00:00:00 2001 From: leshe4ka46 Date: Tue, 11 Nov 2025 11:34:38 +0300 Subject: upd --- .../3-05_knn.ipynb | 906 ++++++++++++++++++++- 1 file changed, 879 insertions(+), 27 deletions(-) (limited to 'Fundamentals_of_Accelerated_Data_Science/3-05_knn.ipynb') diff --git a/Fundamentals_of_Accelerated_Data_Science/3-05_knn.ipynb b/Fundamentals_of_Accelerated_Data_Science/3-05_knn.ipynb index e6d543f..48577c4 100644 --- a/Fundamentals_of_Accelerated_Data_Science/3-05_knn.ipynb +++ b/Fundamentals_of_Accelerated_Data_Science/3-05_knn.ipynb @@ -41,7 +41,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -66,7 +66,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -76,27 +76,134 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "node_id object\n", + "east float32\n", + "north float32\n", + "type object\n", + "dtype: object" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "road_nodes.dtypes" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(3121148, 4)" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "road_nodes.shape" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "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", + "
node_ideastnorthtype
0id02FE73D4-E88D-4119-8DC2-6E80DE6F6594320608.09375870994.0000junction
1id634D65C1-C38B-4868-9080-2E1E47F0935C320628.50000871103.8125road end
2idDC14D4D1-774E-487D-8EDE-60B129E5482C320635.46875870983.8750junction
3id51555819-1A39-4B41-B0C9-C6D2086D9921320648.68750871083.5625junction
4id9E362428-79D7-4EE3-B015-0CE3F6A78A69320658.18750871162.3750junction
\n", + "
" + ], + "text/plain": [ + " node_id east north type\n", + "0 id02FE73D4-E88D-4119-8DC2-6E80DE6F6594 320608.09375 870994.0000 junction\n", + "1 id634D65C1-C38B-4868-9080-2E1E47F0935C 320628.50000 871103.8125 road end\n", + "2 idDC14D4D1-774E-487D-8EDE-60B129E5482C 320635.46875 870983.8750 junction\n", + "3 id51555819-1A39-4B41-B0C9-C6D2086D9921 320648.68750 871083.5625 junction\n", + "4 id9E362428-79D7-4EE3-B015-0CE3F6A78A69 320658.18750 871162.3750 junction" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "road_nodes.head()" ] @@ -111,7 +218,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -120,27 +227,308 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "OrganisationID int64\n", + "OrganisationCode object\n", + "OrganisationType object\n", + "SubType object\n", + "Sector object\n", + "OrganisationStatus object\n", + "IsPimsManaged object\n", + "OrganisationName object\n", + "Address1 object\n", + "Address2 object\n", + "Address3 object\n", + "City object\n", + "County object\n", + "Postcode object\n", + "Latitude float64\n", + "Longitude float64\n", + "ParentODSCode object\n", + "ParentName object\n", + "Phone object\n", + "Email object\n", + "Website object\n", + "Fax object\n", + "northing float64\n", + "easting float64\n", + "dtype: object" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "hospitals.dtypes" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(1226, 24)" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "hospitals.shape" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "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", + "
OrganisationIDOrganisationCodeOrganisationTypeSubTypeSectorOrganisationStatusIsPimsManagedOrganisationNameAddress1Address2...LatitudeLongitudeParentODSCodeParentNamePhoneEmailWebsiteFaxnorthingeasting
017970NDA07HospitalHospitalIndependent SectorVisibleTRUEWalton Community Hospital - Virgin Care Servic...<NA>Rodney Road...51.379997-0.406042NDAVirgin Care Services Ltd01932 414205<NA><NA>01932 253674165810.4688510917.5313
117981NDA18HospitalHospitalIndependent SectorVisibleTRUEWoking Community Hospital (Virgin Care)<NA>Heathside Road...51.315132-0.556289NDAVirgin Care Services Ltd01483 715911<NA><NA><NA>158381.3438500604.8438
218102NLT02HospitalHospitalNHS SectorVisibleTRUENorth Somerset Community HospitalNorth Somerset Community HospitalOld Street...51.437195-2.847193NLTNorth Somerset Community Partnership Community...01275 872212<NA>http://www.nscphealth.co.uk<NA>171305.7813341119.3750
318138NMP01HospitalHospitalIndependent SectorVisibleFALSEBridgewater Hospital120 Princess Road<NA>...53.459743-2.245469NMPBridgewater Hospital (Manchester) Ltd0161 2270000<NA>www.bridgewaterhospital.com<NA>395944.5625383703.5938
418142NMV01HospitalHospitalIndependent SectorVisibleTRUEKneesworth HouseOld North RoadBassingbourn...52.078121-0.030604NMVPartnerships In Care Ltd01763 255 700reception_kneesworthhouse@partnershipsincare.c...www.partnershipsincare.co.uk<NA>244071.7031534945.1875
\n", + "

5 rows × 24 columns

\n", + "
" + ], + "text/plain": [ + " OrganisationID OrganisationCode OrganisationType SubType \\\n", + "0 17970 NDA07 Hospital Hospital \n", + "1 17981 NDA18 Hospital Hospital \n", + "2 18102 NLT02 Hospital Hospital \n", + "3 18138 NMP01 Hospital Hospital \n", + "4 18142 NMV01 Hospital Hospital \n", + "\n", + " Sector OrganisationStatus IsPimsManaged \\\n", + "0 Independent Sector Visible TRUE \n", + "1 Independent Sector Visible TRUE \n", + "2 NHS Sector Visible TRUE \n", + "3 Independent Sector Visible FALSE \n", + "4 Independent Sector Visible TRUE \n", + "\n", + " OrganisationName \\\n", + "0 Walton Community Hospital - Virgin Care Servic... \n", + "1 Woking Community Hospital (Virgin Care) \n", + "2 North Somerset Community Hospital \n", + "3 Bridgewater Hospital \n", + "4 Kneesworth House \n", + "\n", + " Address1 Address2 ... Latitude \\\n", + "0 Rodney Road ... 51.379997 \n", + "1 Heathside Road ... 51.315132 \n", + "2 North Somerset Community Hospital Old Street ... 51.437195 \n", + "3 120 Princess Road ... 53.459743 \n", + "4 Old North Road Bassingbourn ... 52.078121 \n", + "\n", + " Longitude ParentODSCode \\\n", + "0 -0.406042 NDA \n", + "1 -0.556289 NDA \n", + "2 -2.847193 NLT \n", + "3 -2.245469 NMP \n", + "4 -0.030604 NMV \n", + "\n", + " ParentName Phone \\\n", + "0 Virgin Care Services Ltd 01932 414205 \n", + "1 Virgin Care Services Ltd 01483 715911 \n", + "2 North Somerset Community Partnership Community... 01275 872212 \n", + "3 Bridgewater Hospital (Manchester) Ltd 0161 2270000 \n", + "4 Partnerships In Care Ltd 01763 255 700 \n", + "\n", + " Email \\\n", + "0 \n", + "1 \n", + "2 \n", + "3 \n", + "4 reception_kneesworthhouse@partnershipsincare.c... \n", + "\n", + " Website Fax northing easting \n", + "0 01932 253674 165810.4688 510917.5313 \n", + "1 158381.3438 500604.8438 \n", + "2 http://www.nscphealth.co.uk 171305.7813 341119.3750 \n", + "3 www.bridgewaterhospital.com 395944.5625 383703.5938 \n", + "4 www.partnershipsincare.co.uk 244071.7031 534945.1875 \n", + "\n", + "[5 rows x 24 columns]" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "hospitals.head()" ] @@ -161,7 +549,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -171,9 +559,427 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
NearestNeighbors()
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": [ + "NearestNeighbors()" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\n", "road_locs = road_nodes[['east', 'north']]\n", @@ -192,7 +998,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -209,9 +1015,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hospital coordinates:\n", + "easting 260713.17190\n", + "northing 56303.21875\n", + "Name: 10, dtype: float64\n" + ] + } + ], "source": [ "SELECTED_RESULT = 10\n", "print('hospital coordinates:\\n', hospitals.loc[SELECTED_RESULT, ['easting', 'northing']], sep='')" @@ -226,9 +1043,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "node_id:\n", + "0 118559\n", + "1 118560\n", + "2 118678\n", + "Name: 10, dtype: int64\n" + ] + } + ], "source": [ "nearest_road_nodes = indices.iloc[SELECTED_RESULT, 0:3]\n", "print('node_id:\\n', nearest_road_nodes, sep='')" @@ -243,18 +1072,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "road_node coordinates:\n", + " east north\n", + "118559 260697.859375 56322.710938\n", + "118560 260722.812500 56207.925781\n", + "118678 260540.000000 56105.000000\n" + ] + } + ], "source": [ "print('road_node coordinates:\\n', road_nodes.loc[nearest_road_nodes, ['east', 'north']], sep='')" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'status': 'ok', 'restart': True}" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import IPython\n", "app = IPython.Application.instance()\n", -- cgit v1.2.3