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 Perceptron: | |
def __init__(self, num_inputs=2, weights=[1,1]): | |
self.num_inputs = num_inputs | |
self.weights = weights | |
def weighted_sum(self, inputs): | |
weighted_sum = 0 | |
for i in range(self.num_inputs): | |
weighted_sum += self.weights[i]*inputs[i] | |
return weighted_sum |
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 spam_data import training_spam_docs, training_doc_tokens, training_labels, training_docs | |
from sklearn.naive_bayes import MultinomialNB | |
from sklearn.feature_extraction.text import CountVectorizer | |
test_text = """ | |
Play around with the spam classifier! | |
""" | |
bow_vectorizer = CountVectorizer() |
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 spam_data import training_spam_docs, training_doc_tokens, training_labels, test_labels, test_spam_docs, training_docs, test_docs | |
from sklearn.naive_bayes import MultinomialNB | |
def create_features_dictionary(document_tokens): | |
features_dictionary = {} | |
index = 0 | |
for token in document_tokens: | |
if token not in features_dictionary: | |
features_dictionary[token] = index | |
index += 1 |
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 re | |
import random | |
class AlienBot: | |
def __init__(self): | |
self.name = None | |
self.alienbabble = { | |
'describe_planet_intent': r'.*(how|tell.*about|interest.*in).*your.*planet', | |
'answer_why_intent': r'why are you.*(here|asking me?\s?so?\s?many questions)\??', | |
'cubed_intent': r'can.*you.*cube.*number (\d+)?', |
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 re | |
import random | |
class AlienBot: | |
def __init__(self): | |
self.name = None | |
self.alienbabble = { | |
'describe_planet_intent': r'.*(how|tell.*about|interest.*in).*your.*planet', | |
'answer_why_intent': r'why are you.*(here|asking me?\s?so?\s?many questions)\??', | |
'cubed_intent': r'can.*you.*cube.*number (\d+)?', |
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
public class MadLibs { | |
/* | |
This program generates a mad libbed story. | |
Author: João | |
Date: 02/20/2024 | |
*/ | |
public static void main(String[] args){ | |
String name1 = "Carlos"; | |
String adjective1 = "good"; | |
String adjective2 = "bad"; |
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 nltk import pos_tag, RegexpParser | |
from tokenize_words import word_sentence_tokenize | |
from chunk_counters import np_chunk_counter, vp_chunk_counter | |
text = open("the_iliad.txt",encoding='utf-8').read().lower() | |
word_tokenized_text = word_sentence_tokenize(text) |
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
last_semester_gradebook = [["politics", 80], ["latin", 96], ["dance", 97], ["architecture", 65]] | |
# Your code below: | |
subjects = ['physics', 'calculus', 'poetry', 'history'] | |
grades = [98, 97, 85, 88] | |
gradebook = [[subjects[0], grades[0]], [subjects[1], grades[1]], [subjects[2], grades[2]], [subjects[3], grades[3]]] |
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
# Your code below: | |
first_names = ['Ainsley', 'Ben', 'Chani', 'Depak'] | |
preferred_size = ['Small', 'Large', 'Medium'] | |
preferred_size.append('Medium') | |
customer_data = [['Ainsley', 'Small', True], ['Ben', 'Large', False], ['Chani', 'Medium', True], ['Depak', 'Medium', False]] | |
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
# Define your functions | |
def coffee_bot(): | |
print('Welcome to the cafe!') | |
size = get_size() | |
print(size) | |
drink_type = get_drink_type() | |
print(drink_type) |