Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Linear Algebra:

Flight Route Plan: From Nagpur, 5 destinations (GHY, PATNA, JPR, GOA, Chennai)

Aircraft of different sizes (& fuel capacity), distance, multicity ?

Assumptions:

-No restricted airspace

-Straight Line distance

Nagpur (21 N, 79 E), Patna (25 N, 85 E)

Longitude on x-axis and latitude on y-axis if we draw on graph. But if you write N/S (latitude) is first per
convention

N -> North of a reference point

Distance measurements = Haversine distance / great circle distance = but for now we assume flat
surface so take Euclidean distance

Destinations = np.array([Guwahati, patna, Jaipur])

Source = np.array([Nagpur])

Distances = np.sum((desinations – source)**2, axis=1)**0.5

^ Above uses broadcasting property of numpy

Can save distance to be travelled in x and y both in numpy.

Vectors = destinations – source

Np.linalg.norm(vectors, axis=1) -> norm is length of vector


====================

Probability of each outcome: Win, Draw, Loss

A vector is a quantity or phenomenon that has two independent properties: magnitude and direction.
The term also denotes the mathematical or geometrical representation of such a quantity.

Vector Space = i, j = any vector in R2 can be created by i, j = spaces is the span(=Linear combination) of
basis vector

Angle between two vectors = from sklearn.metrics.pairwise import cosine_similarity

from sklearn.metrics.pairwise import cosine_similarity

similarity_mat = cosine_similarity(vectors)
idx = [‘A’, ‘B’, ‘C’, ‘D’, ‘E’]

import seaborn as sns

similarity_df = pd.DataFrame(, col, index)

sns.heatmap()

====

Movie recommender via cosine similarity

User_id, movie_id, rating, title

pivot_movie = pd.pivot_table(df, index, col, value)

Assumption: similar movies have similar ratings

From scipy import sparse

From scipy import sparse


sparse_pivot = sparse.csr_matrix(df)

similarity_mat = cosine_similarity(sparse_pivot)

similarity_df = pd.DataFrame(similarity_mat, columns, ..)

movie similarity based on cosine similarities

User ID 1 2 3 4 5

Movie 1 5 NaN NaN

Movie 2

Similar movie in similar direction

Projection of vector: Line coming perpendicular to r is coming, so shadow of s on r is called projection.

Proj of s on r = [(r) * r.s] / (r.r)

How to break a vector v using basis b1 and b2: use projection.

Any point in R2 can be represented using I, j (basis vector!). (Linear combination)

Independence

Basis vectors = independent, linear combination span the space

Orthonormal = perpendicular and unit length.

Represent (x, y) using (1, 0) and (1, 1)


(x, y) = (x-y) i + y * (1, 1)

[3, 2] = projection of r on I = i r.i/(i.i)

To break a vector into the components, the components need to be linearly independently.
Matrix is collection of vectors. A = m * n = m vectors of size n

(AB)T = BT * AT

Orthogonal matrix = AAT = Identity matrix

Standard basis vector = I, j

R = x i+ y j = p u + q v = change of basis, we need a matrix A which will change (x, y) to (p, q)

Scaler projection and vector projection of vector

You might also like