Git Product home page Git Product logo

leetcode-notebook's Introduction

Leetcode-Notebook

Since i'm becoming a junior student in the school of CS, the ability of coding is extremely important. From today(2020-8-6), i will continuely update my notes of Leetcode till my graduation.Hope i won't become an idiot of algorithm in the future.

Mark

1 Leetcode学习路径

2 大佬Carl开路刷题

感悟:

现在还处于学习的阶段,多看看别人的解法,多总结不同的工具,不要浪费时间死磕

不得不说,自己完全做出来/看着题解做出来/过一阵子再做一遍 是完全不一样的效果。想真正掌握一道不会的题目,得自己徒手做个几遍才行,不然临场发挥会遇到细节问题。

记录:

【8.27】终于刷到了20题,为自己买了一个心心念念的机械键盘。灯光巨好看,用起来,一个字,爽!

leetcode-notebook's People

Contributors

brack-wang avatar

Stargazers

 avatar

Watchers

 avatar

leetcode-notebook's Issues

code

def train(self, X_train: np.ndarray, y_train: np.ndarray):
    """Train the classifier.

    Use the perceptron update rule as introduced in the Lecture.

    Parameters:
        X_train: a number array of shape (N, D) containing training data;
            N examples with D dimensions
        y_train: a numpy array of shape (N,) containing training labels
    """
    # TODO: implement me
    self.w = np.random.random((self.n_class, X_train.shape[1]))

    for epoch in range(self.epochs):
        if epoch % 2 == 0:
            self.lr /= 3
        for index in range(len(X_train)):
            label = y_train[index]
            data = X_train[index, :]
            w_yi = self.w[label, :]
            wyi_xi =  np.dot(w_yi, data.T)
            for class_index in range(self.n_class):
                if (class_index != label):
                    w_c = self.w[class_index, :]
                    wc_xi = np.dot(w_c, data.T)
                    if wc_xi > wyi_xi:
                        self.w[label,:] = self.w[label,:] + self.lr * data
                        self.w[class_index, :] = self.w[class_index, :] - self.lr *data
    
    # for epoch in range(self.epochs):
    #     pred = np.dot(self.w, X_train.T)
    #     for index in range(len(X_train)):
    #         pred_label= np.argmax(pred[:, index])
    #         train_label = y_train[index]
    #         if pred_label!=train_label:
    #             self.w[:, :] -=  self.lr * X_train[index, :]
    #             self.w[train_label, :] +=  2* self.lr * X_train[index, :]
    pass

def predict(self, X_test: np.ndarray) -> np.ndarray:
    """Use the trained weights to predict labels for test data points.

    Parameters:
        X_test: a numpy array of shape (N, D) containing testing data;
            N examples with D dimensions

    Returns:
        predicted labels for the data in X_test; a 1-dimensional array of
            length N, where each element is an integer giving the predicted
            class.
    """
    # TODO: implement me
    result = []

    for index in range(len(X_test)):
        data = X_test[index,:]
        prob = np.dot(self.w, data.T)
        pred = np.argmax(prob)
        result.append(pred)
    return np.array(result)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.