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
import pandas as pd | |
import numpy as np | |
import itertool | |
from nltk import word_tokenize | |
from sklearn.feature_extraction.text import TfidfVectorizer | |
from sklearn.model_selection import train_test_split | |
from sklearn.naive_bayes import MultinomialNB | |
df = pd.read_csv('my_data_with_text.csv') | |
df.columns #id, text, category |
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
import time | |
import threading | |
class Elevator: | |
def __init__(self, control, timer=Timer(), eventlog=EventLog()): | |
self.control = control | |
self.timer = timer | |
self.eventlog = eventlog | |
#Python thinks it's a dict if you |
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
import time | |
class ElevatorButtonPanel: | |
def __init__(self, elevator): | |
self.elevator = elevator | |
# Logic of the elevator | |
def request_button_pressed(self, floor): | |
self.elevator.go_to_floor(floor) |
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
# metal.py | |
# | |
# METAL, by Dave Beazley | |
# dabeaz.com | |
# One of the main roles of a compiler is taking high-level programs | |
# such as what you might write in C or Python and reducing them to | |
# instructions that can execute on actual hardware. | |
# | |
# This file implements a very tiny CPU in the form of a Python |
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
# Top level function that interprets an entire program. It creates the | |
# initial environment that's used for storing variables. | |
def interpret_program(model): | |
# Make the initial environment (a dict). The environment is | |
# where you will create and store variables. | |
env = {} | |
for structure in model.statements: | |
interpret(structure, env) |
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
# Top level function that interprets an entire program. It creates the | |
# initial environment that's used for storing variables. | |
def interpret_program(model): | |
# Make the initial environment (a dict). The environment is | |
# where you will create and store variables. | |
env = {'constants':{}, 'variables':{}} | |
for structure in model.statements: | |
interpret(structure, env) |
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
class Negative: | |
def __init__(self, value): | |
self.value = value | |
def __repr__(self): | |
return f"Negative({self.value})" | |
class Integer: | |
''' | |
Example: 42 |
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
import numpy as np | |
import pandas as pd | |
import sklearn | |
import nltk | |
from sklearn.feature_extraction.text import TfidfVectorizer | |
class Content(): | |
_cached_data = None | |
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
from visualizations.models import Visualization | |
class InfectionRateVisualization(Visualization): | |
class Meta: | |
proxy = True | |
def from_data(csvfile): | |
department_instances = [] | |
infection_type = [] |
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
from __future__ import unicode_literals | |
from django.shortcuts import render | |
from models import Visualization | |
from exceptions import IncompleteDataException | |
from .forms import VisualizationForm | |
from django.contrib.auth.decorators import login_required | |
def _inject_visualization(name): | |
if name == "infection_rate_visualization": |
NewerOlder