Skip to content

Instantly share code, notes, and snippets.

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'
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)
#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]]
@Robofied
Robofied / textfile.out
Created February 15, 2019 20:16
Numpy
0.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00
np.savetxt('textfile.out',x)
np.loadtxt('textfile.out')
#[Output]:
#array([[0., 0.],
# [0., 0.]])
## 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
## 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)
## 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')
## 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]:
## 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)