{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "# Lab 10\n", "\n", "Suppose you have a list of positions of possible clients of Uber in Lisbon (Passageiros.csv). How many cars could you use and where they could be positioned in order to reduce time? Use a cluster analysis appraoch to support the solution of this problem.\n", "\n", "* import the libraries needed\n", "* import dataset from Passageiros.csv file\n", "* Verify imported data\n", "* verify data types and convert into numeric if needed. Use for example, df['x']=pd.to_numeric(df['x'], errors='coerce')\n", "* plot a scatter chart\n", "* create a X dataframe including only numeric columns\n", "* calculete WCSS using X dataframe:\n", "\n", " wcss = []\n", "\n", " for i in range(1, 11):\n", "\n", " kmeans = KMeans(n_clusters=i, init='k-means++', max_iter=300, n_init=10, random_state=0)\n", "\n", " kmeans.fit(df)\n", "\n", " wcss.append(kmeans.inertia_)\n", "\n", " plt.plot(range(1, 11), wcss)\n", "\n", " plt.title('Elbow Method')\n", "\n", " plt.xlabel('Number of clusters')\n", "\n", " plt.ylabel('WCSS')\n", "\n", " plt.show()\n", "\n", " plot a scatter chart showing centroids of the clusters estimated\n", "\n" ] }, { "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.0" } }, "nbformat": 4, "nbformat_minor": 2 }