def frac_time(): urls, reqmap = get_data.getData() reqmap = sorted(reqmap, key=lambda x: return x['totalTime']) display_urls = reqmap[:10] return display_urls
def computeFraction( poi_messages, all_messages ): """ given a number messages to/from POI (numerator) and number of all messages to/from a person (denominator), return the fraction of messages to/from that person that are from/to a POI """ ### you fill in this code, so that it returns either ### the fraction of all messages to this person that come from POIs ### or ### the fraction of all messages from this person that are sent to POIs ### the same code can be used to compute either quantity ### beware of "NaN" when there is no known email address (and so ### no filled email features), and integer division! ### in case of poi_messages or all_messages having "NaN" value, return 0. fraction = 0. for key in data_dict: plt.scatter( data_dict[key]['fraction_to_poi'], data_dict[key]['fraction_from_poi'], color = 'b') if data_dict[key]['poi'] == True: plt.scatter(data_dict[key]['fraction_to_poi'], data_dict[key]['fraction_from_poi'], color='r', marker="*") plt.ylabel('fraction of emails of this person to POI') plt.xlabel('fraction of emails of this person from POI') plt.show() return fraction data_dict = getData() submit_dict = {} for name in data_dict: data_point = data_dict[name] print from_poi_to_this_person = data_point["from_poi_to_this_person"] to_messages = data_point["to_messages"] fraction_from_poi = computeFraction( from_poi_to_this_person, to_messages ) print fraction_from_poi data_point["fraction_from_poi"] = fraction_from_poi from_this_person_to_poi = data_point["from_this_person_to_poi"] from_messages = data_point["from_messages"] fraction_to_poi = computeFraction( from_this_person_to_poi, from_messages ) print fraction_to_poi submit_dict[name]={"from_poi_to_this_person":fraction_from_poi, "from_this_person_to_poi":fraction_to_poi} data_point["fraction_to_poi"] = fraction_to_poi ##################### def submitDict(): return submit_dict
def __init__(self, size, batch, dataset = getData(), train=0.7, val=0.0, test=0.3): self.dataset = dataset train = int(train*size) valid = int(val*size) self.size = size self.batch_size = int(batch) self.train = self.dataset[0:train] # self.valid = self.dataset[t:t+v] self.test = self.dataset[train:]
def __init__(self, size, batch, train=0.7, val=0.1, test=0.2): self.dataset = getData() t = int(train*size) v = int(val*size) self.size = size self.batch_size = int(batch) self.train = self.dataset[0:t] self.valid = self.dataset[t:t+v] self.test = self.dataset[t+v:]
def data_collection(): while(1): hum, temp, soil, ldr = getData(ser) time_read = datetime.now() q.put(hum) q.put(temp) q.put(soil) q.put(ldr) q.put(time_read.strftime("%H:%M"))
def load_n_save(config_path): ''' loads the data from the config_path using the functions from get_data.py file and saves to the data folder ''' config = read_params(config_path) df = getData(config_path) # a liitle preprocessing for changing the name of the columns # because the names have spaces between them which can cause issues # in the future up_cols = [col.replace(" ","_") for col in df.columns] raw_path = config["load_data"]["raw_dataset"] df.to_csv(raw_path, sep=",", index=False, header=up_cols)
### you fill in this code, so that it returns either ### the fraction of all messages to this person that come from POIs ### or ### the fraction of all messages from this person that are sent to POIs ### the same code can be used to compute either quantity ### beware of "NaN" when there is no known email address (and so ### no filled email features), and integer division! ### in case of poi_messages or all_messages having "NaN" value, return 0. fraction = 0. return fraction data_dict = getData() submit_dict = {} for name in data_dict: data_point = data_dict[name] print from_poi_to_this_person = data_point["from_poi_to_this_person"] to_messages = data_point["to_messages"] fraction_from_poi = computeFraction(from_poi_to_this_person, to_messages) print fraction_from_poi data_point["fraction_from_poi"] = fraction_from_poi from_this_person_to_poi = data_point["from_this_person_to_poi"] from_messages = data_point["from_messages"]
# -*- coding: utf-8 -*- """ Created on Sat Oct 24 15:26:55 2015 @author: Animesh, Laura, Minal, Shweta and Vasavi """ import get_ids import get_data d = {} url = "../data/SearchForAtlantaZillow.xml" API_key = 'X1-ZWz1a2hjdxu77v_305s0' id_list = get_ids.getIds(url) d = get_data.getData(id_list, API_key,d) print d
# no filled email features), and integer division! # in case of poi_messages or all_messages having "NaN" value, return 0. fraction = 0. if all_messages == 'NaN': return fraction if poi_messages == 'NaN': poi_messages = 0 fraction = float(poi_messages)/float(all_messages) return fraction data_dict = getData() submit_dict = {} for name in data_dict: data_point = data_dict[name] print from_poi_to_this_person = data_point["from_poi_to_this_person"] to_messages = data_point["to_messages"] fraction_from_poi = computeFraction( from_poi_to_this_person, to_messages ) print fraction_from_poi data_point["fraction_from_poi"] = fraction_from_poi from_this_person_to_poi = data_point["from_this_person_to_poi"] from_messages = data_point["to_messages"]
from math import pi, sqrt, sin, cos import scipy.constants as constants from scipy import optimize import get_data INTEGRITY_CONSTANT = 0 LIGHT_SPEED = constants.c GM = 3.98603 * (10**14) OMEGA = 7.3 / (10**5) # data = get_data.getData('irkutsk', 'etalon2') vv data = get_data.getData('mendeleevo2', 'etalon2') # vv # data = get_data.getData('irkutsk', 'cryosat2') x # data = get_data.getData('mendeleevo2', 'cryosat2') x # data = get_data.getData('irkutsk', 'swarm_A') x # data = get_data.getData('mendeleevo2', 'swarm_A') x # data = get_data.getData('irkutsk', 'KOMPSAT_5') x # data = get_data.getData('mendeleevo2', 'KOMPSAT_5') x # data = get_data.getData('irkutsk', 'QZS_1') v # data = get_data.getData('mendeleevo2', 'QZS_1') ll # data = get_data.getData('irkutsk', 'RadioAstron') v # data = get_data.getData('mendeleevo2', 'RadioAstron') vv fi_0 = data['longitude'] # fi_0 fi = 0 # fi r_0 = 6371302 + data['radial_distance'] # R_0 a = data['a'] # a e = data['eccentricity'] # e theta_0 = data['latitude'] # theta_0 theta = data['inclination'] # theta
from sklearn import svm, tree from sklearn.svm import LinearSVC, SVC from sklearn.ensemble import RandomForestClassifier import tensorflow as tf from sklearn.datasets import load_digits from sklearn.model_selection import train_test_split, validation_curve, learning_curve from sklearn.neural_network import MLPClassifier from sklearn.preprocessing import LabelBinarizer, StandardScaler import numpy as np from sklearn.linear_model import Perceptron import matplotlib.pyplot as plt from get_data import getData [X, y] = getData() # scaler = StandardScaler() scaler.fit(X) x_train_std = scaler.transform(X) # X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, shuffle=True) M1 = [1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1] M2 = [1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1] M3 = [0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1] M4 = [1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0] M5 = [0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1] Mystery = [M1, M2, M3, M4, M5] ppn = Perceptron(n_iter=40, eta0=0.1, random_state=0)
from sklearn import linear_model from get_data import getData features, labels = getData() clf = linear_model.Lasso(alpha=0.1) clf.fit(features)
sw.draw_chart_values(sw.comp_sym_spy.iloc[:10].spy_stock_comp) # day week month statistics # elif itype == "ds": # pass # uptrend sectors in each month elif itype == "tspy": sw.ss.sectors_uptrend_by_month() # find bottom of the stocks when spy is going down elif itype == "fb": sw.find_bottom() # download ernings elif itype == "de": gd = getData() gd.get_earnings() # download prices elif itype == "dd": gd = getData() gd.start_download(interval, utc.localize( datetime.now() - timedelta(days=365))) # show earning dates elif itype == "se": sw.show_earning_dates(sw.db.time_from, sw.db.time_to, symbols = sw.symbols) # show stats for specific stocks elif itype == "ss": sw.show_fin_earn_price(sym = sw.symbols)