Skip to content

Instantly share code, notes, and snippets.

View amir-rahnama's full-sized avatar
🎯
Focusing

Amir Rahnama amir-rahnama

🎯
Focusing
  • Stockholm, Sweden
View GitHub Profile
@amir-rahnama
amir-rahnama / cross_validation.py
Last active November 5, 2020 09:32
Cross validation with pure numpy
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 November 30, 2018 13:30
An implementation of KNN based on Numpy and Pandas
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 January 24, 2018 10:24
Dockerfile for your Flask application
FROM python:3
MAINTAINER Amir Rahnama "[email protected]"
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 December 6, 2016 20:39
Write Your Own Custom Image Dataset for Tensorflow
"""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 August 16, 2016 14:26
OSRM Docker-Compose file for a Stack with OSRM and Nominatim (Data container included)
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 October 22, 2017 00:58
Stackfile for Docker Cloud ElasticSearch Cluster (with Kibana)
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
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 February 21, 2019 18:54
Create N-grams for large text-files (very fast)
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 June 13, 2016 11:46
Capstone report for the Data Specialization Capstone project course
---
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 November 23, 2015 11:18
Send Result of MapReduce in Apache Spark (PySpark) over to a web socket: http://blog.ambodi.com/web-socket/
# 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)