This file contains 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 | |
def plot(x,y,m,b): | |
plt.scatter(x,y) | |
# datapoints | |
y_pred=[i*m+b for i in x] | |
plt.plot(x,y) #classifier line | |
plt.show() | |
This file contains 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 | |
def perceptron(features,labels): | |
theta=np.array([0]*len(features[0])) | |
theta0=0 | |
t=10 | |
while(t): | |
t=t-1 | |
for i in range(len(features)): | |
if (np.dot(features[i],theta)+theta0)*labels[i]<=0: | |
#print('mistake') |
This file contains 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 | |
def perceptron(features,labels): | |
theta=np.array([0]*len(features[0])) | |
theta0=0 | |
t=10 | |
count=1 | |
sum_theta=theta | |
sum_theta_0=theta0 | |
while(t): | |
t=t-1 |
This file contains 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 math | |
import matplotlib.pyplot as plt | |
#----------Pegasos Code definition------------------------# | |
def pegasos(feature_matrix,labels,T): | |
theta=np.array([0]*feature_matrix.shape[1]) | |
theta_0=0 | |
count=0 | |
L=2 #value for lambda | |
for i in range(T): |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
#-------pi(r^2)=(n!)^2 | |
import math | |
fact=[1] | |
#----------Preprocessing---------------# | |
def preprocess(): | |
for i in range(100000): | |
fact.append((fact[i]*(i+1))%1000000007) | |
def main(): | |
preprocess() | |
t=int(input()) |
This file contains 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
p_arr=[] | |
arr=[[0,True,0] for i in range(1000001)] | |
def preprocess(): | |
arr[0][1]=False | |
arr[1][1]=False | |
arr[2][2]=2 | |
p=2 | |
while(p*p<=1000001): | |
#print(p,arr[p][1]) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.