Your task is to build a model^(1) which can predict y-coordinate.
You can pass tests if predicted y-coordinates are inside error margin.

You will receive train set which should be used to build a model. 
After you build a model tests will call function ```predict``` and pass x to it. 

Error is going to be calculated with RMSE.



Blocked libraries: sklearn, pandas, tensorflow, numpy, scipy

Explanation
[1] A mining model is created by applying an algorithm to data, but it is more than an algorithm or a metadata container: it is a set of data, statistics, and patterns that can be applied to new data to generate predictions and make inferences about relationships.

Difficulty: introductory

Starter code:

def __init__(self, train_set):
	

Solutions:
class Datamining:
    a = 0
    b = 0

    def __init__(self, train_set):
        sx = sy = sxx = sxy = 0
        n = len(train_set)
        for i in range(n):
            sx += train_set[i][0]
            sy += train_set[i][1]
            sxx += train_set[i][0]**2
            sxy += train_set[i][0]*train_set[i][1]
        self.b = (n*sxy-sx*sy)/(n*sxx-sx**2)
        self.a = (sy-self.b*sx)/n

    def predict(self, x):
        return self.a + self.b*x



class Datamining:

    def __init__(self, train_set):
        n = len(train_set)
        X = [i[0] for i in train_set]
        Y = [i[1] for i in train_set]
        x_mean = sum(X) / n
        y_mean = sum(Y) / n
        numerator = 0
        denominator = 0
        for i in range(n):
            numerator += (X[i] - x_mean) * (Y[i] - y_mean)
            denominator += (X[i] - x_mean) ** 2
        self.b1 = numerator / denominator
        self.b0 = y_mean - (self.b1 * x_mean)
  
    def predict(self, x):
        return x*self.b1 + self.b0


from operator import itemgetter

class Datamining:
    def __init__(self, train_set):
        X, Y = map(lambda L: sum(L)/len(train_set), zip(*train_set))
        COV = sum((x-X)*(y-Y) for x,y in train_set)
        VAR = sum((x-X)**2 for x in map(itemgetter(0), train_set))
        self.A = COV / VAR
        self.B = Y - self.A * X

    def predict(self, x):
        return self.A * x + self.B

class Datamining:

    def __init__(self, train_set):
        n = len(train_set)
        M1 = [i[0] for i in train_set]
        M2 = [i[1] for i in train_set]
        x_mean = sum(M1) / n
        y_mean = sum(M2) / n
        numerator = 0
        denominator = 0
        for i in range(n):
            numerator += (M1[i] - x_mean) * (M2[i] - y_mean)
            denominator += (M1[i] - x_mean) ** 2
        self.n = numerator / denominator
        self.o = y_mean - (self.n * x_mean)
  
    def predict(self, x):
        return x*self.n + self.o

class Datamining:
    
    def __init__(self, train_set):
        x_mean = lambda train_set: sum( [i[0] for i in train_set] ) / len( [i[0] for i in train_set] )
        y_mean = lambda train_set: sum( [i[1] for i in train_set] ) / len( [i[1] for i in train_set] )
        f = lambda x_mean, y_mean, train_set: sum( (x - x_mean) * (y - y_mean) for x, y in train_set )
        g = lambda x_mean, train_set: sum( (x - x_mean) ** 2 for x in [i[0] for i in train_set] )
        self.a = f( x_mean(train_set), y_mean (train_set), train_set ) / g ( x_mean (train_set), train_set )
        self.b = y_mean(train_set) - self.a * x_mean(train_set)
        
    def predict(self, x): return x * self.a + self.b

class Datamining:
    def __init__(self, train_set):
        x_mean=sum([i[0] for i in train_set])/len([i[0] for i in train_set])
        y_mean=sum([i[1] for i in train_set])/len([i[1] for i in train_set])
        self.a = (sum((x - x_mean) * (y - y_mean) for x, y in train_set)) / \
                 (sum((x - x_mean) ** 2 for x in [i[0] for i in train_set]))
        self.b = y_mean - self.a * x_mean
    def predict(self, x): return x * self.a + self.b

class Datamining:

    def __init__(self, train_set):
        a_x,a_y=[],[]
        for x,y in train_set:
            a_x.append(x)
            a_y.append(y)
        mean_x=sum(a_x)/len(a_x)
        mean_y=sum(a_y)/len(a_y)
        cov=sum((x-mean_x)*(y-mean_y) for x,y in train_set)
        x_v=sum((x-mean_x)**2 for x in a_x)
        self.a=cov/x_v
        self.b=mean_y-self.a*mean_x

    def predict(self, x):
        return self.a*x+self.b

class Datamining:

    def __init__(self, ts):
        self.N = len(ts)        
        self.m = (self.N * sum(x*y for x, y in ts) - sum(x for x,_ in ts)*sum(y for _, y in ts)) / (self.N * sum(x**2 for x,_ in ts) - sum(x for x,_ in ts)**2)
        self.b = (sum(y for _,y in ts) - self.m * sum(x for x, _ in ts)) / (self.N)
                

    def predict(self, x):
        return self.m*x + self.b

class Datamining:

    def __init__(self, train_set):
        n = len(train_set)
        xbar = sum([s[0] for s in train_set]) / n
        ybar = sum([s[1] for s in train_set]) / n
        print(xbar, ybar)
        xe = [s[0] - xbar for s in train_set]
        ye = [s[1] - ybar for s in train_set]
        self.beta = sum(xe[i] * ye[i] for i in range(n)) / sum(xe[i] ** 2 for i in range(n))
        self.alpha = ybar - self.beta * xbar
        predict = [self.alpha + self.beta * s[0] for s in train_set]



    def predict(self, x):
        return self.alpha + self.beta * x

class Datamining:

    def __init__(self, train_set):
        total = len(train_set)
        x = []
        for i in train_set:
            x.append(i[0])
        y = []
        for i in train_set:
            y.append(i[1])
        xmean = sum(x)/total
        ymean = sum(y)/total
        a = 0
        b = 0
        for i in range(total):
            a += (x[i]-xmean) * (y[i] - ymean)
            b+= (x[i]-xmean)**2
        self.z = a/b
        self.y = ymean - (self.z*xmean)

    def predict(self, x):
        return x*self.z + self.y
        pass