This file contains hidden or 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
cv = CountVectorizer() | |
count_matrix = cv.fit_transform(movie["combined_features"]) | |
cosine_sim = cosine_similarity(count_matrix) | |
user_movie = input("Enter movie of your choice:\t") | |
movie_index = index_from_title(user_movie) | |
similar_movies = list(enumerate(cosine_sim[movie_index])) | |
similar_movies_sorted = sorted(similar_movies,key=lambda x:x[1],reverse=True) | |
i=0 |
This file contains hidden or 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
def title_from_index(index): | |
return movie[movie.index == index]["title"].values[0] | |
def index_from_title(title): | |
title_list = movie['title'].tolist() | |
common = difflib.get_close_matches(title, title_list, 1) | |
titlesim = common[0] | |
return movie[movie.title == titlesim]["index"].values[0] |
This file contains hidden or 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
movie = pd.read_csv("moviedata.csv") | |
features = ['keywords','cast','genres','director','tagline'] | |
for feature in features: | |
movie[feature] = movie[feature].fillna('') | |
def combine_features(row): | |
try: | |
return row['keywords'] +" "+row['cast']+" "+row['genres']+" "+row['director']+" "+row['tagline'] | |
except: | |
print ("Error:", row) |
This file contains hidden or 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 pandas as pd | |
import numpy as np | |
from sklearn.feature_extraction.text import CountVectorizer | |
from sklearn.metrics.pairwise import cosine_similarity | |
import difflib |
This file contains hidden or 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
vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) { | |
vector<vector<int>> res; | |
size_t i = 0; | |
// Left part (no intersection with newInterval) | |
while (i < intervals.size() && intervals[i][1] < newInterval[0]) { | |
res.push_back(intervals[i]); | |
++i; | |
} | |
This file contains hidden or 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
TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { | |
if( root == p || root == q || root == NULL) | |
return root; | |
TreeNode * parent1 = lowestCommonAncestor(root->left, p, q); | |
TreeNode * parent2 = lowestCommonAncestor(root->right, p, q); | |
if( parent1 && parent2) | |
return root; | |
else | |
return parent1 ? parent1:parent2; | |
} |
This file contains hidden or 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
bool hasSingleCycle(vector<int> array) { | |
int numElementsVisited = 0; | |
int currentIdx = 0; | |
while (numElementsVisited < array.size()) | |
{ | |
if (numElementsVisited > 0 && currentIdx == 0) | |
return false; | |
numElementsVisited++; | |
currentIdx = getNextIdx(currentIdx, array); | |
} |
This file contains hidden or 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
ListNode* removeNthFromEnd(ListNode* head, int n) | |
{ | |
ListNode** t1 = &head, *t2 = head; | |
for(int i = 1; i < n; ++i) | |
{ | |
t2 = t2->next; | |
} | |
while(t2->next != NULL) | |
{ | |
t1 = &((*t1)->next); |
This file contains hidden or 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
vector<int> riverSizes(vector<vector<int>> matrix) | |
{ | |
vector<int> sizes = {}; | |
vector<vector<int>> visited(matrix.size(), vector<int>(matrix[0].size(), false)); | |
for (int i = 0; i < matrix.size(); i++) { | |
for (int j = 0; j < matrix[i].size(); j++) { | |
if (visited[i][j]) { | |
continue; | |
} | |
traverseNode(i, j, matrix, &visited, &sizes); |
This file contains hidden or 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
int minDistance(string word1, string word2) { | |
int m = word1.size(), n = word2.size(), pre; | |
vector<int> cur(n + 1, 0); | |
for (int j = 1; j <= n; j++) { | |
cur[j] = j; | |
} | |
for (int i = 1; i <= m; i++) { | |
pre = cur[0]; | |
cur[0] = i; | |
for (int j = 1; j <= n; j++) { |