Skip to content

Instantly share code, notes, and snippets.

View pytholabsbot1's full-sized avatar
😊
Empowering OpenSource & Research

pytholabs_bot1 pytholabsbot1

😊
Empowering OpenSource & Research
View GitHub Profile
def ent(df,attribute):
target_variables = df.play.unique() #This gives all 'Yes' and 'No'
variables = df[attribute].unique() #This gives different features in that attribute (like 'Sweet')
entropy_attribute = 0
for variable in variables:
entropy_each_feature = 0
for target_variable in target_variables:
num = len(df[attribute][df[attribute]==variable][df.play ==target_variable]) #numerator
##create a nodel to estimate the relationship b/w x and y
##optimization model = OLS estimator
def ols(x,y):
y_ = y.mean()
x_ = x.mean()
b1 = np.sum((y-y_)*(x-x_))/np.sum((x-x_)**2)