SYMBOL INDEX (968 symbols across 73 files) FILE: first-edition/code-python3/clustering.py class KMeans (line 6) | class KMeans: method __init__ (line 9) | def __init__(self, k): method classify (line 13) | def classify(self, input): method train (line 18) | def train(self, inputs): function squared_clustering_errors (line 40) | def squared_clustering_errors(inputs, k): function plot_squared_clustering_errors (line 50) | def plot_squared_clustering_errors(): function recolor_image (line 65) | def recolor_image(input_file, k=5): function is_leaf (line 87) | def is_leaf(cluster): function get_children (line 91) | def get_children(cluster): function get_values (line 99) | def get_values(cluster): function cluster_distance (line 109) | def cluster_distance(cluster1, cluster2, distance_agg=min): function get_merge_order (line 116) | def get_merge_order(cluster): function bottom_up_cluster (line 122) | def bottom_up_cluster(inputs, distance_agg=min): function generate_clusters (line 146) | def generate_clusters(base_cluster, num_clusters): FILE: first-edition/code-python3/databases.py class Table (line 4) | class Table: method __init__ (line 5) | def __init__(self, columns): method __repr__ (line 9) | def __repr__(self): method insert (line 13) | def insert(self, row_values): method update (line 19) | def update(self, updates, predicate): method delete (line 25) | def delete(self, predicate=lambda row: True): method select (line 30) | def select(self, keep_columns=None, additional_columns=None): method where (line 49) | def where(self, predicate=lambda row: True): method limit (line 55) | def limit(self, num_rows=None): method group_by (line 63) | def group_by(self, group_by_columns, aggregates, having=None): method order_by (line 83) | def order_by(self, order): method join (line 88) | def join(self, other_table, left_join=False): function name_len (line 155) | def name_len(row): return len(row["name"]) function min_user_id (line 164) | def min_user_id(rows): return min(row["user_id"] for row in rows) function first_letter_of_name (line 176) | def first_letter_of_name(row): function average_num_friends (line 179) | def average_num_friends(rows): function enough_friends (line 182) | def enough_friends(rows): function sum_user_ids (line 195) | def sum_user_ids(rows): return sum(row["user_id"] for row in rows) function count_interests (line 233) | def count_interests(rows): FILE: first-edition/code-python3/decision_trees.py function entropy (line 5) | def entropy(class_probabilities): function class_probabilities (line 9) | def class_probabilities(labels): function data_entropy (line 14) | def data_entropy(labeled_data): function partition_entropy (line 19) | def partition_entropy(subsets): function group_by (line 26) | def group_by(items, key_fn): function partition_by (line 35) | def partition_by(inputs, attribute): function partition_entropy_by (line 40) | def partition_entropy_by(inputs,attribute): function classify (line 45) | def classify(tree, input): function build_tree_id3 (line 63) | def build_tree_id3(inputs, split_candidates=None): function forest_classify (line 100) | def forest_classify(trees, input): FILE: first-edition/code-python3/getting_data.py function is_video (line 13) | def is_video(td): function book_info (line 20) | def book_info(td): function scrape (line 40) | def scrape(num_pages=31): function get_year (line 60) | def get_year(book): function plot_years (line 65) | def plot_years(plt, books): function call_twitter_search_api (line 108) | def call_twitter_search_api(): class MyStreamer (line 125) | class MyStreamer(TwythonStreamer): method on_success (line 129) | def on_success(self, data): method on_error (line 141) | def on_error(self, status_code, data): function call_twitter_streaming_api (line 145) | def call_twitter_streaming_api(): function process (line 155) | def process(date, symbol, price): FILE: first-edition/code-python3/gradient_descent.py function sum_of_squares (line 6) | def sum_of_squares(v): function difference_quotient (line 10) | def difference_quotient(f, x, h): function plot_estimated_derivative (line 13) | def plot_estimated_derivative(): function partial_difference_quotient (line 30) | def partial_difference_quotient(f, v, i, h): function estimate_gradient (line 38) | def estimate_gradient(f, v, h=0.00001): function step (line 42) | def step(v, direction, step_size): function sum_of_squares_gradient (line 47) | def sum_of_squares_gradient(v): function safe (line 50) | def safe(f): function minimize_batch (line 66) | def minimize_batch(target_fn, gradient_fn, theta_0, tolerance=0.000001): function negate (line 90) | def negate(f): function negate_all (line 94) | def negate_all(f): function maximize_batch (line 98) | def maximize_batch(target_fn, gradient_fn, theta_0, tolerance=0.000001): function in_random_order (line 108) | def in_random_order(data): function minimize_stochastic (line 115) | def minimize_stochastic(target_fn, gradient_fn, x, y, theta_0, alpha_0=0... function maximize_stochastic (line 145) | def maximize_stochastic(target_fn, gradient_fn, x, y, theta_0, alpha_0=0... FILE: first-edition/code-python3/hypothesis_and_inference.py function normal_approximation_to_binomial (line 4) | def normal_approximation_to_binomial(n, p): function normal_probability_above (line 20) | def normal_probability_above(lo, mu=0, sigma=1): function normal_probability_between (line 24) | def normal_probability_between(lo, hi, mu=0, sigma=1): function normal_probability_outside (line 28) | def normal_probability_outside(lo, hi, mu=0, sigma=1): function normal_upper_bound (line 38) | def normal_upper_bound(probability, mu=0, sigma=1): function normal_lower_bound (line 42) | def normal_lower_bound(probability, mu=0, sigma=1): function normal_two_sided_bounds (line 46) | def normal_two_sided_bounds(probability, mu=0, sigma=1): function two_sided_p_value (line 59) | def two_sided_p_value(x, mu=0, sigma=1): function count_extreme_values (line 67) | def count_extreme_values(): function run_experiment (line 86) | def run_experiment(): function reject_fairness (line 90) | def reject_fairness(experiment): function estimated_parameters (line 102) | def estimated_parameters(N, n): function a_b_test_statistic (line 107) | def a_b_test_statistic(N_A, n_A, N_B, n_B): function B (line 118) | def B(alpha, beta): function beta_pdf (line 122) | def beta_pdf(x, alpha, beta): FILE: first-edition/code-python3/introduction.py function number_of_friends (line 39) | def number_of_friends(user): function friends_of_friend_ids_bad (line 55) | def friends_of_friend_ids_bad(user): function not_the_same (line 63) | def not_the_same(user, other_user): function not_friends (line 67) | def not_friends(user, other_user): function friends_of_friend_ids (line 73) | def friends_of_friend_ids(user): function data_scientists_who_like (line 99) | def data_scientists_who_like(target_interest): function most_common_interests_with (line 118) | def most_common_interests_with(user_id): function make_chart_salaries_by_tenure (line 136) | def make_chart_salaries_by_tenure(): function tenure_bucket (line 156) | def tenure_bucket(tenure): function predict_paid_or_unpaid (line 179) | def predict_paid_or_unpaid(years_experience): FILE: first-edition/code-python3/linear_algebra.py function vector_add (line 12) | def vector_add(v, w): function vector_subtract (line 16) | def vector_subtract(v, w): function vector_sum (line 20) | def vector_sum(vectors): function scalar_multiply (line 23) | def scalar_multiply(c, v): function vector_mean (line 26) | def vector_mean(vectors): function dot (line 32) | def dot(v, w): function sum_of_squares (line 36) | def sum_of_squares(v): function magnitude (line 40) | def magnitude(v): function squared_distance (line 43) | def squared_distance(v, w): function distance (line 46) | def distance(v, w): function shape (line 53) | def shape(A): function get_row (line 58) | def get_row(A, i): function get_column (line 61) | def get_column(A, j): function make_matrix (line 64) | def make_matrix(num_rows, num_cols, entry_fn): function is_diagonal (line 70) | def is_diagonal(i, j): function matrix_add (line 94) | def matrix_add(A, B): function make_graph_dot_product_as_vector_projection (line 104) | def make_graph_dot_product_as_vector_projection(plt): FILE: first-edition/code-python3/logistic_regression.py function logistic (line 10) | def logistic(x): function logistic_prime (line 13) | def logistic_prime(x): function logistic_log_likelihood_i (line 16) | def logistic_log_likelihood_i(x_i, y_i, beta): function logistic_log_likelihood (line 22) | def logistic_log_likelihood(x, y, beta): function logistic_log_partial_ij (line 26) | def logistic_log_partial_ij(x_i, y_i, beta, j): function logistic_log_gradient_i (line 32) | def logistic_log_gradient_i(x_i, y_i, beta): function logistic_log_gradient (line 39) | def logistic_log_gradient(x, y, beta): FILE: first-edition/code-python3/machine_learning.py function split_data (line 8) | def split_data(data, prob): function train_test_split (line 15) | def train_test_split(x, y, test_pct): function accuracy (line 26) | def accuracy(tp, fp, fn, tn): function precision (line 31) | def precision(tp, fp, fn, tn): function recall (line 34) | def recall(tp, fp, fn, tn): function f1_score (line 37) | def f1_score(tp, fp, fn, tn): FILE: first-edition/code-python3/mapreduce.py function word_count_old (line 6) | def word_count_old(documents): function wc_mapper (line 12) | def wc_mapper(document): function wc_reducer (line 17) | def wc_reducer(word, counts): function word_count (line 21) | def word_count(documents): function map_reduce (line 35) | def map_reduce(inputs, mapper, reducer): function reduce_with (line 47) | def reduce_with(aggregation_fn, key, values): function values_reducer (line 51) | def values_reducer(aggregation_fn): function data_science_day_mapper (line 73) | def data_science_day_mapper(status_update): function words_per_user_mapper (line 83) | def words_per_user_mapper(status_update): function most_popular_word_reducer (line 88) | def most_popular_word_reducer(user, words_and_counts): function liker_mapper (line 104) | def liker_mapper(status_update): function matrix_multiply_mapper (line 118) | def matrix_multiply_mapper(m, element): function matrix_multiply_reducer (line 132) | def matrix_multiply_reducer(m, key, indexed_values): FILE: first-edition/code-python3/multiple_regression.py function predict (line 10) | def predict(x_i, beta): function error (line 13) | def error(x_i, y_i, beta): function squared_error (line 16) | def squared_error(x_i, y_i, beta): function squared_error_gradient (line 19) | def squared_error_gradient(x_i, y_i, beta): function estimate_beta (line 24) | def estimate_beta(x, y): function multiple_r_squared (line 32) | def multiple_r_squared(x, y, beta): function bootstrap_sample (line 37) | def bootstrap_sample(data): function bootstrap_statistic (line 41) | def bootstrap_statistic(data, stats_fn, num_samples): function estimate_sample_beta (line 46) | def estimate_sample_beta(sample): function p_value (line 50) | def p_value(beta_hat_j, sigma_hat_j): function ridge_penalty (line 62) | def ridge_penalty(beta, alpha): function squared_error_ridge (line 65) | def squared_error_ridge(x_i, y_i, beta, alpha): function ridge_penalty_gradient (line 69) | def ridge_penalty_gradient(beta, alpha): function squared_error_ridge_gradient (line 73) | def squared_error_ridge_gradient(x_i, y_i, beta, alpha): function estimate_beta_ridge (line 79) | def estimate_beta_ridge(x, y, alpha): function lasso_penalty (line 90) | def lasso_penalty(beta, alpha): FILE: first-edition/code-python3/naive_bayes.py function tokenize (line 5) | def tokenize(message): function count_words (line 11) | def count_words(training_set): function word_probabilities (line 19) | def word_probabilities(counts, total_spams, total_non_spams, k=0.5): function spam_probability (line 27) | def spam_probability(word_probs, message): class NaiveBayesClassifier (line 50) | class NaiveBayesClassifier: method __init__ (line 52) | def __init__(self, k=0.5): method train (line 56) | def train(self, training_set): method classify (line 71) | def classify(self, message): function get_subject_data (line 75) | def get_subject_data(path): function p_spam_given_word (line 94) | def p_spam_given_word(word_prob): function train_and_test_model (line 98) | def train_and_test_model(path): FILE: first-edition/code-python3/natural_language_processing.py function plot_resumes (line 6) | def plot_resumes(plt): function fix_unicode (line 32) | def fix_unicode(text): function get_document (line 35) | def get_document(): function generate_using_bigrams (line 53) | def generate_using_bigrams(transitions): function generate_using_trigrams (line 62) | def generate_using_trigrams(starts, trigram_transitions): function is_terminal (line 76) | def is_terminal(token): function expand (line 79) | def expand(grammar, tokens): function generate_sentence (line 97) | def generate_sentence(grammar): function roll_a_die (line 104) | def roll_a_die(): function direct_sample (line 107) | def direct_sample(): function random_y_given_x (line 112) | def random_y_given_x(x): function random_x_given_y (line 116) | def random_x_given_y(y): function gibbs_sample (line 126) | def gibbs_sample(num_iters=100): function compare_distributions (line 133) | def compare_distributions(num_samples=1000): function sample_from (line 144) | def sample_from(weights): function p_topic_given_document (line 185) | def p_topic_given_document(topic, d, alpha=0.1): function p_word_given_topic (line 192) | def p_word_given_topic(word, topic, beta=0.1): function topic_weight (line 199) | def topic_weight(d, word, k): function choose_new_topic (line 205) | def choose_new_topic(d, word): FILE: first-edition/code-python3/nearest_neighbors.py function raw_majority_vote (line 7) | def raw_majority_vote(labels): function majority_vote (line 12) | def majority_vote(labels): function knn_classify (line 26) | def knn_classify(k, labeled_points, new_point): function plot_state_borders (line 43) | def plot_state_borders(plt, color='0.8'): function plot_cities (line 46) | def plot_cities(): function classify_and_plot_grid (line 71) | def classify_and_plot_grid(k=1): function random_point (line 98) | def random_point(dim): function random_distances (line 101) | def random_distances(dim, num_pairs): FILE: first-edition/code-python3/network_analysis.py function shortest_paths_from (line 36) | def shortest_paths_from(from_user): function farness (line 102) | def farness(user): function matrix_product_entry (line 115) | def matrix_product_entry(A, B, i, j): function matrix_multiply (line 118) | def matrix_multiply(A, B): function vector_as_matrix (line 126) | def vector_as_matrix(v): function vector_from_matrix (line 130) | def vector_from_matrix(v_as_matrix): function matrix_operate (line 134) | def matrix_operate(A, v): function find_eigenvector (line 139) | def find_eigenvector(A, tolerance=0.00001): function entry_fn (line 156) | def entry_fn(i, j): function page_rank (line 187) | def page_rank(users, damping = 0.85, num_iters = 100): FILE: first-edition/code-python3/neural_networks.py function step_function (line 8) | def step_function(x): function perceptron_output (line 11) | def perceptron_output(weights, bias, x): function sigmoid (line 15) | def sigmoid(t): function neuron_output (line 18) | def neuron_output(weights, inputs): function feed_forward (line 21) | def feed_forward(neural_network, input_vector): function backpropagate (line 39) | def backpropagate(network, input_vector, target): function patch (line 62) | def patch(x, y, hatch, color): function show_weights (line 69) | def show_weights(neuron_idx): function make_digit (line 154) | def make_digit(raw_digit): function predict (line 185) | def predict(input): FILE: first-edition/code-python3/plot_state_borders.py function plot_state_borders (line 22) | def plot_state_borders(color='0.8'): FILE: first-edition/code-python3/probability.py function random_kid (line 4) | def random_kid(): function uniform_pdf (line 7) | def uniform_pdf(x): function uniform_cdf (line 10) | def uniform_cdf(x): function normal_pdf (line 16) | def normal_pdf(x, mu=0, sigma=1): function plot_normal_pdfs (line 20) | def plot_normal_pdfs(plt): function normal_cdf (line 29) | def normal_cdf(x, mu=0,sigma=1): function plot_normal_cdfs (line 32) | def plot_normal_cdfs(plt): function inverse_normal_cdf (line 41) | def inverse_normal_cdf(p, mu=0, sigma=1, tolerance=0.00001): function bernoulli_trial (line 64) | def bernoulli_trial(p): function binomial (line 67) | def binomial(p, n): function make_hist (line 70) | def make_hist(p, n, num_points): FILE: first-edition/code-python3/recommender_systems.py function most_popular_new_interests (line 27) | def most_popular_new_interests(user_interests, max_results=5): function cosine_similarity (line 37) | def cosine_similarity(v, w): function make_user_interest_vector (line 44) | def make_user_interest_vector(user_interests): function most_similar_users_to (line 56) | def most_similar_users_to(user_id): function user_based_suggestions (line 67) | def user_based_suggestions(user_id, include_current_interests=False): function most_similar_interests_to (line 99) | def most_similar_interests_to(interest_id): function item_based_suggestions (line 108) | def item_based_suggestions(user_id, include_current_interests=False): FILE: first-edition/code-python3/simple_linear_regression.py function predict (line 7) | def predict(alpha, beta, x_i): function error (line 10) | def error(alpha, beta, x_i, y_i): function sum_of_squared_errors (line 13) | def sum_of_squared_errors(alpha, beta, x, y): function least_squares_fit (line 17) | def least_squares_fit(x,y): function total_sum_of_squares (line 24) | def total_sum_of_squares(y): function r_squared (line 28) | def r_squared(alpha, beta, x, y): function squared_error (line 35) | def squared_error(x_i, y_i, theta): function squared_error_gradient (line 39) | def squared_error_gradient(x_i, y_i, theta): FILE: first-edition/code-python3/stats.py function make_friend_counts_histogram (line 7) | def make_friend_counts_histogram(plt): function mean (line 29) | def mean(x): function median (line 32) | def median(v): function quantile (line 47) | def quantile(x, p): function mode (line 52) | def mode(x): function data_range (line 60) | def data_range(x): function de_mean (line 63) | def de_mean(x): function variance (line 68) | def variance(x): function standard_deviation (line 74) | def standard_deviation(x): function interquartile_range (line 77) | def interquartile_range(x): function covariance (line 88) | def covariance(x, y): function correlation (line 92) | def correlation(x, y): FILE: first-edition/code-python3/visualizing_data.py function make_chart_simple_line_chart (line 4) | def make_chart_simple_line_chart(): function make_chart_simple_bar_chart (line 20) | def make_chart_simple_bar_chart(): function make_chart_histogram (line 39) | def make_chart_histogram(): function make_chart_misleading_y_axis (line 55) | def make_chart_misleading_y_axis(mislead=True): function make_chart_several_line_charts (line 77) | def make_chart_several_line_charts(): function make_chart_scatter_plot (line 99) | def make_chart_scatter_plot(): function make_chart_scatterplot_axes (line 119) | def make_chart_scatterplot_axes(equal_axes=False): function make_chart_pie_chart (line 136) | def make_chart_pie_chart(): FILE: first-edition/code-python3/working_with_data.py function bucketize (line 12) | def bucketize(point, bucket_size): function make_histogram (line 16) | def make_histogram(points, bucket_size): function plot_histogram (line 20) | def plot_histogram(points, bucket_size, title=""): function compare_two_distributions (line 26) | def compare_two_distributions(): function random_normal (line 37) | def random_normal(): function scatter (line 46) | def scatter(): function correlation_matrix (line 54) | def correlation_matrix(data): function make_scatterplot_matrix (line 65) | def make_scatterplot_matrix(): function parse_row (line 109) | def parse_row(input_row, parsers): function parse_rows_with (line 115) | def parse_rows_with(reader, parsers): function try_or_none (line 120) | def try_or_none(f): function parse_row (line 128) | def parse_row(input_row, parsers): function try_parse_field (line 132) | def try_parse_field(field_name, value, parser_dict): function parse_dict (line 140) | def parse_dict(input_dict, parser_dict): function picker (line 150) | def picker(field_name): function pluck (line 154) | def pluck(field_name, rows): function group_by (line 158) | def group_by(grouper, rows, value_transform=None): function percent_price_change (line 169) | def percent_price_change(yesterday, today): function day_over_day_changes (line 172) | def day_over_day_changes(grouped_rows): function scale (line 187) | def scale(data_matrix): function rescale (line 195) | def rescale(data_matrix): function de_mean_matrix (line 316) | def de_mean_matrix(A): function direction (line 323) | def direction(w): function directional_variance_i (line 327) | def directional_variance_i(x_i, w): function directional_variance (line 331) | def directional_variance(X, w): function directional_variance_gradient_i (line 335) | def directional_variance_gradient_i(x_i, w): function directional_variance_gradient (line 341) | def directional_variance_gradient(X, w): function first_principal_component (line 344) | def first_principal_component(X): function first_principal_component_sgd (line 352) | def first_principal_component_sgd(X): function project (line 360) | def project(v, w): function remove_projection_from_vector (line 365) | def remove_projection_from_vector(v, w): function remove_projection (line 369) | def remove_projection(X, w): function principal_component_analysis (line 374) | def principal_component_analysis(X, num_components): function transform_vector (line 383) | def transform_vector(v, components): function transform (line 386) | def transform(X, components): function combine_pct_changes (line 445) | def combine_pct_changes(pct_change1, pct_change2): function overall_change (line 448) | def overall_change(changes): FILE: first-edition/code/clustering.py class KMeans (line 7) | class KMeans: method __init__ (line 10) | def __init__(self, k): method classify (line 14) | def classify(self, input): method train (line 19) | def train(self, inputs): function squared_clustering_errors (line 41) | def squared_clustering_errors(inputs, k): function plot_squared_clustering_errors (line 51) | def plot_squared_clustering_errors(plt): function recolor_image (line 66) | def recolor_image(input_file, k=5): function is_leaf (line 88) | def is_leaf(cluster): function get_children (line 92) | def get_children(cluster): function get_values (line 100) | def get_values(cluster): function cluster_distance (line 110) | def cluster_distance(cluster1, cluster2, distance_agg=min): function get_merge_order (line 117) | def get_merge_order(cluster): function bottom_up_cluster (line 123) | def bottom_up_cluster(inputs, distance_agg=min): function generate_clusters (line 147) | def generate_clusters(base_cluster, num_clusters): FILE: first-edition/code/databases.py class Table (line 5) | class Table: method __init__ (line 6) | def __init__(self, columns): method __repr__ (line 10) | def __repr__(self): method insert (line 14) | def insert(self, row_values): method update (line 20) | def update(self, updates, predicate): method delete (line 26) | def delete(self, predicate=lambda row: True): method select (line 31) | def select(self, keep_columns=None, additional_columns=None): method where (line 50) | def where(self, predicate=lambda row: True): method limit (line 56) | def limit(self, num_rows=None): method group_by (line 64) | def group_by(self, group_by_columns, aggregates, having=None): method order_by (line 84) | def order_by(self, order): method join (line 89) | def join(self, other_table, left_join=False): function name_len (line 156) | def name_len(row): return len(row["name"]) function min_user_id (line 165) | def min_user_id(rows): return min(row["user_id"] for row in rows) function first_letter_of_name (line 177) | def first_letter_of_name(row): function average_num_friends (line 180) | def average_num_friends(rows): function enough_friends (line 183) | def enough_friends(rows): function sum_user_ids (line 196) | def sum_user_ids(rows): return sum(row["user_id"] for row in rows) function count_interests (line 234) | def count_interests(rows): FILE: first-edition/code/decision_trees.py function entropy (line 6) | def entropy(class_probabilities): function class_probabilities (line 10) | def class_probabilities(labels): function data_entropy (line 15) | def data_entropy(labeled_data): function partition_entropy (line 20) | def partition_entropy(subsets): function group_by (line 27) | def group_by(items, key_fn): function partition_by (line 36) | def partition_by(inputs, attribute): function partition_entropy_by (line 41) | def partition_entropy_by(inputs,attribute): function classify (line 46) | def classify(tree, input): function build_tree_id3 (line 64) | def build_tree_id3(inputs, split_candidates=None): function forest_classify (line 101) | def forest_classify(trees, input): FILE: first-edition/code/getting_data.py function is_video (line 14) | def is_video(td): function book_info (line 21) | def book_info(td): function scrape (line 41) | def scrape(num_pages=31): function get_year (line 61) | def get_year(book): function plot_years (line 66) | def plot_years(plt, books): function call_twitter_search_api (line 109) | def call_twitter_search_api(): class MyStreamer (line 126) | class MyStreamer(TwythonStreamer): method on_success (line 130) | def on_success(self, data): method on_error (line 142) | def on_error(self, status_code, data): function call_twitter_streaming_api (line 146) | def call_twitter_streaming_api(): function process (line 156) | def process(date, symbol, price): FILE: first-edition/code/gradient_descent.py function sum_of_squares (line 6) | def sum_of_squares(v): function difference_quotient (line 10) | def difference_quotient(f, x, h): function plot_estimated_derivative (line 13) | def plot_estimated_derivative(): function partial_difference_quotient (line 30) | def partial_difference_quotient(f, v, i, h): function estimate_gradient (line 38) | def estimate_gradient(f, v, h=0.00001): function step (line 42) | def step(v, direction, step_size): function sum_of_squares_gradient (line 47) | def sum_of_squares_gradient(v): function safe (line 50) | def safe(f): function minimize_batch (line 66) | def minimize_batch(target_fn, gradient_fn, theta_0, tolerance=0.000001): function negate (line 90) | def negate(f): function negate_all (line 94) | def negate_all(f): function maximize_batch (line 98) | def maximize_batch(target_fn, gradient_fn, theta_0, tolerance=0.000001): function in_random_order (line 108) | def in_random_order(data): function minimize_stochastic (line 115) | def minimize_stochastic(target_fn, gradient_fn, x, y, theta_0, alpha_0=0... function maximize_stochastic (line 145) | def maximize_stochastic(target_fn, gradient_fn, x, y, theta_0, alpha_0=0... FILE: first-edition/code/hypothesis_and_inference.py function normal_approximation_to_binomial (line 5) | def normal_approximation_to_binomial(n, p): function normal_probability_above (line 21) | def normal_probability_above(lo, mu=0, sigma=1): function normal_probability_between (line 25) | def normal_probability_between(lo, hi, mu=0, sigma=1): function normal_probability_outside (line 29) | def normal_probability_outside(lo, hi, mu=0, sigma=1): function normal_upper_bound (line 39) | def normal_upper_bound(probability, mu=0, sigma=1): function normal_lower_bound (line 43) | def normal_lower_bound(probability, mu=0, sigma=1): function normal_two_sided_bounds (line 47) | def normal_two_sided_bounds(probability, mu=0, sigma=1): function two_sided_p_value (line 60) | def two_sided_p_value(x, mu=0, sigma=1): function count_extreme_values (line 68) | def count_extreme_values(): function run_experiment (line 87) | def run_experiment(): function reject_fairness (line 91) | def reject_fairness(experiment): function estimated_parameters (line 103) | def estimated_parameters(N, n): function a_b_test_statistic (line 108) | def a_b_test_statistic(N_A, n_A, N_B, n_B): function B (line 119) | def B(alpha, beta): function beta_pdf (line 123) | def beta_pdf(x, alpha, beta): FILE: first-edition/code/introduction.py function number_of_friends (line 41) | def number_of_friends(user): function friends_of_friend_ids_bad (line 57) | def friends_of_friend_ids_bad(user): function not_the_same (line 65) | def not_the_same(user, other_user): function not_friends (line 69) | def not_friends(user, other_user): function friends_of_friend_ids (line 75) | def friends_of_friend_ids(user): function data_scientists_who_like (line 101) | def data_scientists_who_like(target_interest): function most_common_interests_with (line 120) | def most_common_interests_with(user_id): function make_chart_salaries_by_tenure (line 138) | def make_chart_salaries_by_tenure(): function tenure_bucket (line 158) | def tenure_bucket(tenure): function predict_paid_or_unpaid (line 181) | def predict_paid_or_unpaid(years_experience): FILE: first-edition/code/linear_algebra.py function vector_add (line 13) | def vector_add(v, w): function vector_subtract (line 17) | def vector_subtract(v, w): function vector_sum (line 21) | def vector_sum(vectors): function scalar_multiply (line 24) | def scalar_multiply(c, v): function vector_mean (line 28) | def vector_mean(vectors): function dot (line 34) | def dot(v, w): function sum_of_squares (line 38) | def sum_of_squares(v): function magnitude (line 42) | def magnitude(v): function squared_distance (line 45) | def squared_distance(v, w): function distance (line 48) | def distance(v, w): function shape (line 55) | def shape(A): function get_row (line 60) | def get_row(A, i): function get_column (line 63) | def get_column(A, j): function make_matrix (line 66) | def make_matrix(num_rows, num_cols, entry_fn): function is_diagonal (line 72) | def is_diagonal(i, j): function matrix_add (line 96) | def matrix_add(A, B): function make_graph_dot_product_as_vector_projection (line 106) | def make_graph_dot_product_as_vector_projection(plt): FILE: first-edition/code/logistic_regression.py function logistic (line 11) | def logistic(x): function logistic_prime (line 14) | def logistic_prime(x): function logistic_log_likelihood_i (line 17) | def logistic_log_likelihood_i(x_i, y_i, beta): function logistic_log_likelihood (line 23) | def logistic_log_likelihood(x, y, beta): function logistic_log_partial_ij (line 27) | def logistic_log_partial_ij(x_i, y_i, beta, j): function logistic_log_gradient_i (line 33) | def logistic_log_gradient_i(x_i, y_i, beta): function logistic_log_gradient (line 40) | def logistic_log_gradient(x, y, beta): FILE: first-edition/code/machine_learning.py function split_data (line 9) | def split_data(data, prob): function train_test_split (line 16) | def train_test_split(x, y, test_pct): function accuracy (line 27) | def accuracy(tp, fp, fn, tn): function precision (line 32) | def precision(tp, fp, fn, tn): function recall (line 35) | def recall(tp, fp, fn, tn): function f1_score (line 38) | def f1_score(tp, fp, fn, tn): FILE: first-edition/code/mapreduce.py function word_count_old (line 7) | def word_count_old(documents): function wc_mapper (line 13) | def wc_mapper(document): function wc_reducer (line 18) | def wc_reducer(word, counts): function word_count (line 22) | def word_count(documents): function map_reduce (line 36) | def map_reduce(inputs, mapper, reducer): function reduce_with (line 48) | def reduce_with(aggregation_fn, key, values): function values_reducer (line 52) | def values_reducer(aggregation_fn): function data_science_day_mapper (line 74) | def data_science_day_mapper(status_update): function words_per_user_mapper (line 84) | def words_per_user_mapper(status_update): function most_popular_word_reducer (line 89) | def most_popular_word_reducer(user, words_and_counts): function liker_mapper (line 105) | def liker_mapper(status_update): function matrix_multiply_mapper (line 119) | def matrix_multiply_mapper(m, element): function matrix_multiply_reducer (line 133) | def matrix_multiply_reducer(m, key, indexed_values): FILE: first-edition/code/multiple_regression.py function predict (line 12) | def predict(x_i, beta): function error (line 15) | def error(x_i, y_i, beta): function squared_error (line 18) | def squared_error(x_i, y_i, beta): function squared_error_gradient (line 21) | def squared_error_gradient(x_i, y_i, beta): function estimate_beta (line 26) | def estimate_beta(x, y): function multiple_r_squared (line 34) | def multiple_r_squared(x, y, beta): function bootstrap_sample (line 39) | def bootstrap_sample(data): function bootstrap_statistic (line 43) | def bootstrap_statistic(data, stats_fn, num_samples): function estimate_sample_beta (line 48) | def estimate_sample_beta(sample): function p_value (line 52) | def p_value(beta_hat_j, sigma_hat_j): function ridge_penalty (line 64) | def ridge_penalty(beta, alpha): function squared_error_ridge (line 67) | def squared_error_ridge(x_i, y_i, beta, alpha): function ridge_penalty_gradient (line 71) | def ridge_penalty_gradient(beta, alpha): function squared_error_ridge_gradient (line 75) | def squared_error_ridge_gradient(x_i, y_i, beta, alpha): function estimate_beta_ridge (line 81) | def estimate_beta_ridge(x, y, alpha): function lasso_penalty (line 92) | def lasso_penalty(beta, alpha): FILE: first-edition/code/naive_bayes.py function tokenize (line 6) | def tokenize(message): function count_words (line 12) | def count_words(training_set): function word_probabilities (line 20) | def word_probabilities(counts, total_spams, total_non_spams, k=0.5): function spam_probability (line 28) | def spam_probability(word_probs, message): class NaiveBayesClassifier (line 51) | class NaiveBayesClassifier: method __init__ (line 53) | def __init__(self, k=0.5): method train (line 57) | def train(self, training_set): method classify (line 72) | def classify(self, message): function get_subject_data (line 76) | def get_subject_data(path): function p_spam_given_word (line 95) | def p_spam_given_word(word_prob): function train_and_test_model (line 99) | def train_and_test_model(path): FILE: first-edition/code/natural_language_processing.py function plot_resumes (line 7) | def plot_resumes(plt): function fix_unicode (line 33) | def fix_unicode(text): function get_document (line 36) | def get_document(): function generate_using_bigrams (line 54) | def generate_using_bigrams(transitions): function generate_using_trigrams (line 63) | def generate_using_trigrams(starts, trigram_transitions): function is_terminal (line 77) | def is_terminal(token): function expand (line 80) | def expand(grammar, tokens): function generate_sentence (line 98) | def generate_sentence(grammar): function roll_a_die (line 105) | def roll_a_die(): function direct_sample (line 108) | def direct_sample(): function random_y_given_x (line 113) | def random_y_given_x(x): function random_x_given_y (line 117) | def random_x_given_y(y): function gibbs_sample (line 127) | def gibbs_sample(num_iters=100): function compare_distributions (line 134) | def compare_distributions(num_samples=1000): function sample_from (line 145) | def sample_from(weights): function p_topic_given_document (line 186) | def p_topic_given_document(topic, d, alpha=0.1): function p_word_given_topic (line 193) | def p_word_given_topic(word, topic, beta=0.1): function topic_weight (line 200) | def topic_weight(d, word, k): function choose_new_topic (line 206) | def choose_new_topic(d, word): FILE: first-edition/code/nearest_neighbors.py function raw_majority_vote (line 8) | def raw_majority_vote(labels): function majority_vote (line 13) | def majority_vote(labels): function knn_classify (line 27) | def knn_classify(k, labeled_points, new_point): function plot_state_borders (line 44) | def plot_state_borders(plt, color='0.8'): function plot_cities (line 47) | def plot_cities(): function classify_and_plot_grid (line 72) | def classify_and_plot_grid(k=1): function random_point (line 99) | def random_point(dim): function random_distances (line 102) | def random_distances(dim, num_pairs): FILE: first-edition/code/network_analysis.py function shortest_paths_from (line 37) | def shortest_paths_from(from_user): function farness (line 103) | def farness(user): function matrix_product_entry (line 116) | def matrix_product_entry(A, B, i, j): function matrix_multiply (line 119) | def matrix_multiply(A, B): function vector_as_matrix (line 127) | def vector_as_matrix(v): function vector_from_matrix (line 131) | def vector_from_matrix(v_as_matrix): function matrix_operate (line 135) | def matrix_operate(A, v): function find_eigenvector (line 140) | def find_eigenvector(A, tolerance=0.00001): function entry_fn (line 157) | def entry_fn(i, j): function page_rank (line 188) | def page_rank(users, damping = 0.85, num_iters = 100): FILE: first-edition/code/neural_networks.py function step_function (line 9) | def step_function(x): function perceptron_output (line 12) | def perceptron_output(weights, bias, x): function sigmoid (line 16) | def sigmoid(t): function neuron_output (line 19) | def neuron_output(weights, inputs): function feed_forward (line 22) | def feed_forward(neural_network, input_vector): function backpropagate (line 40) | def backpropagate(network, input_vector, target): function patch (line 63) | def patch(x, y, hatch, color): function show_weights (line 70) | def show_weights(neuron_idx): function make_digit (line 155) | def make_digit(raw_digit): function predict (line 186) | def predict(input): FILE: first-edition/code/plot_state_borders.py function plot_state_borders (line 21) | def plot_state_borders(plt, color='0.8'): FILE: first-edition/code/probability.py function random_kid (line 5) | def random_kid(): function uniform_pdf (line 8) | def uniform_pdf(x): function uniform_cdf (line 11) | def uniform_cdf(x): function normal_pdf (line 17) | def normal_pdf(x, mu=0, sigma=1): function plot_normal_pdfs (line 21) | def plot_normal_pdfs(plt): function normal_cdf (line 30) | def normal_cdf(x, mu=0,sigma=1): function plot_normal_cdfs (line 33) | def plot_normal_cdfs(plt): function inverse_normal_cdf (line 42) | def inverse_normal_cdf(p, mu=0, sigma=1, tolerance=0.00001): function bernoulli_trial (line 65) | def bernoulli_trial(p): function binomial (line 68) | def binomial(p, n): function make_hist (line 71) | def make_hist(p, n, num_points): FILE: first-edition/code/recommender_systems.py function most_popular_new_interests (line 28) | def most_popular_new_interests(user_interests, max_results=5): function cosine_similarity (line 38) | def cosine_similarity(v, w): function make_user_interest_vector (line 45) | def make_user_interest_vector(user_interests): function most_similar_users_to (line 57) | def most_similar_users_to(user_id): function user_based_suggestions (line 68) | def user_based_suggestions(user_id, include_current_interests=False): function most_similar_interests_to (line 100) | def most_similar_interests_to(interest_id): function item_based_suggestions (line 109) | def item_based_suggestions(user_id, include_current_interests=False): FILE: first-edition/code/simple_linear_regression.py function predict (line 8) | def predict(alpha, beta, x_i): function error (line 11) | def error(alpha, beta, x_i, y_i): function sum_of_squared_errors (line 14) | def sum_of_squared_errors(alpha, beta, x, y): function least_squares_fit (line 18) | def least_squares_fit(x,y): function total_sum_of_squares (line 25) | def total_sum_of_squares(y): function r_squared (line 29) | def r_squared(alpha, beta, x, y): function squared_error (line 36) | def squared_error(x_i, y_i, theta): function squared_error_gradient (line 40) | def squared_error_gradient(x_i, y_i, theta): FILE: first-edition/code/statistics.py function make_friend_counts_histogram (line 8) | def make_friend_counts_histogram(plt): function mean (line 30) | def mean(x): function median (line 33) | def median(v): function quantile (line 48) | def quantile(x, p): function mode (line 53) | def mode(x): function data_range (line 61) | def data_range(x): function de_mean (line 64) | def de_mean(x): function variance (line 69) | def variance(x): function standard_deviation (line 75) | def standard_deviation(x): function interquartile_range (line 78) | def interquartile_range(x): function covariance (line 89) | def covariance(x, y): function correlation (line 93) | def correlation(x, y): FILE: first-edition/code/visualizing_data.py function make_chart_simple_line_chart (line 4) | def make_chart_simple_line_chart(plt): function make_chart_simple_bar_chart (line 20) | def make_chart_simple_bar_chart(plt): function make_chart_histogram (line 39) | def make_chart_histogram(plt): function make_chart_misleading_y_axis (line 55) | def make_chart_misleading_y_axis(plt, mislead=True): function make_chart_several_line_charts (line 77) | def make_chart_several_line_charts(plt): function make_chart_scatter_plot (line 99) | def make_chart_scatter_plot(plt): function make_chart_scatterplot_axes (line 119) | def make_chart_scatterplot_axes(plt, equal_axes=False): function make_chart_pie_chart (line 136) | def make_chart_pie_chart(plt): FILE: first-edition/code/working_with_data.py function bucketize (line 13) | def bucketize(point, bucket_size): function make_histogram (line 17) | def make_histogram(points, bucket_size): function plot_histogram (line 21) | def plot_histogram(points, bucket_size, title=""): function compare_two_distributions (line 27) | def compare_two_distributions(): function random_normal (line 38) | def random_normal(): function scatter (line 47) | def scatter(): function correlation_matrix (line 55) | def correlation_matrix(data): function make_scatterplot_matrix (line 66) | def make_scatterplot_matrix(): function parse_row (line 110) | def parse_row(input_row, parsers): function parse_rows_with (line 116) | def parse_rows_with(reader, parsers): function try_or_none (line 121) | def try_or_none(f): function parse_row (line 129) | def parse_row(input_row, parsers): function try_parse_field (line 133) | def try_parse_field(field_name, value, parser_dict): function parse_dict (line 141) | def parse_dict(input_dict, parser_dict): function picker (line 151) | def picker(field_name): function pluck (line 155) | def pluck(field_name, rows): function group_by (line 159) | def group_by(grouper, rows, value_transform=None): function percent_price_change (line 170) | def percent_price_change(yesterday, today): function day_over_day_changes (line 173) | def day_over_day_changes(grouped_rows): function scale (line 188) | def scale(data_matrix): function rescale (line 196) | def rescale(data_matrix): function de_mean_matrix (line 317) | def de_mean_matrix(A): function direction (line 324) | def direction(w): function directional_variance_i (line 328) | def directional_variance_i(x_i, w): function directional_variance (line 332) | def directional_variance(X, w): function directional_variance_gradient_i (line 336) | def directional_variance_gradient_i(x_i, w): function directional_variance_gradient (line 342) | def directional_variance_gradient(X, w): function first_principal_component (line 345) | def first_principal_component(X): function first_principal_component_sgd (line 353) | def first_principal_component_sgd(X): function project (line 361) | def project(v, w): function remove_projection_from_vector (line 366) | def remove_projection_from_vector(v, w): function remove_projection (line 370) | def remove_projection(X, w): function principal_component_analysis (line 375) | def principal_component_analysis(X, num_components): function transform_vector (line 384) | def transform_vector(v, components): function transform (line 387) | def transform(X, components): function combine_pct_changes (line 446) | def combine_pct_changes(pct_change1, pct_change2): function overall_change (line 449) | def overall_change(changes): FILE: scratch/clustering.py function num_differences (line 3) | def num_differences(v1: Vector, v2: Vector) -> int: function cluster_means (line 13) | def cluster_means(k: int, class KMeans (line 30) | class KMeans: method __init__ (line 31) | def __init__(self, k: int) -> None: method classify (line 35) | def classify(self, input: Vector) -> int: method train (line 40) | def train(self, inputs: List[Vector]) -> None: class Leaf (line 62) | class Leaf(NamedTuple): class Merged (line 68) | class Merged(NamedTuple): function get_values (line 76) | def get_values(cluster: Cluster) -> List[Vector]: function cluster_distance (line 89) | def cluster_distance(cluster1: Cluster, function get_merge_order (line 100) | def get_merge_order(cluster: Cluster) -> float: function get_children (line 108) | def get_children(cluster: Cluster): function bottom_up_cluster (line 114) | def bottom_up_cluster(inputs: List[Vector], function generate_clusters (line 142) | def generate_clusters(base_cluster: Cluster, function main (line 160) | def main(): FILE: scratch/crash_course_in_python.py function double (line 49) | def double(x): function apply_to_one (line 56) | def apply_to_one(f): function another_double (line 73) | def another_double(x): function my_print (line 77) | def my_print(message = "my default message"): function full_name (line 83) | def full_name(first = "What's-his-name", last = "Something"): function sum_and_product (line 207) | def sum_and_product(x, y): function some_function_that_returns_a_string (line 393) | def some_function_that_returns_a_string(): function smallest_item (line 465) | def smallest_item(xs): function smallest_item (line 471) | def smallest_item(xs): class CountingClicker (line 475) | class CountingClicker: method __init__ (line 478) | def __init__(self, count = 0): method __repr__ (line 481) | def __repr__(self): method click (line 484) | def click(self, num_times = 1): method read (line 488) | def read(self): method reset (line 491) | def reset(self): class NoResetClicker (line 503) | class NoResetClicker(CountingClicker): method reset (line 507) | def reset(self): function generate_range (line 517) | def generate_range(n): function natural_numbers (line 526) | def natural_numbers(): function add (line 620) | def add(a, b): return a + b function doubler (line 629) | def doubler(f): function f1 (line 637) | def f1(x): function f2 (line 644) | def f2(x, y): function magic (line 653) | def magic(*args, **kwargs): function other_way_magic (line 663) | def other_way_magic(x, y, z): function doubler_correct (line 670) | def doubler_correct(f): function add (line 680) | def add(a, b): function add (line 692) | def add(a: int, b: int) -> int: function dot_product (line 704) | def dot_product(x, y): ... function dot_product (line 707) | def dot_product(x: Vector, y: Vector) -> float: ... function secretly_ugly_function (line 711) | def secretly_ugly_function(value, operation): ... function ugly_function (line 713) | def ugly_function(value: int, operation: Union[str, int, float, bool]) -... function total (line 716) | def total(xs: list) -> float: function total (line 721) | def total(xs: List[float]) -> float: function twice (line 758) | def twice(repeater: Callable[[str, int], str], s: str) -> str: function comma_repeater (line 761) | def comma_repeater(s: str, n: int) -> str: function total (line 770) | def total(xs: Numbers) -> Number: FILE: scratch/databases.py class Table (line 14) | class Table: method __init__ (line 15) | def __init__(self, columns: List[str], types: List[type]) -> None: method col2type (line 22) | def col2type(self, col: str) -> type: method insert (line 26) | def insert(self, values: list) -> None: method __getitem__ (line 39) | def __getitem__(self, idx: int) -> Row: method __iter__ (line 42) | def __iter__(self) -> Iterator[Row]: method __len__ (line 45) | def __len__(self) -> int: method __repr__ (line 48) | def __repr__(self): method update (line 54) | def update(self, method delete (line 72) | def delete(self, predicate: WhereClause = lambda row: True) -> None: method select (line 76) | def select(self, method where (line 106) | def where(self, predicate: WhereClause = lambda row: True) -> 'Table': method limit (line 115) | def limit(self, num_rows: int) -> 'Table': method group_by (line 125) | def group_by(self, method order_by (line 153) | def order_by(self, order: Callable[[Row], Any]) -> 'Table': method join (line 158) | def join(self, other_table: 'Table', left_join: bool = False) -> 'Table': function main (line 191) | def main(): FILE: scratch/decision_trees.py function entropy (line 4) | def entropy(class_probabilities: List[float]) -> float: function class_probabilities (line 17) | def class_probabilities(labels: List[Any]) -> List[float]: function data_entropy (line 22) | def data_entropy(labels: List[Any]) -> float: function partition_entropy (line 29) | def partition_entropy(subsets: List[List[Any]]) -> float: class Candidate (line 38) | class Candidate(NamedTuple): function partition_by (line 67) | def partition_by(inputs: List[T], attribute: str) -> Dict[Any, List[T]]: function partition_entropy_by (line 75) | def partition_entropy_by(inputs: List[Any], class Leaf (line 104) | class Leaf(NamedTuple): class Split (line 107) | class Split(NamedTuple): function classify (line 126) | def classify(tree: DecisionTree, input: Any) -> Any: function build_tree_id3 (line 144) | def build_tree_id3(inputs: List[Any], FILE: scratch/deep_learning.py function shape (line 5) | def shape(tensor: Tensor) -> List[int]: function is_1d (line 15) | def is_1d(tensor: Tensor) -> bool: function tensor_sum (line 25) | def tensor_sum(tensor: Tensor) -> float: function tensor_apply (line 38) | def tensor_apply(f: Callable[[float], float], tensor: Tensor) -> Tensor: function zeros_like (line 48) | def zeros_like(tensor: Tensor) -> Tensor: function tensor_combine (line 54) | def tensor_combine(f: Callable[[float, float], float], class Layer (line 70) | class Layer: method forward (line 76) | def forward(self, input): method backward (line 84) | def backward(self, gradient): method params (line 92) | def params(self) -> Iterable[Tensor]: method grads (line 100) | def grads(self) -> Iterable[Tensor]: class Sigmoid (line 108) | class Sigmoid(Layer): method forward (line 109) | def forward(self, input: Tensor) -> Tensor: method backward (line 117) | def backward(self, gradient: Tensor) -> Tensor: function random_uniform (line 126) | def random_uniform(*dims: int) -> Tensor: function random_normal (line 132) | def random_normal(*dims: int, function random_tensor (line 145) | def random_tensor(*dims: int, init: str = 'normal') -> Tensor: class Linear (line 158) | class Linear(Layer): method __init__ (line 159) | def __init__(self, input_dim: int, output_dim: int, init: str = 'xavie... method forward (line 173) | def forward(self, input: Tensor) -> Tensor: method backward (line 181) | def backward(self, gradient: Tensor) -> Tensor: method params (line 198) | def params(self) -> Iterable[Tensor]: method grads (line 201) | def grads(self) -> Iterable[Tensor]: class Sequential (line 206) | class Sequential(Layer): method __init__ (line 212) | def __init__(self, layers: List[Layer]) -> None: method forward (line 215) | def forward(self, input): method backward (line 221) | def backward(self, gradient): method params (line 227) | def params(self) -> Iterable[Tensor]: method grads (line 231) | def grads(self) -> Iterable[Tensor]: class Loss (line 235) | class Loss: method loss (line 236) | def loss(self, predicted: Tensor, actual: Tensor) -> float: method gradient (line 240) | def gradient(self, predicted: Tensor, actual: Tensor) -> Tensor: class SSE (line 244) | class SSE(Loss): method loss (line 246) | def loss(self, predicted: Tensor, actual: Tensor) -> float: method gradient (line 256) | def gradient(self, predicted: Tensor, actual: Tensor) -> Tensor: class Optimizer (line 267) | class Optimizer: method step (line 272) | def step(self, layer: Layer) -> None: class GradientDescent (line 275) | class GradientDescent(Optimizer): method __init__ (line 276) | def __init__(self, learning_rate: float = 0.1) -> None: method step (line 279) | def step(self, layer: Layer) -> None: class Momentum (line 297) | class Momentum(Optimizer): method __init__ (line 298) | def __init__(self, method step (line 305) | def step(self, layer: Layer) -> None: function tanh (line 327) | def tanh(x: float) -> float: class Tanh (line 336) | class Tanh(Layer): method forward (line 337) | def forward(self, input: Tensor) -> Tensor: method backward (line 342) | def backward(self, gradient: Tensor) -> Tensor: class Relu (line 348) | class Relu(Layer): method forward (line 349) | def forward(self, input: Tensor) -> Tensor: method backward (line 353) | def backward(self, gradient: Tensor) -> Tensor: function softmax (line 358) | def softmax(tensor: Tensor) -> Tensor: class SoftmaxCrossEntropy (line 372) | class SoftmaxCrossEntropy(Loss): method loss (line 378) | def loss(self, predicted: Tensor, actual: Tensor) -> float: method gradient (line 391) | def gradient(self, predicted: Tensor, actual: Tensor) -> Tensor: class Dropout (line 399) | class Dropout(Layer): method __init__ (line 400) | def __init__(self, p: float) -> None: method forward (line 404) | def forward(self, input: Tensor) -> Tensor: method backward (line 417) | def backward(self, gradient: Tensor) -> Tensor: function one_hot_encode (line 428) | def one_hot_encode(i: int, num_labels: int = 10) -> List[float]: function save_weights (line 439) | def save_weights(model: Layer, filename: str) -> None: function load_weights (line 444) | def load_weights(model: Layer, filename: str) -> None: function main (line 456) | def main(): FILE: scratch/getting_data.py function get_domain (line 8) | def get_domain(email_address: str) -> str: function process (line 33) | def process(date: str, symbol: str, closing_price: float) -> None: function paragraph_mentions (line 136) | def paragraph_mentions(text: str, keyword: str) -> bool: function main (line 166) | def main(): FILE: scratch/gradient_descent.py function sum_of_squares (line 3) | def sum_of_squares(v: Vector) -> float: function difference_quotient (line 9) | def difference_quotient(f: Callable[[float], float], function square (line 14) | def square(x: float) -> float: function derivative (line 17) | def derivative(x: float) -> float: function estimate_gradient (line 20) | def estimate_gradient(f: Callable[[Vector], float], function gradient_step (line 29) | def gradient_step(v: Vector, gradient: Vector, step_size: float) -> Vector: function sum_of_squares_gradient (line 35) | def sum_of_squares_gradient(v: Vector) -> Vector: function linear_gradient (line 41) | def linear_gradient(x: float, y: float, theta: Vector) -> Vector: function minibatches (line 53) | def minibatches(dataset: List[T], function main (line 66) | def main(): FILE: scratch/inference.py function normal_approximation_to_binomial (line 4) | def normal_approximation_to_binomial(n: int, p: float) -> Tuple[float, f... function normal_probability_above (line 16) | def normal_probability_above(lo: float, function normal_probability_between (line 23) | def normal_probability_between(lo: float, function normal_probability_outside (line 31) | def normal_probability_outside(lo: float, function normal_upper_bound (line 40) | def normal_upper_bound(probability: float, function normal_lower_bound (line 46) | def normal_lower_bound(probability: float, function normal_two_sided_bounds (line 52) | def normal_two_sided_bounds(probability: float, function two_sided_p_value (line 106) | def two_sided_p_value(x: float, mu: float = 0, sigma: float = 1) -> float: function run_experiment (line 158) | def run_experiment() -> List[bool]: function reject_fairness (line 162) | def reject_fairness(experiment: List[bool]) -> bool: function estimated_parameters (line 175) | def estimated_parameters(N: int, n: int) -> Tuple[float, float]: function a_b_test_statistic (line 180) | def a_b_test_statistic(N_A: int, n_A: int, N_B: int, n_B: int) -> float: function B (line 198) | def B(alpha: float, beta: float) -> float: function beta_pdf (line 202) | def beta_pdf(x: float, alpha: float, beta: float) -> float: FILE: scratch/introduction.py function number_of_friends (line 32) | def number_of_friends(user): function foaf_ids_bad (line 67) | def foaf_ids_bad(user): function friends_of_friends (line 89) | def friends_of_friends(user): function data_scientists_who_like (line 122) | def data_scientists_who_like(target_interest): function most_common_interests_with (line 142) | def most_common_interests_with(user): function tenure_bucket (line 193) | def tenure_bucket(tenure): function predict_paid_or_unpaid (line 225) | def predict_paid_or_unpaid(years_experience): FILE: scratch/k_nearest_neighbors.py function raw_majority_vote (line 4) | def raw_majority_vote(labels: List[str]) -> str: function majority_vote (line 11) | def majority_vote(labels: List[str]) -> str: class LabeledPoint (line 30) | class LabeledPoint(NamedTuple): function knn_classify (line 34) | def knn_classify(k: int, function random_point (line 51) | def random_point(dim: int) -> Vector: function random_distances (line 54) | def random_distances(dim: int, num_pairs: int) -> List[float]: function main (line 58) | def main(): FILE: scratch/linear_algebra.py function add (line 14) | def add(v: Vector, w: Vector) -> Vector: function subtract (line 22) | def subtract(v: Vector, w: Vector) -> Vector: function vector_sum (line 30) | def vector_sum(vectors: List[Vector]) -> Vector: function scalar_multiply (line 45) | def scalar_multiply(c: float, v: Vector) -> Vector: function vector_mean (line 51) | def vector_mean(vectors: List[Vector]) -> Vector: function dot (line 58) | def dot(v: Vector, w: Vector) -> float: function sum_of_squares (line 66) | def sum_of_squares(v: Vector) -> float: function magnitude (line 74) | def magnitude(v: Vector) -> float: function squared_distance (line 80) | def squared_distance(v: Vector, w: Vector) -> float: function distance (line 84) | def distance(v: Vector, w: Vector) -> float: function distance (line 89) | def distance(v: Vector, w: Vector) -> float: # type: ignore function shape (line 104) | def shape(A: Matrix) -> Tuple[int, int]: function get_row (line 112) | def get_row(A: Matrix, i: int) -> Vector: function get_column (line 116) | def get_column(A: Matrix, j: int) -> Vector: function make_matrix (line 123) | def make_matrix(num_rows: int, function identity_matrix (line 134) | def identity_matrix(n: int) -> Matrix: FILE: scratch/logistic_regression.py function logistic (line 11) | def logistic(x: float) -> float: function logistic_prime (line 14) | def logistic_prime(x: float) -> float: function _negative_log_likelihood (line 21) | def _negative_log_likelihood(x: Vector, y: float, beta: Vector) -> float: function negative_log_likelihood (line 30) | def negative_log_likelihood(xs: List[Vector], function _negative_log_partial_j (line 38) | def _negative_log_partial_j(x: Vector, y: float, beta: Vector, j: int) -... function _negative_log_gradient (line 45) | def _negative_log_gradient(x: Vector, y: float, beta: Vector) -> Vector: function negative_log_gradient (line 52) | def negative_log_gradient(xs: List[Vector], function main (line 58) | def main(): FILE: scratch/machine_learning.py function split_data (line 5) | def split_data(data: List[X], prob: float) -> Tuple[List[X], List[X]]: function train_test_split (line 24) | def train_test_split(xs: List[X], function accuracy (line 48) | def accuracy(tp: int, fp: int, fn: int, tn: int) -> float: function precision (line 55) | def precision(tp: int, fp: int, fn: int, tn: int) -> float: function recall (line 60) | def recall(tp: int, fp: int, fn: int, tn: int) -> float: function f1_score (line 65) | def f1_score(tp: int, fp: int, fn: int, tn: int) -> float: FILE: scratch/mapreduce.py function tokenize (line 4) | def tokenize(document: str) -> List[str]: function word_count_old (line 8) | def word_count_old(documents: List[str]): function wc_mapper (line 16) | def wc_mapper(document: str) -> Iterator[Tuple[str, int]]: function wc_reducer (line 23) | def wc_reducer(word: str, function word_count (line 30) | def word_count(documents: List[str]) -> List[Tuple[str, int]]: function map_reduce (line 60) | def map_reduce(inputs: Iterable, function values_reducer (line 74) | def values_reducer(values_fn: Callable) -> Reducer: class Entry (line 93) | class Entry(NamedTuple): function matrix_multiply_mapper (line 99) | def matrix_multiply_mapper(num_rows_a: int, num_cols_b: int) -> Mapper: function matrix_multiply_reducer (line 118) | def matrix_multiply_reducer(key: Tuple[int, int], function main (line 141) | def main(): FILE: scratch/multiple_regression.py function predict (line 8) | def predict(x: Vector, beta: Vector) -> float: function error (line 19) | def error(x: Vector, y: float, beta: Vector) -> float: function squared_error (line 22) | def squared_error(x: Vector, y: float, beta: Vector) -> float: function sqerror_gradient (line 32) | def sqerror_gradient(x: Vector, y: float, beta: Vector) -> Vector: function least_squares_fit (line 44) | def least_squares_fit(xs: List[Vector], function multiple_r_squared (line 69) | def multiple_r_squared(xs: List[Vector], ys: Vector, beta: Vector) -> fl... function bootstrap_sample (line 79) | def bootstrap_sample(data: List[X]) -> List[X]: function bootstrap_statistic (line 83) | def bootstrap_statistic(data: List[X], function p_value (line 108) | def p_value(beta_hat_j: float, sigma_hat_j: float) -> float: function ridge_penalty (line 124) | def ridge_penalty(beta: Vector, alpha: float) -> float: function squared_error_ridge (line 127) | def squared_error_ridge(x: Vector, function ridge_penalty_gradient (line 136) | def ridge_penalty_gradient(beta: Vector, alpha: float) -> Vector: function sqerror_ridge_gradient (line 140) | def sqerror_ridge_gradient(x: Vector, function least_squares_fit_ridge (line 157) | def least_squares_fit_ridge(xs: List[Vector], function lasso_penalty (line 177) | def lasso_penalty(beta, alpha): function main (line 180) | def main(): FILE: scratch/naive_bayes.py function tokenize (line 4) | def tokenize(text: str) -> Set[str]: class Message (line 13) | class Message(NamedTuple): class NaiveBayesClassifier (line 21) | class NaiveBayesClassifier: method __init__ (line 22) | def __init__(self, k: float = 0.5) -> None: method train (line 30) | def train(self, messages: Iterable[Message]) -> None: method _probabilities (line 46) | def _probabilities(self, token: str) -> Tuple[float, float]: method predict (line 56) | def predict(self, text: str) -> float: function drop_final_s (line 115) | def drop_final_s(word): function main (line 118) | def main(): FILE: scratch/network_analysis.py class User (line 3) | class User(NamedTuple): function shortest_paths_from (line 32) | def shortest_paths_from(from_user_id: int, function farness (line 92) | def farness(user_id: int) -> float: function matrix_times_matrix (line 101) | def matrix_times_matrix(m1: Matrix, m2: Matrix) -> Matrix: function matrix_times_vector (line 114) | def matrix_times_vector(m: Matrix, v: Vector) -> Vector: function find_eigenvector (line 125) | def find_eigenvector(m: Matrix, function entry_fn (line 146) | def entry_fn(i: int, j: int): function page_rank (line 162) | def page_rank(users: List[User], FILE: scratch/neural_networks.py function step_function (line 3) | def step_function(x: float) -> float: function perceptron_output (line 6) | def perceptron_output(weights: Vector, bias: float, x: Vector) -> float: function sigmoid (line 35) | def sigmoid(t: float) -> float: function neuron_output (line 38) | def neuron_output(weights: Vector, inputs: Vector) -> float: function feed_forward (line 44) | def feed_forward(neural_network: List[List[Vector]], function sqerror_gradients (line 76) | def sqerror_gradients(network: List[List[Vector]], function fizz_buzz_encode (line 114) | def fizz_buzz_encode(x: int) -> Vector: function binary_encode (line 129) | def binary_encode(x: int) -> Vector: function argmax (line 145) | def argmax(xs: list) -> int: function main (line 153) | def main(): FILE: scratch/nlp.py function fix_unicode (line 16) | def fix_unicode(text: str) -> str: function generate_using_bigrams (line 42) | def generate_using_bigrams() -> str: function generate_using_trigrams (line 61) | def generate_using_trigrams() -> str: function is_terminal (line 92) | def is_terminal(token: str) -> bool: function expand (line 95) | def expand(grammar: Grammar, tokens: List[str]) -> List[str]: function generate_sentence (line 117) | def generate_sentence(grammar: Grammar) -> List[str]: function roll_a_die (line 123) | def roll_a_die() -> int: function direct_sample (line 126) | def direct_sample() -> Tuple[int, int]: function random_y_given_x (line 131) | def random_y_given_x(x: int) -> int: function random_x_given_y (line 135) | def random_x_given_y(y: int) -> int: function gibbs_sample (line 145) | def gibbs_sample(num_iters: int = 100) -> Tuple[int, int]: function compare_distributions (line 152) | def compare_distributions(num_samples: int = 1000) -> Dict[int, List[int]]: function sample_from (line 159) | def sample_from(weights: List[float]) -> int: function p_topic_given_document (line 213) | def p_topic_given_document(topic: int, d: int, alpha: float = 0.1) -> fl... function p_word_given_topic (line 221) | def p_word_given_topic(word: str, topic: int, beta: float = 0.1) -> float: function topic_weight (line 229) | def topic_weight(d: int, word: str, k: int) -> float: function choose_new_topic (line 236) | def choose_new_topic(d: int, word: str) -> int: function cosine_similarity (line 294) | def cosine_similarity(v1: Vector, v2: Vector) -> float: function make_sentence (line 307) | def make_sentence() -> str: class Vocabulary (line 325) | class Vocabulary: method __init__ (line 326) | def __init__(self, words: List[str] = None) -> None: method size (line 334) | def size(self) -> int: method add (line 338) | def add(self, word: str) -> None: method get_id (line 344) | def get_id(self, word: str) -> int: method get_word (line 348) | def get_word(self, word_id: int) -> str: method one_hot_encode (line 352) | def one_hot_encode(self, word: str) -> Tensor: function save_vocab (line 371) | def save_vocab(vocab: Vocabulary, filename: str) -> None: function load_vocab (line 375) | def load_vocab(filename: str) -> Vocabulary: class Embedding (line 386) | class Embedding(Layer): method __init__ (line 387) | def __init__(self, num_embeddings: int, embedding_dim: int) -> None: method forward (line 398) | def forward(self, input_id: int) -> Tensor: method backward (line 404) | def backward(self, gradient: Tensor) -> None: method params (line 414) | def params(self) -> Iterable[Tensor]: method grads (line 417) | def grads(self) -> Iterable[Tensor]: class TextEmbedding (line 420) | class TextEmbedding(Embedding): method __init__ (line 421) | def __init__(self, vocab: Vocabulary, embedding_dim: int) -> None: method __getitem__ (line 428) | def __getitem__(self, word: str) -> Tensor: method closest (line 435) | def closest(self, word: str, n: int = 5) -> List[Tuple[float, str]]: class SimpleRnn (line 448) | class SimpleRnn(Layer): method __init__ (line 450) | def __init__(self, input_dim: int, hidden_dim: int) -> None: method reset_hidden_state (line 460) | def reset_hidden_state(self) -> None: method forward (line 463) | def forward(self, input: Tensor) -> Tensor: method backward (line 475) | def backward(self, gradient: Tensor): method params (line 500) | def params(self) -> Iterable[Tensor]: method grads (line 503) | def grads(self) -> Iterable[Tensor]: function main (line 506) | def main(): FILE: scratch/nlp_advanced.py class EmbeddingOptimizer (line 3) | class EmbeddingOptimizer(Optimizer): method __init__ (line 8) | def __init__(self, learning_rate: float) -> None: method step (line 11) | def step(self, layer: Layer) -> None: FILE: scratch/probability.py function uniform_cdf (line 1) | def uniform_cdf(x: float) -> float: function normal_pdf (line 10) | def normal_pdf(x: float, mu: float = 0, sigma: float = 1) -> float: function normal_cdf (line 29) | def normal_cdf(x: float, mu: float = 0, sigma: float = 1) -> float: function inverse_normal_cdf (line 46) | def inverse_normal_cdf(p: float, function bernoulli_trial (line 71) | def bernoulli_trial(p: float) -> int: function binomial (line 75) | def binomial(n: int, p: float) -> int: function binomial_histogram (line 81) | def binomial_histogram(p: float, n: int, num_points: int) -> None: function main (line 103) | def main(): FILE: scratch/recommender_systems.py function most_popular_new_interests (line 27) | def most_popular_new_interests( function make_user_interest_vector (line 49) | def make_user_interest_vector(user_interests: List[str]) -> List[int]: function most_similar_users_to (line 72) | def most_similar_users_to(user_id: int) -> List[Tuple[int, float]]: function user_based_suggestions (line 93) | def user_based_suggestions(user_id: int, function most_similar_interests_to (line 133) | def most_similar_interests_to(interest_id: int): function item_based_suggestions (line 149) | def item_based_suggestions(user_id: int, function main (line 194) | def main(): FILE: scratch/simple_linear_regression.py function predict (line 1) | def predict(alpha: float, beta: float, x_i: float) -> float: function error (line 4) | def error(alpha: float, beta: float, x_i: float, y_i: float) -> float: function sum_of_sqerrors (line 13) | def sum_of_sqerrors(alpha: float, beta: float, x: Vector, y: Vector) -> ... function least_squares_fit (line 21) | def least_squares_fit(x: Vector, y: Vector) -> Tuple[float, float]: function total_sum_of_squares (line 44) | def total_sum_of_squares(y: Vector) -> float: function r_squared (line 48) | def r_squared(alpha: float, beta: float, x: Vector, y: Vector) -> float: function main (line 59) | def main(): FILE: scratch/statistics.py function mean (line 42) | def mean(xs: List[float]) -> float: function _median_odd (line 53) | def _median_odd(xs: List[float]) -> float: function _median_even (line 57) | def _median_even(xs: List[float]) -> float: function median (line 63) | def median(v: List[float]) -> float: function quantile (line 73) | def quantile(xs: List[float], p: float) -> float: function mode (line 83) | def mode(x: List[float]) -> List[float]: function data_range (line 93) | def data_range(xs: List[float]) -> float: function de_mean (line 100) | def de_mean(xs: List[float]) -> List[float]: function variance (line 105) | def variance(xs: List[float]) -> float: function standard_deviation (line 117) | def standard_deviation(xs: List[float]) -> float: function interquartile_range (line 123) | def interquartile_range(xs: List[float]) -> float: function covariance (line 136) | def covariance(xs: List[float], ys: List[float]) -> float: function correlation (line 144) | def correlation(xs: List[float], ys: List[float]) -> float: FILE: scratch/working_with_data.py function bucketize (line 7) | def bucketize(point: float, bucket_size: float) -> float: function make_histogram (line 11) | def make_histogram(points: List[float], bucket_size: float) -> Dict[floa... function plot_histogram (line 15) | def plot_histogram(points: List[float], bucket_size: float, title: str =... function random_normal (line 24) | def random_normal() -> float: function correlation_matrix (line 53) | def correlation_matrix(data: List[Vector]) -> Matrix: class StockPrice (line 84) | class StockPrice(NamedTuple): method is_high_tech (line 89) | def is_high_tech(self) -> bool: function parse_row (line 101) | def parse_row(row: List[str]) -> StockPrice: function try_parse_row (line 117) | def try_parse_row(row: List[str]) -> Optional[StockPrice]: function pct_change (line 189) | def pct_change(yesterday: StockPrice, today: StockPrice) -> float: class DailyChange (line 192) | class DailyChange(NamedTuple): function day_over_day_changes (line 197) | def day_over_day_changes(prices: List[StockPrice]) -> List[DailyChange]: function scale (line 250) | def scale(data: List[Vector]) -> Tuple[Vector, Vector]: function rescale (line 265) | def rescale(data: List[Vector]) -> List[Vector]: function de_mean (line 396) | def de_mean(data: List[Vector]) -> List[Vector]: function direction (line 403) | def direction(w: Vector) -> Vector: function directional_variance (line 409) | def directional_variance(data: List[Vector], w: Vector) -> float: function directional_variance_gradient (line 416) | def directional_variance_gradient(data: List[Vector], w: Vector) -> Vector: function first_principal_component (line 426) | def first_principal_component(data: List[Vector], function project (line 443) | def project(v: Vector, w: Vector) -> Vector: function remove_projection_from_vector (line 450) | def remove_projection_from_vector(v: Vector, w: Vector) -> Vector: function remove_projection (line 454) | def remove_projection(data: List[Vector], w: Vector) -> List[Vector]: function pca (line 457) | def pca(data: List[Vector], num_components: int) -> List[Vector]: function transform_vector (line 466) | def transform_vector(v: Vector, components: List[Vector]) -> Vector: function transform (line 469) | def transform(data: List[Vector], components: List[Vector]) -> List[Vect... function main (line 472) | def main():