Skip to content

Instantly share code, notes, and snippets.

View kocabiyik's full-sized avatar

Imran Kocabiyik kocabiyik

View GitHub Profile
@kocabiyik
kocabiyik / gradient-descent-ggplot2-with-momentum.R
Created March 17, 2019 18:01
Gradient Descent with Momentum
library(Deriv)
library(tidyverse)
library(stringr)
library(latex2exp)
library(glue)
# test function
f <- function(x) ((x^2-4*x+4)*(x^2+4*x+2))
# plotting the test function
@kocabiyik
kocabiyik / gradient-descent-ggplot2.R
Created March 17, 2019 17:55
Gradient Descent Visualization with ggplot2
library(Deriv)
library(tidyverse)
library(stringr)
library(latex2exp)
library(glue)
# test function
f <- function(x) ((x^2-4*x+4)*(x^2+4*x+2))
# plotting the test function
@kocabiyik
kocabiyik / random-walk.R
Last active March 17, 2019 18:05
Random Walk Plot
library(tidyverse)
create_random_walk_df <- function(n = 10, initial = c(0, 0)) {
df_direction <- data_frame(x = initial[1], y = initial[2])
for (i in 2:n){
direction <- sample(list(c(0, 1), c(1, 0), c(0, -1), c(-1, 0)), 1)
df_direction[i, 1] <- direction[[1]][1] + df_direction[i-1, 1]
df_direction[i, 2] <-direction[[1]][2] + df_direction[i-1, 2]
df_direction[i, 1] <- direction[[1]][1] + df_direction[i-1, 1]
df_direction[i, 2] <-direction[[1]][2] + df_direction[i-1, 2]
@kocabiyik
kocabiyik / Least Squares Visualized.R
Last active April 10, 2017 20:29
Best fit illustration with ggplot2
library(magrittr)
library(ggplot2)
library(broom)
mtcars %$%
lm(disp~wt) %>%
augment() %>%
ggplot(mapping = aes(x = wt, y = disp)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
geom_segment(aes(x = wt, xend = wt,
@kocabiyik
kocabiyik / flight-map.R
Last active April 11, 2017 18:24
Flight map template with ggplot2
# get data ----------
library(dplyr)
library(ggplot2)
df <- data_frame(origin = c("Istanbul", "Berlin", "Berlin", "Berlin"),
destination = c("Berlin", "Prague", "Tenerife", "Zurich"))
library(ggmap)
for (i in 1:nrow(df)) {
df$origin_lon[i] <- geocode(df$origin[i])[1, 1]
df$origin_lat[i] <- geocode(df$origin[i])[1, 2]