This file contains 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
b0, b1 = 0.0, 1.0 | |
lr = 0.001 | |
epochs = 10000 | |
error = [] | |
# run 10000 times | |
for epoch in range(epochs): | |
# initialize to 0 -> cost of epoch, Jb_0, Jb_1 | |
epoch_cost, cost_b0, cost_b1 = 0, 0, 0 |
This file contains 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
ratings_df = pd.DataFrame() | |
ratings_df['Mean_Rating'] = data.groupby('title')['rating'].mean().values | |
ratings_df['Num_Ratings'] = data.groupby('title')['rating'].count().values | |
fig, ax = plt.subplots(figsize=(14, 7)) | |
ax.spines['top'].set_visible(False) | |
ax.spines['right'].set_visible(False) | |
ax.set_title('Rating vs. Number of Ratings', fontsize=24, pad=20) | |
ax.set_xlabel('Rating', fontsize=16, labelpad=20) |
This file contains 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
data.sort_values(by='numRatings', ascending=False).drop_duplicates('movieId')[:10] |
This file contains 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
num_ratings = pd.DataFrame(data.groupby('movieId').count()['rating']).reset_index() | |
data = pd.merge(left=data, right=num_ratings, on='movieId') | |
data.rename(columns={'rating_x': 'rating', 'rating_y': 'numRatings'}, inplace=True) |
This file contains 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
values = defaultdict(list) | |
for ind, row in data.iterrows(): | |
for genre in row['genres'].split('|'): | |
values[genre].append(row['rating']) | |
genre_lst, rating_lst = [], [] | |
for key, item in values.items(): | |
if key not in [0, 1]: | |
genre_lst.append(key) |
This file contains 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
def make_bar_chart(dataset, attribute, bar_color='#3498db', edge_color='#2980b9', title='Title', xlab='X', ylab='Y', sort_index=False): | |
if sort_index == False: | |
xs = dataset[attribute].value_counts().index | |
ys = dataset[attribute].value_counts().values | |
else: | |
xs = dataset[attribute].value_counts().sort_index().index | |
ys = dataset[attribute].value_counts().sort_index().values | |
fig, ax = plt.subplots(figsize=(14, 7)) |
This file contains 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
genre_df = pd.DataFrame(data['genres'].str.split('|').tolist(), index=data['movieId']).stack() | |
genre_df = genre_df.reset_index([0, 'movieId']) | |
genre_df.columns = ['movieId', 'Genre'] |
This file contains 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
def make_histogram(dataset, attribute, bins=25, bar_color='#3498db', edge_color='#2980b9', title='Title', xlab='X', ylab='Y', sort_index=False): | |
if attribute == 'moviePubYear': | |
dataset = dataset[dataset['moviePubYear'] != 9999] | |
fig, ax = plt.subplots(figsize=(14, 7)) | |
ax.spines['top'].set_visible(False) | |
ax.spines['right'].set_visible(False) | |
ax.set_title(title, fontsize=24, pad=20) | |
ax.set_xlabel(xlab, fontsize=16, labelpad=20) | |
ax.set_ylabel(ylab, fontsize=16, labelpad=20) |
This file contains 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
years = [] | |
for title in data['title']: | |
year_subset = title[-5:-1] | |
try: years.append(int(year_subset)) | |
except: years.append(9999) | |
data['moviePubYear'] = years | |
print(len(data[data['moviePubYear'] == 9999])) |
This file contains 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
%matplotlib inline | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
from collections import defaultdict | |
# read CSVs | |
movies = pd.read_csv('data/movies.csv') | |
ratings = pd.read_csv('data/ratings.csv') |
NewerOlder