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
import math, gzip, pickle | |
import numpy as np | |
import random | |
import torch | |
from torch import tensor | |
from torch.nn import init | |
from fastai import datasets |
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
import numpy as np | |
import matplotlib.pyplot as plt | |
# random seed to make sure reimplement | |
np.random.seed(0) | |
# the real model line | |
def g(x): | |
return 0.1 * (x + x**2 + x**3) |
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
import numpy as np | |
import matplotlib.pyplot as plt | |
# random seed to make sure reimplement | |
np.random.seed(0) | |
# the real model line | |
def g(x): | |
return 0.1 * (x + x**2 + x**3) |
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
import math | |
import numpy as np | |
import matplotlib.pyplot as plt | |
# read data | |
data = np.loadtxt("non_linear_data.csv", delimiter=',', skiprows=1) | |
train_x = data[:, 0:2] | |
train_y = data[:, 2] | |
# plot data points |
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
import numpy as np | |
import matplotlib.pyplot as plt | |
# read data | |
data = np.loadtxt("non_linear_data.csv", delimiter=',', skiprows=1) | |
train_x = data[:, 0:2] | |
train_y = data[:, 2] | |
# plot data points | |
# plt.plot(train_x[train_y == 1, 0], train_x[train_y == 1, 1], 'o') |
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
x1 | x2 | y | |
---|---|---|---|
0.54508775 | 2.34541183 | 0 | |
0.32769134 | 13.43066561 | 0 | |
4.42748117 | 14.74150395 | 0 | |
2.98189041 | -1.81818172 | 1 | |
4.02286274 | 8.90695686 | 1 | |
2.26722613 | -6.61287392 | 1 | |
-2.66447221 | 5.05453871 | 1 | |
-1.03482441 | -1.95643469 | 1 | |
4.06331548 | 1.70892541 | 1 |
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
import numpy as np | |
import matplotlib.pyplot as plt | |
# read data | |
data = np.loadtxt("linear_data.csv", delimiter=',', skiprows=1) | |
train_x = data[:, 0:2] | |
train_y = data[:, 2] | |
# initialize parameter | |
theta = np.random.randn(3) |
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
x1 | x2 | y | |
---|---|---|---|
153 | 432 | 0 | |
220 | 262 | 0 | |
118 | 214 | 0 | |
474 | 384 | 1 | |
485 | 411 | 1 | |
233 | 430 | 0 | |
396 | 321 | 1 | |
484 | 349 | 1 | |
429 | 259 | 1 |
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
class Solution: | |
def removeDuplicates(self, nums: List[int]) -> int: | |
if len(nums) == 0: return 0 | |
if len(nums) == 1: return 1 | |
# nums = [0,0,1,1,1,2,2,3,3,4] | |
j = 1 # slover pointer, only move when meet unique number | |
for i in range(1, len(nums)): # faster pointer, i will iterate over all element in nums | |
if nums[i] != nums[i-1]: # when nums[i] is a unique number, assign it to nums[j] | |
nums[j] = nums[i] |
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
var fs = require('fs'); | |
var text = fs.readFileSync('./unicode_plane.txt'); | |
var lines = text.toString().split('\n') | |
for (i=0; i < lines.length; i++) { | |
// console.log(lines[i].split(' ')); | |
unicode_char = lines[i].split(' ')[0]; | |
count = lines[i].split(' ')[1]; | |
// test for not use spread operator |