Skip to content

Instantly share code, notes, and snippets.

View temmyzeus's full-sized avatar
🎯
Focusing

Temiloluwa Awoyele temmyzeus

🎯
Focusing
View GitHub Profile
# Creating a class with the name `Item`
class Item:
...
...
class Item:
# this is a class variable
percent_off = 0.1
def __init__(self, item_name, price):
self.item_name = item_name
self.price = price
@classmethod
def from_list(cls, item_lst):
class Item:
# this is a class variable
percent_off = 0.1
def __init__(self, item_name, price):
self.item_name = item_name
self.price = price
# a class method taking in 1 argument
@classmethod
class Item:
def __init__(self, item_name, price):
self.item_name = item_name
self.price = price
# this is an instance method taking in no arguments
def buy_item(self):
print(f'{self.item_name.title()} is being bought for ${self.price}')
# Accessing Class / Static Variables from the class itself
print(Item.percent_off)
# Accessing Class / Static Variables from the instance object
print(burger.percent_off)
class Item:
# this is a class variable
percent_off = 0.1
def __init__(self, item_name, price):
self.item_name = item_name
self.price = price
burger = Item(item_name='burger', price=2.55)
# print out the percent_off
class Item:
# parameters for instance variables are defined in the __init__ function
def __init__(self, item_name, price):
self.item_name = item_name
self.price = price
# instance variables are defined when the class is instantiated or created
burger = Item(item_name='burger', price=2.55)
@temmyzeus
temmyzeus / news_jsont_to_csv.py
Created October 26, 2021 11:09
News Classifier Datasets from json to csv format => https://www.kaggle.com/rmisra/news-category-dataset
"""Convert Data from .json to .csv easily readable by Pandas"""
import os
import sys
import ast
from pathlib import Path
from typing import List, Dict
import pandas as pd
# Set directory to file directory so other paths are easily relative to it without error
import os
import argparse
# Create the parser
my_parser = argparse.ArgumentParser(prog='myls',
usage='%(prog)s [options] path',
description='List the content of a folder')
args = my_parser.parse_args()
@temmyzeus
temmyzeus / log_loss.py
Created October 26, 2020 02:43
Implementation of Log Loss from scratch and comparism to Scikit-Learn Log Loss Metric
import numpy as np
from sklearn.metrics import log_loss
np.random.seed(0)#Setting our seed to make our results reproducable
#Creating a sample target and a sample predictions probabilites
targets = np.random.randint(low=0,high=2,size=100)
probs = np.random.rand(100)
#Using Scikit-Learn Log Loss Metric
sklearn_loss = log_loss(