This file contains hidden or 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
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 |
This file contains hidden or 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
##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) |
NewerOlder