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
# Creating a class with the name `Item` | |
class Item: | |
... | |
... |
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 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): |
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 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 |
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 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}') | |
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
# Accessing Class / Static Variables from the class itself | |
print(Item.percent_off) | |
# Accessing Class / Static Variables from the instance object | |
print(burger.percent_off) |
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 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 |
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 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) |
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
"""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 |
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 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() |
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 | |
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( |
NewerOlder