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 pickle | |
import os.path | |
import requests | |
from googleapiclient.discovery import build | |
from google_auth_oauthlib.flow import InstalledAppFlow | |
from google.auth.transport.requests import Request | |
from email.mime.text import MIMEText | |
import base64 | |
# If modifying these scopes, delete the file token.pickle. |
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
# Reset environment | |
state = env.reset() | |
# Render it | |
env.render() | |
time.sleep(0.5) | |
done = False | |
while not done: | |
# Choose the action with the max expected reward i.e. max Q-value |
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 numpy as np | |
import gym | |
# Define the environment | |
env = gym.make("Taxi-v2").env | |
# Initialize the q-table with zero values | |
q_table = np.zeros([env.observation_space.n, env.action_space.n]) |
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
env.step(1) |
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 gym | |
env = gym.make("Taxi-v3").env | |
env.render() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
import requests | |
def convert_to_num(s): | |
if isinstance(s, int): | |
return s | |
elif 'K' in s: | |
return int(1000 * float(s.replace('K',''))) | |
else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from python_graphql_client import GraphqlClient | |
import time | |
client = GraphqlClient(endpoint="https://medium.com/_/graphql") | |
def get_posts(data, posts): | |
for post in data["data"]["topic"]["latestPosts"]["postPreviews"]: | |
title = "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from python_graphql_client import GraphqlClient | |
client = GraphqlClient(endpoint="https://medium.com/_/graphql") | |
query = "query TopicHandler($topicSlug: ID!, $feedPagingOptions: PagingOptions, $sidebarPagingOptions: PagingOptions) {\n topic(slug: $topicSlug) {\n canonicalSlug\n ...TopicScreen_topic\n __typename\n }\n}\n\nfragment PostListingItemFeed_postPreview on PostPreview {\n post {\n ...PostListingItemPreview_post\n ...PostListingItemByline_post\n ...PostListingItemImage_post\n ...PostPresentationTracker_post\n __typename\n }\n __typename\n}\n\nfragment PostListingItemPreview_post on Post {\n id\n mediumUrl\n title\n previewContent {\n subtitle\n isFullContent\n __typename\n }\n isPublished\n creator {\n id\n __typename\n }\n __typename\n}\n\nfragment PostListingItemByline_post on Post {\n id\n creator {\n id\n username\n name\n __typename\n }\n isLocked\n readingTime\n ...BookmarkButton_post\n firstPublishedAt\n updatedAt\n status |
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 ridge_regression(data, predictors, alpha=None): | |
# Fit the model | |
if alpha is not None and predictors is not None: | |
model = Ridge(alpha=alpha, normalize=True, max_iter=1e8) | |
else: | |
model = RidgeCV(alphas=np.linspace(1e-4, 1e-3, 1000), fit_intercept=True, normalize=True) | |
model.fit(data[predictors],data['y']) | |
y_pred = model.predict(data[predictors]) | |