Skip to content

Instantly share code, notes, and snippets.

View ahmedazizkhelifi's full-sized avatar
🍉

KHELIFI Ahmed Aziz ahmedazizkhelifi

🍉
View GitHub Profile
from google.colab import files
uploaded = files.upload()
## test.csv(application/vnd.ms-excel) - 28629 bytes, last modified: 11/12/2019 - 100% done
## train.csv(application/vnd.ms-excel) - 61194 bytes, last modified: 11/12/2019 - 100% done
import io
train = pd.read_csv(io.BytesIO(uploaded['train.csv']))
test = pd.read_csv(io.BytesIO(uploaded['test.csv']))
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
class DecisionNode(Node):
def __init__(self,label,distr,threshold ,left = None,right = None):
Node.__init__(self,label,left,right)
self.threshold = threshold
self.distr = distr
def __str__(self):
L = self.linearize()
s = ""
for e in L:
s += "IF "
Blood Pressure Age Tachycardia Decision
110 50 1 0
119 36 0 0
82 72 0 1
81 70 0 1
56 50 1 1
class Node:
def __init__(self,val,leftNote = None, rightNode = None):
self.label = val
self.left = leftNote
self.right = rightNode
def isLeaf(self):
return self.left == None and self.right == None
def __str__(self):
if self.isLeaf():
return "Node({})".format(self.label)
def iterative_factorial(n):
f = 1
for i in range(2, n+1):
f *= i
return f
def recursive_factorial(n):
if n <= 1:
return 1
else:
return n*recursive_factorial(n-1)
def recursive_factorial(n):
return n*recursive_factorial(n-1)
# 1) conventional syntax:
dict1={}
for user in Users:
dict1.update({user['name']:user['salary']})
print (dict1) #>>> {'Ahmed': 1200, 'Aziz': 1800, 'Khelifi': 820}
# 2) Dict comprehesion:
dict2 = {user['name'] : user['salary'] for user in Users }
print(dict2) #>>> {'Ahmed': 1200, 'Aziz': 1800, 'Khelifi': 820}
# 1) conventional syntax:
dict1={}
for user in Users:
dict1.update({user['name']:user['salary']})
print (dict1) #>>> {'Ahmed': 1200, 'Aziz': 1800, 'Khelifi': 820}
# 2) Dict comprehesion:
dict2 = {user['name'] : user['salary'] for user in Users }
print(dict2) #>>> {'Ahmed': 1200, 'Aziz': 1800, 'Khelifi': 820}