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
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' |
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 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) |
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 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]] |
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
0.000000000000000000e+00 0.000000000000000000e+00 | |
0.000000000000000000e+00 0.000000000000000000e+00 |
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
np.savetxt('textfile.out',x) | |
np.loadtxt('textfile.out') | |
#[Output]: | |
#array([[0., 0.], | |
# [0., 0.]]) |
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
## 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 |
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
## 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) |
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
## 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') |
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
## 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]: |
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
## 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) |
NewerOlder