Skip to content

Instantly share code, notes, and snippets.

Avatar

Amir Rahnama amir-rahnama

  • Stockholm, Sweden
View GitHub Profile
@amir-rahnama
amir-rahnama / cross_validation.py
Last active Nov 5, 2020
Cross validation with pure numpy
View cross_validation.py
import numpy as np
np.random.seed(0)
def cross_validation(X, y, cv_size=0.1):
"""Run cross validation on a numpy ndarray and return corresponding indices as well
@param: X data in the form of numpy ndarray
@param: y labels in the form of numpy ndarray
@param: cv_size size of the test set
@amir-rahnama
amir-rahnama / knn.ipynb
Last active Nov 30, 2018
An implementation of KNN based on Numpy and Pandas
View knn.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@amir-rahnama
amir-rahnama / Dockerfile
Created Jan 24, 2018
Dockerfile for your Flask application
View Dockerfile
FROM python:3
MAINTAINER Amir Rahnama "amirrahnama@gmail.com"
COPY . /app
WORKDIR /app
RUN pip install -r requirement.txt
RUN pip install --editable .
ENV FLASK_APP mini/app.py
@amir-rahnama
amir-rahnama / dataset.py
Created Dec 6, 2016
Write Your Own Custom Image Dataset for Tensorflow
View dataset.py
"""A generic module to read data."""
import numpy
import collections
from tensorflow.python.framework import dtypes
class DataSet(object):
"""Dataset class object."""
def __init__(self,
@amir-rahnama
amir-rahnama / docker-compose.yml
Created Aug 16, 2016
OSRM Docker-Compose file for a Stack with OSRM and Nominatim (Data container included)
View docker-compose.yml
osrm:
command: './start.sh Sweden http://download.geofabrik.de/europe/sweden-latest.osm.pbf'
image: 'irony/osrm5:latest'
ports:
- '5000:5000'
volumes_from:
- osrm-data
osrm-data:
image: 'irony/osrm5:latest'
volumes:
@amir-rahnama
amir-rahnama / stackfile.yml
Last active Oct 22, 2017
Stackfile for Docker Cloud ElasticSearch Cluster (with Kibana)
View stackfile.yml
es-master:
image: 'elasticsearch:latest'
command: 'elasticsearch --network.host=0.0.0.0 --node.master=true --cluster.name=escluster'
restart: always
es-develop:
image: 'elasticsearch:latest'
command: 'elasticsearch --network.host=0.0.0.0 --cluster.name=escluster --discovery.zen.ping.unicast.hosts=es-master'
deployment_strategy: high_availability
links:
- es-master
View 5-grams.R
library(text2vec)
library(SnowballC)
library(doParallel)
library(microbenchmark)
library(tm)
con <- file("/Users/ara/dev/personal/r/final/en_US/en_US.blogs.txt", "r")
blogs <- readLines(con, encoding = 'UTF-8')
close(con)
@amir-rahnama
amir-rahnama / create-ngrams.R
Last active Feb 21, 2019
Create N-grams for large text-files (very fast)
View create-ngrams.R
source("fast-ngrams.R")
con <- file("path_to_file", "r")
data <- readLines(con, encoding = 'UTF-8')
close(con)
data <- clean(data)
onegram <- text_to_ngrams(decode(data), 1)
bigram <- text_to_ngrams(decode(data), 2)
trigram <- text_to_ngrams(decode(data, 3))
@amir-rahnama
amir-rahnama / Capstone_Report.Rmd
Last active Jun 13, 2016
Capstone report for the Data Specialization Capstone project course
View Capstone_Report.Rmd
---
title: "Capstone First Milestone Report: Feature Engineering"
author: "Amir Hossein Rahnama"
date: "11 June 2016"
output: html_document
---
####Introduction
In this report, we are analyzing I have tried to start by showing a summary of all three data source from SwiftKey in terms of size. You can obtain the data with following code:
```{r eval=FALSE}
@amir-rahnama
amir-rahnama / map_reduce.py
Last active Nov 23, 2015
Send Result of MapReduce in Apache Spark (PySpark) over to a web socket: http://blog.ambodi.com/web-socket/
View map_reduce.py
# pip install websocket-client
from pyspark import SparkContext
from pyspark.streaming import StreamingContext
from websocket import create_connection
def take_rdd_send_to_socket(time, rdd, num=1000):
result = []
taken = rdd.take(num + 1)
print("-------------------------------------------")
print("Time: %s" % time)