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
| # l2 norm of a vector | |
| # = sqrt(a1^2 + a2^2 + a3^2) | |
| from numpy import array | |
| from numpy.linalg import norm | |
| a = array([1, 2, 3]) | |
| print(a) | |
| l2 = norm(a) | |
| print(l2) # 3.7416573867 |
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
| """ | |
| DISTANCE BETWEEN COORDINATES | |
| """ | |
| import math | |
| lat1 = 40.813078 | |
| lat2 = 55.340000 | |
| lon1 = -73.046388 | |
| lon2 = -131.640000 |
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
| from datetime import datetime | |
| from sqlalchemy import (MetaData, Table, Column, Integer, Numeric, String, | |
| DateTime, ForeignKey, create_engine) | |
| metadata = MetaData() | |
| cookies = Table('cookies', metadata, | |
| Column('cookie_id', Integer(), primary_key=True), | |
| Column('cookie_name', String(50), index=True), |
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
| # AR example | |
| from statsmodels.tsa.ar_model import AR | |
| from random import random | |
| # contrived dataset | |
| data = [x + random() for x in range(1, 100)] | |
| # fit model | |
| model = AR(data) | |
| model_fit = model.fit() | |
| # make prediction | |
| yhat = model_fit.predict(len(data), len(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
| # MA example | |
| from statsmodels.tsa.arima_model import ARMA | |
| from random import random | |
| # contrived dataset | |
| data = [x + random() for x in range(1, 100)] | |
| # fit model | |
| model = ARMA(data, order=(0, 1)) | |
| model_fit = model.fit(disp=False) | |
| # make prediction | |
| yhat = model_fit.predict(len(data), len(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
| # ARMA example | |
| from statsmodels.tsa.arima_model import ARMA | |
| from random import random | |
| # contrived dataset | |
| data = [random() for x in range(1, 100)] | |
| # fit model | |
| model = ARMA(data, order=(2, 1)) | |
| model_fit = model.fit(disp=False) | |
| # make prediction | |
| yhat = model_fit.predict(len(data), len(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
| # SES example | |
| from statsmodels.tsa.holtwinters import SimpleExpSmoothing | |
| from random import random | |
| # contrived dataset | |
| data = [x + random() for x in range(1, 100)] | |
| # fit model | |
| model = SimpleExpSmoothing(data) | |
| model_fit = model.fit() | |
| # make prediction | |
| yhat = model_fit.predict(len(data), len(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
| # HWES example | |
| from statsmodels.tsa.holtwinters import ExponentialSmoothing | |
| from random import random | |
| # contrived dataset | |
| data = [x + random() for x in range(1, 100)] | |
| # fit model | |
| model = ExponentialSmoothing(data) | |
| model_fit = model.fit() | |
| # make prediction | |
| yhat = model_fit.predict(len(data), len(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
| import glob | |
| import os | |
| import cv2 | |
| import concurrent.futures | |
| def load_and_resize(image_filename): | |
| ### Read in the image data | |
| img = cv2.imread(image_filename) | |
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
| from geopy import GoogleV3 | |
| place = "221b Baker Street, London" | |
| location = GoogleV3().geocode(place) | |
| print(location.address) | |
| print(location.location) |
OlderNewer