From c879bce9fb26afa652f3ca5165630eb2cf1fc460 Mon Sep 17 00:00:00 2001 From: Jen Looper Date: Sun, 9 May 2021 14:58:13 -0400 Subject: [PATCH] solution edits --- API/1-API/solution/notebook.ipynb | 57 ++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/API/1-API/solution/notebook.ipynb b/API/1-API/solution/notebook.ipynb index 7e68127bd..0eb54e246 100644 --- a/API/1-API/solution/notebook.ipynb +++ b/API/1-API/solution/notebook.ipynb @@ -38,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": 77, + "execution_count": 53, "metadata": {}, "outputs": [ { @@ -76,7 +76,7 @@ "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
datetimecitystatecountryshapeduration (seconds)duration (hours/min)commentsdate postedlatitudelongitude
010/10/1949 20:30san marcostxuscylinder2700.045 minutesThis event took place in early fall around 194...4/27/200429.883056-97.941111
110/10/1949 21:00lackland afbtxNaNlight7200.01-2 hrs1949 Lackland AFB&#44 TX. Lights racing acros...12/16/200529.384210-98.581082
210/10/1955 17:00chester (uk/england)NaNgbcircle20.020 secondsGreen/Orange circular disc over Chester&#44 En...1/21/200853.200000-2.916667
310/10/1956 21:00ednatxuscircle20.01/2 hourMy older brother and twin sister were leaving ...1/17/200428.978333-96.645833
410/10/1960 20:00kaneohehiuslight900.015 minutesAS a Marine 1st Lt. flying an FJ4B fighter/att...1/22/200421.418056-157.803611
\n
" }, "metadata": {}, - "execution_count": 77 + "execution_count": 53 } ], "source": [ @@ -90,7 +90,33 @@ }, { "cell_type": "code", - "execution_count": 78, + "execution_count": 54, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array(['us', nan, 'gb', 'ca', 'au', 'de'], dtype=object)" + ] + }, + "metadata": {}, + "execution_count": 54 + } + ], + "source": [ + "from sklearn.preprocessing import LabelEncoder\n", + "\n", + "ufos = pd.DataFrame({'Seconds': ufos['duration (seconds)'], 'Country': ufos['country'],'Latitude': ufos['latitude'],'Longitude': ufos['longitude']})\n", + "\n", + "ufos.Country.unique()\n", + "\n", + "# 0 au, 1 ca, 2 de, 3 gb, 4 us" + ] + }, + { + "cell_type": "code", + "execution_count": 55, "metadata": {}, "outputs": [ { @@ -102,10 +128,6 @@ } ], "source": [ - "from sklearn.preprocessing import LabelEncoder\n", - "\n", - "ufos = pd.DataFrame({'Seconds': ufos['duration (seconds)'], 'Country': ufos['country'],'Latitude': ufos['latitude'],'Longitude': ufos['longitude']})\n", - "\n", "ufos.dropna(inplace=True)\n", "\n", "ufos['Country'] = LabelEncoder().fit_transform(ufos['Country'])\n", @@ -114,14 +136,12 @@ "\n", "ufos = ufos[(ufos['Seconds'] >= 1) & (ufos['Seconds'] <= 60)]\n", "\n", - "ufos.info()\n", - "\n", - "\n" + "ufos.info()" ] }, { "cell_type": "code", - "execution_count": 79, + "execution_count": 56, "metadata": {}, "outputs": [ { @@ -138,7 +158,7 @@ "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
SecondsCountryLatitudeLongitude
220.0353.200000-2.916667
320.0428.978333-96.645833
1430.0435.823889-80.253611
2360.0445.582778-122.352222
243.0351.783333-0.783333
\n
" }, "metadata": {}, - "execution_count": 79 + "execution_count": 56 } ], "source": [ @@ -152,12 +172,14 @@ "\n", "new_ufos['Country'] = LabelEncoder().fit_transform(new_ufos['Country'])\n", "\n", + "\n", + "\n", "new_ufos.head()" ] }, { "cell_type": "code", - "execution_count": 88, + "execution_count": 57, "metadata": {}, "outputs": [], "source": [ @@ -169,12 +191,12 @@ "y = new_ufos['Country']\n", "\n", "\n", - "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)" + "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)\n" ] }, { "cell_type": "code", - "execution_count": 89, + "execution_count": 58, "metadata": {}, "outputs": [ { @@ -214,12 +236,13 @@ "\n", "print(classification_report(y_test, predictions))\n", "print('Predicted labels: ', predictions)\n", - "print('Accuracy: ', accuracy_score(y_test, predictions))\n" + "print('Accuracy: ', accuracy_score(y_test, predictions))\n", + "\n" ] }, { "cell_type": "code", - "execution_count": 97, + "execution_count": 59, "metadata": {}, "outputs": [ {