From ec20d79ab2051d36ae66650eda0ab67f32c29a5d Mon Sep 17 00:00:00 2001 From: Phil Weir Date: Thu, 11 May 2023 11:17:52 +0100 Subject: [PATCH] add restructured fat_learn --- .../fat_learn/.github/workflows/build.yaml | 42 +++++ 015-machine-learning/fat_learn/.gitignore | 4 + 015-machine-learning/fat_learn/LICENSE.md | 16 ++ 015-machine-learning/fat_learn/README.md | 5 + .../data/car-park-locations-data.csv | 31 ++++ 015-machine-learning/fat_learn/data/iris.data | 150 ++++++++++++++++++ .../fat_learn/fat_learn/__init__.py | 1 + .../fat_learn/fat_learn/carpark.py | 56 +++++++ .../fat_learn/fat_learn/iris.py | 78 +++++++++ .../fat_learn/fat_learn/utils.py | 25 +++ 015-machine-learning/fat_learn/pyproject.toml | 38 +++++ .../fat_learn/requirements.txt | 0 12 files changed, 446 insertions(+) create mode 100644 015-machine-learning/fat_learn/.github/workflows/build.yaml create mode 100644 015-machine-learning/fat_learn/.gitignore create mode 100644 015-machine-learning/fat_learn/LICENSE.md create mode 100644 015-machine-learning/fat_learn/README.md create mode 100644 015-machine-learning/fat_learn/data/car-park-locations-data.csv create mode 100644 015-machine-learning/fat_learn/data/iris.data create mode 100644 015-machine-learning/fat_learn/fat_learn/__init__.py create mode 100644 015-machine-learning/fat_learn/fat_learn/carpark.py create mode 100644 015-machine-learning/fat_learn/fat_learn/iris.py create mode 100644 015-machine-learning/fat_learn/fat_learn/utils.py create mode 100644 015-machine-learning/fat_learn/pyproject.toml create mode 100644 015-machine-learning/fat_learn/requirements.txt diff --git a/015-machine-learning/fat_learn/.github/workflows/build.yaml b/015-machine-learning/fat_learn/.github/workflows/build.yaml new file mode 100644 index 0000000..484d0f1 --- /dev/null +++ b/015-machine-learning/fat_learn/.github/workflows/build.yaml @@ -0,0 +1,42 @@ +name: Upload Python Package + +on: + tags: + - 'v*' + +permissions: + contents: read + +jobs: + deploy: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: '3.x' + - name: Set up Docker Context for Buildx + id: buildx-context + run: | + docker context create builders + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + version: latest + endpoint: builders + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + - name: Build package + run: | + python -m build + - name: Publish package + uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + packages_dir: build/wheels/ diff --git a/015-machine-learning/fat_learn/.gitignore b/015-machine-learning/fat_learn/.gitignore new file mode 100644 index 0000000..d656d1c --- /dev/null +++ b/015-machine-learning/fat_learn/.gitignore @@ -0,0 +1,4 @@ +__pycache__ +*env* +output.html +*.egg-info diff --git a/015-machine-learning/fat_learn/LICENSE.md b/015-machine-learning/fat_learn/LICENSE.md new file mode 100644 index 0000000..31be165 --- /dev/null +++ b/015-machine-learning/fat_learn/LICENSE.md @@ -0,0 +1,16 @@ +All code is MIT licensed. + +Belfast City Council's dataset of car parks is included under the UK Open Government License: http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/ +With thanks to OpenDataNI for supplying this dataset: https://opendatani.gov.uk + + +MIT LICENSE (for code) +=========== + +Copyright 2016 Phil Weir + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/015-machine-learning/fat_learn/README.md b/015-machine-learning/fat_learn/README.md new file mode 100644 index 0000000..6bb26ed --- /dev/null +++ b/015-machine-learning/fat_learn/README.md @@ -0,0 +1,5 @@ +This is a companion repository to the + +https://github.com/flaxandteal/python-course + +Python course. diff --git a/015-machine-learning/fat_learn/data/car-park-locations-data.csv b/015-machine-learning/fat_learn/data/car-park-locations-data.csv new file mode 100644 index 0000000..dea08a9 --- /dev/null +++ b/015-machine-learning/fat_learn/data/car-park-locations-data.csv @@ -0,0 +1,31 @@ +"NAME","ADDRESS","POSTCODE","NON-DESIGNATED BAYS","X CO-ORDINATE","Y CO-ORDINATE","LATITUDE","LONGITUDE","BLUE BADGE BAYS","FAMILY FRIENDLY BAYS","E-CAR BAYS","TARIFF","CHARGED HOURS" +"Ashdale Street Car Park","Ashdale Street - Off Bloomfield Ave.","BT5 5AX","87","336410","374115","54.596667","-5.890236","","","","TL3","Mon- Sat 0800-1800" +"Bankmore Street Car Park","Bankmore Street/Maryville Street","BT7 1AQ","46","333872","373522","54.592300","-5.929871","","","","TM12","Mon- Sat 0800-1800" +"Charlotte Street Car Park","Ormeau Avenue","BT7 1BG","90","334066","373514","54.592281","-5.926693","","","","TM7","Mon- Sat 0800-1800" +"Corporation Square Car Park","Corporation Sqaure/Tomb Street","BT1 3AJ","198","334270","374888","54.604340","-5.922644","","","","TL4","Mon- Sat 0800-1800" +"Corporation Street Car Park","Corporation Street","BT1 3DG","124","334214","374958","54.605046","-5.923358","","","","TL4","Mon- Sat 0800-1800" +"Cromac Street Car Park","Cromac Street","BT2 8JN","99","334232","373792","54.593924","-5.924265","1","1","2","TL6","Mon- Sat 0800-1800" +"Dunbar Street Car Park","Talbot Street/Dunbar Street","BT2 1LH","32","334090","374713","54.603248","-5.925944","2","1","","TM10","Mon- Sat 0800-1800" +"Dundela Crescent Car Park","Dundela Crescent","BT4 3BN ","26","337106","374514","54.600309","-5.878777","","","","Free","Free" +"Exchange Street Car Park","Exchange Street off Corporation Street","BT1 2LJ","46","334135","374749","54.600396","-5.925242","2","1","","TM8","Mon- Sat 0800-1800" +"Frederick Street Car Park","Frederick Street","BT1 2LW","134","333821","375030","54.605616","-5.930339","1","","","TL4","Mon- Sat 0800-1800" +"Glenburn Road Car Park","Glenburn Road-Dunmurry","BT17 9AG","123","329158","368703","54.550223","-6.005425","3","","2","Free","Free" +"Grampian Avenue Car Park","Grampian Avenue","BT4 3AG","41","336658","374237","54.598169","-5.886109","1","1","","Free","Free" +"Hope Street North Car Park","Hope Street","BT12 5EE","41","333469","373666","54.593413","-5.935841","","","2","TM12","Mon- Sat 0800-2100" +"Kent Street Car Park","Kent Street","BT1 2JA","66","333547","374736","54.603463","-5.933922","2","","","TM10","Mon- Sat 0800-1800" +"Little Donegall Street Car Park","Little Donegal Street/Stephen Street","BT1 2JD","105","333607","374853","54.604610","-5.932752","2","2","2","TL6","Mon- Sat 0800-1800" +"Little Victoria Street Car Park","Little Victoria Street/Bruce Street","BT2 7JH","84","333650","373570","54.592701","-5.933385","2","1","2","TM12","Mon- Sat 0800-2100" +"Marlborough Avenue Car Park","Marlborough Avenue","BT9 7HB","31","332265","371684","54.575889","-5.955479","2","2","","TL2","Mon- Sat 0800-1800" +"Northumberland Street Car Park","Northumberland Street/Kendal Street","BT13 2JF","87","332750","374714","54.602989","-5.946541","2","2","","Free","Free" +"Parkgate Avenue Car Park","Parkgate Avenue","BT4 1JA","36","336658","374375","54.599127","-5.886814","1","1","","Free","Free" +"Ravenscroft Avenue Car Park","Ravenscroft Avenue","BT5 5BA","53","336608","374148","54.597197","-5.887805","3","2","","Free","Free" +"Sandown Road Car Park","Sandown Road","BT5 6GT","65","337804","373839","54.594108","-5.868433","2","2","","Free","Free" +"Shaw's Bridge Car Park","Malone Road/Shaws Bridge","BT9 5YN","57","332379","369116","54.553536","-5.954924","4","3","","Free","Free" +"Smithfield Car Park","Wine Tavern Street","BT1 1JQ","107","333543","374569","54.601901","-5.933594","2","","","TM12","Mon- Sat 0800-1800 Thurs until 2100" +"Station Street Car Park","Station Street","BT5 1AS","114","334561","374431","54.600366","-5.918011","","","","TL6","Mon- Sat 0800-1800" +"Wandsworth Road Car Park","Wandsworth Road","BT4 3LS","24","338755","373976","54.595118","-5.854048","","","","Free","Free" +"Westminster Avenue (East) Car Park","Westminster Avenue ","BT4 1QQ","10","336522","374275","54.598300","-5.888232","","","","Free","Free" +"Westminster Avenue (North) Car Park","Westminster Avenue North","BT4 1QQ","70","336460","374286","54.598303","-5.889029","","","","Free","Free" +"Westminster Avenue (West) Car Park","Westminster Avenue ","BT4 1QQ","10","336543","374286","54.598300","-5.888165","","","","Free","Free" +"Whitla Street Car Park","Whitla Street","BT15 1JP","50","334266","375596","54.611024","-5.922635","","","","Free","Free" +"Lancaster Street - York Street","York Street","BT15 1AS","53","333947","375082","54.606033","-5.927695","","","","TL4","Mon- Sat 0800-1800" \ No newline at end of file diff --git a/015-machine-learning/fat_learn/data/iris.data b/015-machine-learning/fat_learn/data/iris.data new file mode 100644 index 0000000..a3490e0 --- /dev/null +++ b/015-machine-learning/fat_learn/data/iris.data @@ -0,0 +1,150 @@ +5.1,3.5,1.4,0.2,Iris-setosa +4.9,3.0,1.4,0.2,Iris-setosa +4.7,3.2,1.3,0.2,Iris-setosa +4.6,3.1,1.5,0.2,Iris-setosa +5.0,3.6,1.4,0.2,Iris-setosa +5.4,3.9,1.7,0.4,Iris-setosa +4.6,3.4,1.4,0.3,Iris-setosa +5.0,3.4,1.5,0.2,Iris-setosa +4.4,2.9,1.4,0.2,Iris-setosa +4.9,3.1,1.5,0.1,Iris-setosa +5.4,3.7,1.5,0.2,Iris-setosa +4.8,3.4,1.6,0.2,Iris-setosa +4.8,3.0,1.4,0.1,Iris-setosa +4.3,3.0,1.1,0.1,Iris-setosa +5.8,4.0,1.2,0.2,Iris-setosa +5.7,4.4,1.5,0.4,Iris-setosa +5.4,3.9,1.3,0.4,Iris-setosa +5.1,3.5,1.4,0.3,Iris-setosa +5.7,3.8,1.7,0.3,Iris-setosa +5.1,3.8,1.5,0.3,Iris-setosa +5.4,3.4,1.7,0.2,Iris-setosa +5.1,3.7,1.5,0.4,Iris-setosa +4.6,3.6,1.0,0.2,Iris-setosa +5.1,3.3,1.7,0.5,Iris-setosa +4.8,3.4,1.9,0.2,Iris-setosa +5.0,3.0,1.6,0.2,Iris-setosa +5.0,3.4,1.6,0.4,Iris-setosa +5.2,3.5,1.5,0.2,Iris-setosa +5.2,3.4,1.4,0.2,Iris-setosa +4.7,3.2,1.6,0.2,Iris-setosa +4.8,3.1,1.6,0.2,Iris-setosa +5.4,3.4,1.5,0.4,Iris-setosa +5.2,4.1,1.5,0.1,Iris-setosa +5.5,4.2,1.4,0.2,Iris-setosa +4.9,3.1,1.5,0.1,Iris-setosa +5.0,3.2,1.2,0.2,Iris-setosa +5.5,3.5,1.3,0.2,Iris-setosa +4.9,3.1,1.5,0.1,Iris-setosa +4.4,3.0,1.3,0.2,Iris-setosa +5.1,3.4,1.5,0.2,Iris-setosa +5.0,3.5,1.3,0.3,Iris-setosa +4.5,2.3,1.3,0.3,Iris-setosa +4.4,3.2,1.3,0.2,Iris-setosa +5.0,3.5,1.6,0.6,Iris-setosa +5.1,3.8,1.9,0.4,Iris-setosa +4.8,3.0,1.4,0.3,Iris-setosa +5.1,3.8,1.6,0.2,Iris-setosa +4.6,3.2,1.4,0.2,Iris-setosa +5.3,3.7,1.5,0.2,Iris-setosa +5.0,3.3,1.4,0.2,Iris-setosa +7.0,3.2,4.7,1.4,Iris-versicolor +6.4,3.2,4.5,1.5,Iris-versicolor +6.9,3.1,4.9,1.5,Iris-versicolor +5.5,2.3,4.0,1.3,Iris-versicolor +6.5,2.8,4.6,1.5,Iris-versicolor +5.7,2.8,4.5,1.3,Iris-versicolor +6.3,3.3,4.7,1.6,Iris-versicolor +4.9,2.4,3.3,1.0,Iris-versicolor +6.6,2.9,4.6,1.3,Iris-versicolor +5.2,2.7,3.9,1.4,Iris-versicolor +5.0,2.0,3.5,1.0,Iris-versicolor +5.9,3.0,4.2,1.5,Iris-versicolor +6.0,2.2,4.0,1.0,Iris-versicolor +6.1,2.9,4.7,1.4,Iris-versicolor +5.6,2.9,3.6,1.3,Iris-versicolor +6.7,3.1,4.4,1.4,Iris-versicolor +5.6,3.0,4.5,1.5,Iris-versicolor +5.8,2.7,4.1,1.0,Iris-versicolor +6.2,2.2,4.5,1.5,Iris-versicolor +5.6,2.5,3.9,1.1,Iris-versicolor +5.9,3.2,4.8,1.8,Iris-versicolor +6.1,2.8,4.0,1.3,Iris-versicolor +6.3,2.5,4.9,1.5,Iris-versicolor +6.1,2.8,4.7,1.2,Iris-versicolor +6.4,2.9,4.3,1.3,Iris-versicolor +6.6,3.0,4.4,1.4,Iris-versicolor +6.8,2.8,4.8,1.4,Iris-versicolor +6.7,3.0,5.0,1.7,Iris-versicolor +6.0,2.9,4.5,1.5,Iris-versicolor +5.7,2.6,3.5,1.0,Iris-versicolor +5.5,2.4,3.8,1.1,Iris-versicolor +5.5,2.4,3.7,1.0,Iris-versicolor +5.8,2.7,3.9,1.2,Iris-versicolor +6.0,2.7,5.1,1.6,Iris-versicolor +5.4,3.0,4.5,1.5,Iris-versicolor +6.0,3.4,4.5,1.6,Iris-versicolor +6.7,3.1,4.7,1.5,Iris-versicolor +6.3,2.3,4.4,1.3,Iris-versicolor +5.6,3.0,4.1,1.3,Iris-versicolor +5.5,2.5,4.0,1.3,Iris-versicolor +5.5,2.6,4.4,1.2,Iris-versicolor +6.1,3.0,4.6,1.4,Iris-versicolor +5.8,2.6,4.0,1.2,Iris-versicolor +5.0,2.3,3.3,1.0,Iris-versicolor +5.6,2.7,4.2,1.3,Iris-versicolor +5.7,3.0,4.2,1.2,Iris-versicolor +5.7,2.9,4.2,1.3,Iris-versicolor +6.2,2.9,4.3,1.3,Iris-versicolor +5.1,2.5,3.0,1.1,Iris-versicolor +5.7,2.8,4.1,1.3,Iris-versicolor +6.3,3.3,6.0,2.5,Iris-virginica +5.8,2.7,5.1,1.9,Iris-virginica +7.1,3.0,5.9,2.1,Iris-virginica +6.3,2.9,5.6,1.8,Iris-virginica +6.5,3.0,5.8,2.2,Iris-virginica +7.6,3.0,6.6,2.1,Iris-virginica +4.9,2.5,4.5,1.7,Iris-virginica +7.3,2.9,6.3,1.8,Iris-virginica +6.7,2.5,5.8,1.8,Iris-virginica +7.2,3.6,6.1,2.5,Iris-virginica +6.5,3.2,5.1,2.0,Iris-virginica +6.4,2.7,5.3,1.9,Iris-virginica +6.8,3.0,5.5,2.1,Iris-virginica +5.7,2.5,5.0,2.0,Iris-virginica +5.8,2.8,5.1,2.4,Iris-virginica +6.4,3.2,5.3,2.3,Iris-virginica +6.5,3.0,5.5,1.8,Iris-virginica +7.7,3.8,6.7,2.2,Iris-virginica +7.7,2.6,6.9,2.3,Iris-virginica +6.0,2.2,5.0,1.5,Iris-virginica +6.9,3.2,5.7,2.3,Iris-virginica +5.6,2.8,4.9,2.0,Iris-virginica +7.7,2.8,6.7,2.0,Iris-virginica +6.3,2.7,4.9,1.8,Iris-virginica +6.7,3.3,5.7,2.1,Iris-virginica +7.2,3.2,6.0,1.8,Iris-virginica +6.2,2.8,4.8,1.8,Iris-virginica +6.1,3.0,4.9,1.8,Iris-virginica +6.4,2.8,5.6,2.1,Iris-virginica +7.2,3.0,5.8,1.6,Iris-virginica +7.4,2.8,6.1,1.9,Iris-virginica +7.9,3.8,6.4,2.0,Iris-virginica +6.4,2.8,5.6,2.2,Iris-virginica +6.3,2.8,5.1,1.5,Iris-virginica +6.1,2.6,5.6,1.4,Iris-virginica +7.7,3.0,6.1,2.3,Iris-virginica +6.3,3.4,5.6,2.4,Iris-virginica +6.4,3.1,5.5,1.8,Iris-virginica +6.0,3.0,4.8,1.8,Iris-virginica +6.9,3.1,5.4,2.1,Iris-virginica +6.7,3.1,5.6,2.4,Iris-virginica +6.9,3.1,5.1,2.3,Iris-virginica +5.8,2.7,5.1,1.9,Iris-virginica +6.8,3.2,5.9,2.3,Iris-virginica +6.7,3.3,5.7,2.5,Iris-virginica +6.7,3.0,5.2,2.3,Iris-virginica +6.3,2.5,5.0,1.9,Iris-virginica +6.5,3.0,5.2,2.0,Iris-virginica +6.2,3.4,5.4,2.3,Iris-virginica +5.9,3.0,5.1,1.8,Iris-virginica diff --git a/015-machine-learning/fat_learn/fat_learn/__init__.py b/015-machine-learning/fat_learn/fat_learn/__init__.py new file mode 100644 index 0000000..f102a9c --- /dev/null +++ b/015-machine-learning/fat_learn/fat_learn/__init__.py @@ -0,0 +1 @@ +__version__ = "0.0.1" diff --git a/015-machine-learning/fat_learn/fat_learn/carpark.py b/015-machine-learning/fat_learn/fat_learn/carpark.py new file mode 100644 index 0000000..73c9428 --- /dev/null +++ b/015-machine-learning/fat_learn/fat_learn/carpark.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Find the closest carparks to the Computer Science building + +@author: Phil Weir +@license: MIT +""" + +import pandas +from sklearn.neighbors import NearestNeighbors + +from . import utils + +def closest_carpark(gdf, target): + X = [] + def extract_points(row): + X.append([row.geometry.y, row.geometry.x]) + + gdf.apply(extract_points, axis=1) + nbrs = NearestNeighbors(n_neighbors=4).fit(X) + + Y = [target] + # This maps multiple targets at once efficiently, but we just need one + distances_per_Y_row, row_numbers_per_Y_row = nbrs.kneighbors(Y) + + distances = distances_per_Y_row[0] + row_numbers = row_numbers_per_Y_row[0] + + # Report distance as a comparison + reference_distance = distances[0] + # Why are there two zeroes below? What happens if Y has multiple entries? + for distance, row_i in zip(distances, row_numbers): + relative_distance = 100 * (distance / reference_distance - 1) + row = gdf.iloc[row_i] + print(row['NAME'], " is ", relative_distance, "percent further than the closest") + + +def run(): + # Load data into variable called "df" + df = pandas.read_csv('car-park-locations-data.csv', encoding='latin1') + + # Because why not? + # print(df.describe()) + + # Get a geopandas dataframe, from a normal pandas one + # gdf = utils.to_geo_dataframe(df) + + # Create a plot + # utils.plot_gdf("output.html", gdf) + + # CompSci Building 54.5817428 -5.9374874 + closest_carpark(gdf, [54.5817428, -5.9374874]) + +if __name__ == "__main__": + run() diff --git a/015-machine-learning/fat_learn/fat_learn/iris.py b/015-machine-learning/fat_learn/fat_learn/iris.py new file mode 100644 index 0000000..3a6f8ef --- /dev/null +++ b/015-machine-learning/fat_learn/fat_learn/iris.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Test learning algorithms on the classic Iris dataset. + +@author: Phil Weir +@license: MIT +""" + +import os +import numpy as np +import pandas + +from sklearn import svm + +from sklearn import datasets +from pandas.plotting import scatter_matrix + +def run(): + # Why is this if-statement here? Why don't we just use lines 21-22? + if not os.path.exists('iris.data'): + url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data" + df = pandas.read_csv(url, header=None) + df.to_csv('iris.data', header=False, index=False) + + df = pandas.read_csv('./iris.data', header=None) + + # When you are happy with what this looks like, remove it! + print(df) + + # Why is this important? + reordering = np.random.permutation(df.index) + df = df.reindex(reordering) + + # This is the set of inputs + X_training = df.iloc[:-30, :-1] + # This is the known classifiers + y_training_target = df.iloc[:-30, -1] + + # This set we will use for testing the model + X_testing = df.iloc[-30:, :-1] + # We will measure our predictions against these + y_testing_target = df.iloc[-30:, -1] + + # Make a model + classifier = svm.SVC(kernel='linear', C=1).fit(X_training, y_training_target) + + # Evaluate it + score = classifier.score(X_testing, y_testing_target) + print(score) + + # What type of flower is an iris with: + # Sepal length: 4.7cm + # Sepal width: 3.4cm + # Petal length: 1.1cm + # Petal width: 0.2cm + # ? + samples = [ + [4.7, 3.4, 1.1, 0.2] + ] + print(classifier.predict(samples)) + + # TASKS + #------ + # 0 - What, in words, is each slicing operation doing? + # + # 1 - Download the CSV and open it from the same folder as script (still with read_csv) + + # 2 - Add plots of sepal length, sepal width, petal length and petal width using Pandas' + # - scatter_matrix (hint: create a dataframe with those four columns) + # - RadViz (familiar looking dataset on the Pandas manual page!) + + # 3 - Switch to using "test_train_split" instead of using "-30" and slicing + + # 4 - Instead of using "score", use "cross_val_score": http://scikit-learn.org/stable/modules/cross_validation.html#cross-validation + +if __name__ == "__main__": + run() diff --git a/015-machine-learning/fat_learn/fat_learn/utils.py b/015-machine-learning/fat_learn/fat_learn/utils.py new file mode 100644 index 0000000..1b34a35 --- /dev/null +++ b/015-machine-learning/fat_learn/fat_learn/utils.py @@ -0,0 +1,25 @@ +import geopandas +import folium +from shapely.geometry import Point + +def to_geo_dataframe(df): + """Turn a carpark DataFrame into a GeoDataFrame.""" + + geometry = [Point(row['LONGITUDE'], row['LATITUDE']) for index, row in df.iterrows()] + + gdf = geopandas.GeoDataFrame(df, geometry=geometry) + gdf.crs = {'init': 'epsg:4326'} + + return gdf + + +def plot_gdf(filename, gdf): + """Save an interactive map plot.""" + + map = folium.Map( + location=[54.6, -5.90], + zoom_start=10 + ) + carparks = folium.features.GeoJson(gdf) + map.add_children(carparks) + map.save(filename) \ No newline at end of file diff --git a/015-machine-learning/fat_learn/pyproject.toml b/015-machine-learning/fat_learn/pyproject.toml new file mode 100644 index 0000000..ff55633 --- /dev/null +++ b/015-machine-learning/fat_learn/pyproject.toml @@ -0,0 +1,38 @@ +[project] +name = "fat_learn" +license = { file = "LICENSE.md" } +authors = [{ name = "Phil Weir", email = "phil.weir@flaxandteal.co.uk" }] +dynamic = ["version"] +requires-python = ">= 3.9" +readme = "README.md" + +dependencies = [ + "scipy", + "scikit-image", + "scikit-learn", + "numpy", + "pandas", + "matplotlib", + "geopandas", + "folium", + "shapely" +] + +[project.optional-dependencies] +test = [ + "pytest >= 7", + "ruff", +] + +[tool.black] +line-length = 120 + +[tool.setuptools] +packages = ["fat_learn"] + +[tool.setuptools.dynamic] +version = { attr = "fat_learn.__version__" } + +[build-system] +requires = ["setuptools ~= 64.0"] +build-backend = "setuptools.build_meta" diff --git a/015-machine-learning/fat_learn/requirements.txt b/015-machine-learning/fat_learn/requirements.txt new file mode 100644 index 0000000..e69de29