item = item_inverse_mapper[ind]
            print("item:%s, # of reviews:  %1d" % (item, len(X[:, ind].data)))

    elif question == "3":
        data = load_dataset("outliersData.pkl")
        X = data['X']
        y = data['y']

        # Fit least-squares estimator
        model = linear_model.LeastSquares()
        model.fit(X, y)
        print(model.w)

        utils.test_and_plot(model,
                            X,
                            y,
                            title="Least Squares",
                            filename="least_squares_outliers.pdf")

    elif question == "3.1":
        data = load_dataset("outliersData.pkl")
        X = data['X']
        y = data['y']

        mylist = []
        for i in range(0, 400):
            mylist.append(1)
        for i in range(0, 100):
            mylist.append(0.1)

        z = np.array(mylist)
Example #2
0
            print("The item {} has {} reviews".format(
                item_code, ratings['item'].value_counts().loc[item_code]))

    elif question == "3":
        data = load_dataset("outliersData.pkl")
        X = data['X']
        y = data['y']

        # Fit least-squares estimator
        model = linear_model.LeastSquares()
        model.fit(X, y)
        print(model.w)

        utils.test_and_plot(model,
                            X,
                            y,
                            title="Least Squares",
                            filename="least_squares_outliers.pdf")

    elif question == "3.1":
        data = load_dataset("outliersData.pkl")
        X = data['X']
        y = data['y']

        len = len(X)
        v = np.full(shape=len, fill_value=1)
        v[400:500] = 0.1
        V = np.diag(v)

        model = linear_model.WeightedLeastSquares()
        model.fit(X, y, V)
Example #3
0
        # YOUR CODE HERE FOR Q1.3

    elif question == "3":
        data = load_dataset("outliersData.pkl")
        X = data['X']
        y = data['y']

        # Fit least-squares estimator
        model = linear_model.LeastSquares()
        model.fit(X, y)
        print(model.w)

        utils.test_and_plot(model,
                            X,
                            y,
                            title="Least Squares",
                            filename="least_squares_outliers.pdf")

    elif question == "3.1":
        data = load_dataset("outliersData.pkl")
        X = data['X']
        y = data['y']

        # YOUR CODE HERE

    elif question == "3.3":
        # loads the data in the form of dictionary
        data = load_dataset("outliersData.pkl")
        X = data['X']
        y = data['y']
        print(
            "Number of reviews for the 5 recommendations based on cosine similarity:",
            item_record[nearest_index_3[0, 1:]])
    elif question == "3":
        data = load_dataset("outliersData.pkl")
        X = data['X']
        y = data['y']

        # Fit least-squares estimator
        model = linear_model.LeastSquares()
        model.fit(X, y)
        print(model.w)

        utils.test_and_plot(model,
                            X,
                            y,
                            title="Least Squares",
                            filename="least_squares_outliers.pdf")

    elif question == "3.1":
        data = load_dataset("outliersData.pkl")
        X = data['X']
        y = data['y']

        # YOUR CODE HERE
        z = np.zeros((500))
        z[0:100] = 1
        z[100:500] = 0.1
        model = linear_model.WeightedLeastSquares()
        model.fit(X, y, z)
        print(model.w)
        X_can_all = np.delete(X_all, [0, 1, 3], axis=1)
        X_can_all = np.reshape(X_can_all, (X_can_all.shape[0], 3))
        X_can_all = X_can_all.astype(float)

        X_can_cases = get_feature(X_all, 2)
        X_can_cases_14_100k = get_feature(X_all, 4)
        X_can_cases_100k = get_feature(X_all, 5)

        model = linear_model.LeastSquares()
        w = model.fit(X_can_cases, y_can)
        y_pred = model.predict(X_can_cases)
        utils.test_and_plot(model,
                            X_can_cases,
                            y_can,
                            Xtest=None,
                            ytest=None,
                            title="Canadian",
                            filename="Canadian_cases_feature.pdf")

        # model.fit(X_cases, y)
        # y_pred = model.predict(X_cases)

        # model.fit(X_cases, y)
        # y_pred = model.predict(X_cases)

        # y_pred = model.predict(X_test)
        # # y_pred = model.predict(X_cases)

        print("World: ")
Example #6
0
        y = utils.s2v(train_exp_dataset)
        Xtest = utils.s2v(ref_dataset[train_day:])
        ytest = utils.s2v(exp_dataset[train_day:])

        poly_par = 1
        if test_par != None:
            poly_par = int(test_par)
        model = linear_model.LeastSquaresPoly(p=poly_par)
        model.fit(X, y)
        titlename = exp_name + "_" + exp_ct_name + "_vs_" + ref_name + "_" + ref_ct_name + "_lag" + str(
            lag) + "_p" + str(poly_par)
        filename = "LRplot_" + titlename + ".pdf"
        utils.test_and_plot(model,
                            X,
                            y,
                            Xtest,
                            ytest,
                            title=titlename,
                            filename=filename)

    if question == "corr":

        dataset = read_dataset("phase1_training_data.csv")
        dataset = utils.get_all(dataset)
        n_ct, ct_key, ct_mapper, ct_inv_mapper, ct_ind = utils.make_mapper(
            dataset)

        day_n = len(dataset[dataset[ct_key] == 'CA']["cases"])

        exp_name = "cases_14_100k"
        exp_ct_name = 'CA'
Example #7
0
            reviews = X_binary.getcol(ind).sum()
            print(item_inverse_mapper[ind] + " " + str(reviews))

    elif question == "3":
        data = load_dataset("outliersData.pkl")
        X = data['X']
        y = data['y']

        # Fit least-squares estimator
        model = linear_model.LeastSquares()
        model.fit(X, y)
        print(model.w)

        utils.test_and_plot(model,
                            X,
                            y,
                            title="Least Squares",
                            filename="least_squares_outliers.pdf")

    elif question == "3.1":
        data = load_dataset("outliersData.pkl")
        X = data['X']
        y = data['y']

        # YOUR CODE HERE

    elif question == "3.3":
        # loads the data in the form of dictionary
        data = load_dataset("outliersData.pkl")
        X = data['X']
        y = data['y']
Example #8
0
        print(X_sums[:][98068])
        print(X_sums[:][98066])

    elif question == "3":
        data = load_dataset("outliersData.pkl")
        X = data['X']
        y = data['y']

        # Fit least-squares estimator
        model = linear_model.LeastSquares()
        model.fit(X, y)
        print(model.w)

        utils.test_and_plot(model,
                            X,
                            y,
                            title="Least Squares",
                            filename="least_squares_outliers.png")

    elif question == "3.1":
        data = load_dataset("outliersData.pkl")
        X = data['X']
        y = data['y']

        dataPoints = np.ones(400)
        outliers = np.full((100, ), 0.1)
        data = np.concatenate((dataPoints, outliers), axis=0)
        z = np.diag(data)

        model = linear_model.WeightedLeastSquares()
        model.fit(X, y, z)
Example #9
0
        print(X_sums[:][98068])
        print(X_sums[:][98066])

    elif question == "3":
        data = load_dataset("outliersData.pkl")
        X = data['X']
        y = data['y']

        # Fit least-squares estimator
        model = linear_model.LeastSquares()
        model.fit(X, y)
        print(model.w)

        utils.test_and_plot(model,
                            X,
                            y,
                            title="Least Squares",
                            filename="least_squares_outliers.pdf")

    elif question == "3.1":
        data = load_dataset("outliersData.pkl")
        X = data['X']
        y = data['y']
        R, C = X.shape

        # YOUR CODE HERE
        z = np.ones(500)
        z[400:500] = z[400:500] * .1
        d = np.diag(z)

        model = linear_model.WeightedLeastSquares()
Example #10
0
        # YOUR CODE HERE FOR Q1.3

    elif question == "3":
        data = load_dataset("outliersData.pkl")
        X = data['X']
        y = data['y']

        # Fit least-squares estimator
        model = linear_model.LeastSquares()
        model.fit(X, y)
        print(model.w)

        utils.test_and_plot(model,
                            X,
                            y,
                            title="Least Squares",
                            filename="least_squares_outliers.pdf")

    elif question == "3.1":
        data = load_dataset("outliersData.pkl")
        X = data['X']
        y = data['y']

        # YOUR CODE HERE
        model = linear_model.WeightedLeastSquares()
        model.fit(X[:400], y[:400], 1)
        model.fit(X[400:], y[400:], 0.1)
        print(model.w)

        utils.test_and_plot(model,