This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load h2o | |
library(h2o) | |
library(ggplot2) | |
# Load Dataset - London Bike | |
london_bike <- read.csv('./london_merged.csv') | |
# Transforming Weather code and Season to factor | |
london_bike$weather_code <- as.factor(london_bike$weather_code) | |
london_bike$season <- as.factor(london_bike$season) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# caret library example used in blogpost: | |
# https://towardsdatascience.com/a-guide-to-using-caret-in-r-71dec0bda208 | |
library(caTools) | |
library(caret) | |
# Train Test Split on both Iris and Mtcars | |
train_test_split <- function(df) { | |
set.seed(42) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# R Function Best Practices used in blog post: | |
# https://towardsdatascience.com/writing-better-r-functions-best-practices-and-tips-d48ef0691c24 | |
library(ggplot2) | |
#----------------------------------# | |
# Function Indentation | |
# Proper Indentation - Bad Example |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# mlr library example clode - used in blog post: | |
# https://towardsdatascience.com/decision-tree-hyperparameter-tuning-in-r-using-mlr-3248bfd2d88c | |
titanic <- read.csv('train.csv') | |
library(dplyr) | |
library(rpart) | |
library(rpart.plot) | |
library(Metrics) | |
library(mlr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# dplyr library example used in blog post: | |
# https://towardsdatascience.com/8-cool-dplyr-function-to-learn-in-r-8736d7fa899c | |
library(dplyr) | |
starwars_df <- starwars | |
# Filter using Dplyr | |
filter_droids <- starwars %>% | |
filter(species == 'Droid') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rasterio | |
from rasterio.plot import show | |
url = "zip+file:data/mdt.zip!mdt.tif" | |
lisbon_elevation = rasterio.open(url) | |
# Plot the raster data to get a sense of it | |
show(lisbon_elevation, cmap="terrain") | |
# Get the elevation from the raster data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read the metro data | |
metro = pd.read_csv(Path("data", "metro_stations.csv")) | |
# Convert to a GeoDataFrame | |
metro = gpd.GeoDataFrame( | |
metro, | |
geometry=gpd.points_from_xy(metro.longitude, metro.latitude), | |
crs="epsg:4326" | |
).to_crs(epsg=3857) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Public Hospitals in Lisbon | |
hospitals_url = "https://opendata.arcgis.com/datasets/172678f193144512860a397fde991361_4.geojson" # GeoJSON | |
hospitals_gdf = gpd.read_file(hospitals_url).to_crs(epsg=3857) | |
hospitals_gdf.head() | |
# Buffer the house locations by 1km | |
house_data_gdf_buffer = ( | |
house_data_gdf | |
.copy() | |
.assign(geometry_buffer = lambda d: d.buffer(1000)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read data directly from the portuguese gov website. | |
parishes_url = "zip+https://dados.gov.pt/s/resources/freguesias-de-portugal/20181112-195834/cont-aad-caop2017.zip" | |
parishes = gpd.read_file(parishes_url) | |
# Left Join the house data to the parishes data, if house is `within` parish. | |
house_data_gdf = gpd.sjoin(house_data_gdf, parishes, how="left", op="within") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import geopandas as gpd | |
house_data_gdf = gpd.GeoDataFrame( | |
house_data, | |
geometry=gpd.points_from_xy( | |
house_data.longitude, | |
house_data.latitude | |
), | |
crs="epsg:4326", | |
) |
NewerOlder