Lecture 1: Introduction to Research โ [๐Lecture Notebooks] [
Lecture 2: Introduction to Python โ [๐Lecture Notebooks] [
Lecture 3: Introduction to NumPy โ [๐Lecture Notebooks] [
Lecture 4: Introduction to pandas โ [๐Lecture Notebooks] [
Lecture 5: Plotting Data โ [๐Lecture Notebooks] [[
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 time,imutils | |
import cv2 | |
from PIL import Image | |
import numpy as np | |
from twilio.rest import Client | |
import tkinter | |
from threading import Thread | |
cap = cv2.VideoCapture(0) | |
cap.set(3,640) # set Width |
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
def predict(ratings, similarity, type='user'): | |
if type == 'user': | |
mean_user_rating = ratings.mean(axis=1).reshape(-1,1) | |
#We use np.newaxis so that mean_user_rating has same format as ratings | |
ratings_diff = (ratings - mean_user_rating) | |
pred = mean_user_rating + similarity.dot(ratings_diff) / np.array([np.abs(similarity).sum(axis=1)]).T | |
elif type == 'item': |
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
r_cols = ['user_id', 'movie_id', 'rating', 'unix_timestamp'] | |
ratings_train = pd.read_csv('ml-100k/ua.base', sep='\t', names=r_cols, encoding='latin-1') | |
ratings_test = pd.read_csv('ml-100k/ua.test', sep='\t', names=r_cols, encoding='latin-1') | |
ratings_train.shape, ratings_test.shape |
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 pandas as pd | |
%matplotlib inline | |
import matplotlib | |
import matplotlib.pyplot as plt | |
import numpy as np | |
# pass in column names for each CSV as the column name is not given in the file and read them using pandas. | |
# You can check the column names from the readme file | |
#Reading users file: | |
u_cols = ['user_id', 'age', 'sex', 'occupation', 'zip_code'] |
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 sys | |
import jsonpickle | |
import os | |
searchQuery = 'brexit' # this is what we're searching for | |
maxTweets = 1000 # Some arbitrary large number | |
tweetsPerQry = 100 # this is the max the API permits | |
fName = 'tweets.txt' # We'll store the tweets in a text file. | |
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 tweepy | |
# Replace the API_KEY and API_SECRET with your application's key and secret. | |
auth = tweepy.AppAuthHandler(API_KEY, API_SECRET) | |
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=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
dataset ={'outlook':outlook,'temp':temp,'humidity':humidity,'windy':windy,'play':play} | |
df = pd.DataFrame(dataset,columns=['outlook','temp','humidity','windy','play']) |
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
outlook = 'overcast,overcast,overcast,overcast,rainy,rainy,rainy,rainy,rainy,sunny,sunny,sunny,sunny,sunny'.split(',') | |
temp = 'hot,cool,mild,hot,mild,cool,cool,mild,mild,hot,hot,mild,cool,mild'.split(',') | |
humidity = 'high,normal,high,normal,high,normal,normal,normal,high,high,high,high,normal,normal'.split(',') | |
windy = 'FALSE,TRUE,TRUE,FALSE,FALSE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,FALSE,TRUE'.split(',') | |
play = 'yes,yes,yes,yes,yes,yes,no,yes,no,no,no,no,yes,yes'.split(',') |
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
##1. claculate entropy o the whole dataset | |
entropy_node = 0 #Initialize Entropy | |
values = df.play.unique() #Unique objects - 'Yes', 'No' | |
for value in values: | |
fraction = df.play.value_counts()[value]/len(df.play) | |
entropy_node += -fraction*np.log2(fraction) |
NewerOlder