Skip to content

Instantly share code, notes, and snippets.

Robofied Robofied

View GitHub Profile
View SupportVectorMachine.py
from sklearn import svm
#X-> training inputs
#Y-> training outputs
# Here we are training a binary classifier
X = [[1, 0, 2], [0, 1, 3]]
y = [0, 1]
##SVM with setting kernel='linear'
##By default we all have kernel='RBF'
View LADRegression.py
import numpy as np
def d1(c, x):
return sum(abs(x-c))
#Data points: x1,x2,x3,…,xNx1,x2,x3,…,xN
def generate_nods(N):
x = np.linspace(-1.0, 1.0, num=N)
View PolynomialRegression.py
#Import required modules
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
#Some random values for input to a model
X_train = [[1,4],[3,5]]
Y_train = [1,2]
X_test = [[1,5]]
View textfile.out
0.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00
View numpy_input_output3.py
np.savetxt('textfile.out',x)
np.loadtxt('textfile.out')
#[Output]:
#array([[0., 0.],
# [0., 0.]])
View numpy_input_output2.py
## Creating the array of one's
a = np.ones((1,1))
## creating another array
b = np.arange(4)
## saving both the arrays in the same file using savez as .npz
savez('outfile1',a,b)
## Loading the saved .npz file
View numpy_input_output1.py
## Importing libraries to create arrays and save and load then using built in file functions
import numpy as np
x = np.zeros((2,2))
## using save function, save the created numpy array into the .npy filenp.save('outfile', x)
## loading the above saved .npy file
y = np.load('outfile.npy')
print (y)
View numpy_matrix_library2.py
## returning 0's matrix
nm.zeros((2,3))
#[Output]:
#matrix([[0., 0., 0.],
# [0., 0., 0.]])
## it returns diagonal matrix i.e, 1's at diagonal and 0's elsewhere.
nm.eye(n=3, M=4, k=-1, dtype='int')
View numpy_matrix_library1.py
## importig libraries to use for matrix and numpy array
## Importing it as an nm, don't be confused you can use any name instead ## of nm
import numpy.matlib as nm
import numpy as np
## It returns values with initializing empty.
## filled with random data
nm.empty((3,3))
#[Output]:
View numpy_linear_algebra3.py
## performing svd using svd() function.
## Returns full matrices by default.
U,V,S = lnp.svd(a = np.random.randn(9, 6))
## Printing the shapes of all matrices.
print(U.shape,V.shape,S.shape)
#[Output]:
#(9, 9) (6,) (6, 6)
You can’t perform that action at this time.