<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vlademir José on Medium]]></title>
        <description><![CDATA[Stories by Vlademir José on Medium]]></description>
        <link>https://medium.com/@vlademirjos?source=rss-30e2b60ce20d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Kbja2UsQ-aF2beMRQjb-nQ.png</url>
            <title>Stories by Vlademir José on Medium</title>
            <link>https://medium.com/@vlademirjos?source=rss-30e2b60ce20d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 04:36:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vlademirjos/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Quick Tutorial about Q-Learning]]></title>
            <link>https://medium.com/@vlademirjos/quick-tutorial-about-q-learning-e77b3df6dad4?source=rss-30e2b60ce20d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e77b3df6dad4</guid>
            <category><![CDATA[q-learning]]></category>
            <category><![CDATA[unsupervised-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[reinforcement-learning]]></category>
            <category><![CDATA[deep-q-learning]]></category>
            <dc:creator><![CDATA[Vlademir José]]></dc:creator>
            <pubDate>Fri, 12 Jul 2024 13:26:46 GMT</pubDate>
            <atom:updated>2024-07-12T13:26:46.359Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/688/0*mumgsC8azjco0FZK.jpg" /></figure><h3>Introduction to Reinforcement Learning</h3><p>Reinforcement Learning (RL) is a type of machine learning where an agent learns to make decisions by taking actions in an environment to maximize cumulative reward. Unlike supervised learning, where the model learns from a fixed dataset, RL involves learning from the consequences of actions, encouraging behaviors that yield the highest rewards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/0*KVDHopNX4rT5pp-L.png" /></figure><p>Summarizing the reinforcement learning process:</p><ol><li>The agent starts at an initial state in the environment.</li><li>It takes an action based on a specific policy or strategy.</li><li>The environment responds with a reward or punishment for that action.</li><li>The agent updates its strategy by learning from the outcomes of previous actions.</li><li>This process repeats until the agent discovers an optimal strategy that maximizes cumulative reward.</li></ol><h3>What is Q-Learning?</h3><p>Q-Learning is a model-free reinforcement learning algorithm. It seeks to learn a policy that tells an agent what action to take under what circumstances. By using Q-values (which represent the quality of a state-action combination), the agent aims to maximize its total reward over time.</p><p>In Q-Learning, we use a Q-Table where rows represent states and columns represent actions. The value in cell (s, a) of the Q-Table is the Q-value, which indicates the expected utility of taking action ‘a’ in state ‘s’.</p><p>The Q-value update rule is given by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/0*syKwX_XNOS1VlFYa.png" /></figure><p>A Q-Table representation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8_vSu15PkoWO74LA.png" /></figure><h3>Frozen Lake Problem</h3><p>The Frozen Lake environment is a classic problem provided by the Gymnasium library. The agent must navigate a frozen lake to reach a goal without falling into holes. The state space represents the positions on the grid, and the action space includes four possible movements (left, down, right, up). Rewards are sparse, with a reward of 1 for reaching the goal and 0 otherwise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/0*deawLac5VnfiMzge.gif" /></figure><h3>Implementing Q-Learning for Frozen Lake</h3><h4>1. Importing Libraries</h4><pre>import numpy as np<br>import matplotlib.pyplot as plt<br>import gymnasium as gym<br>import os</pre><h4>2. Epsilon-Greedy Strategy</h4><p>We set up the parameters for epsilon decay. Epsilon controls the exploration-exploitation trade-off. Initially, the agent explores more, but over time it exploits the knowledge acquired.</p><pre>max_epsilon = 1.0<br>min_epsilon = 0.05<br>decay_rate = 0.02<br>episodes = 100<br><br>epsilons = [min_epsilon + (max_epsilon - min_epsilon) * np.exp(-decay_rate * ep) for ep in range(episodes)]<br><br>plt.plot(epsilons)<br>plt.xlabel(&#39;Episode&#39;)<br>plt.ylabel(&#39;Epsilon&#39;)<br>plt.title(&#39;Epsilon Decay over Episodes&#39;)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*5t5oRcAuKIIkSklIGa0caQ.png" /></figure><h4>3. Q-Value Update Function</h4><pre>def q_function(q_table, state, action, reward, next_state, learning_rate, discount_rate):<br>    best_next_q_action = np.max(q_table[next_state, :])<br>    <br>    q_value = q_table[state, action] + learning_rate * (reward + discount_rate * best_next_q_action - q_table[state, action])<br><br>    return q_value</pre><h4>4. Training the Q-Learning Agent</h4><p>We initialize the environment and Q-table, then train the agent over multiple episodes.</p><pre>env = gym.make(&#39;FrozenLake-v1&#39;, render_mode=&#39;human&#39;)<br><br>n_states = env.observation_space.n<br>n_actions = env.action_space.n<br><br>file_path = &#39;q_table.txt&#39;<br><br>if os.path.exists(file_path):<br>    print(&#39;Exist&#39;)<br>    q_table = np.loadtxt(file_path)<br>else:<br>    print(&#39;Create Q-Table&#39;)<br>    q_table = np.zeros((n_states, n_actions))<br><br>learning_rate = 0.7<br>discount_rate = 0.95<br><br>episodes = 1000<br><br>for ep in range(episodes):<br>    state = env.reset()[0]<br>    finish = False<br><br>    epsilon = min_epsilon + (max_epsilon - min_epsilon) * np.exp(-decay_rate * ep)<br><br>    while not finish:<br>        if np.random.uniform(0, 1) &lt; epsilon:<br>            action = np.random.choice(n_actions)  # Exploration<br>        else:<br>            action = np.argmax(q_table[state, :])  # Exploitation<br><br>        step_return = env.step(action)<br><br>        next_state = step_return[0]<br>        reward = step_return[1]<br>        finish = step_return[2]<br><br>        if finish == 1 and reward == 0:<br>            reward = -1<br><br>        q_value = q_function(q_table, state, action, reward, next_state, learning_rate, discount_rate)<br>        q_table[state, action] = q_value<br><br>        state = next_state<br><br>    print(f&#39;Ep {ep}&#39;)<br><br>    if reward == 1:<br>        print(&#39;Win&#39;)<br><br>env.close()<br><br>np.savetxt(&#39;q_table.txt&#39;, q_table)</pre><p><strong>Full example here</strong>: <a href="https://github.com/VladeMelo/q-learning">https://github.com/VladeMelo/q-learning</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e77b3df6dad4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Object Detection and Tracking Project]]></title>
            <link>https://medium.com/@vlademirjos/object-detection-and-tracking-project-1e3f10cd1a83?source=rss-30e2b60ce20d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e3f10cd1a83</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[object-detection]]></category>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[yolo]]></category>
            <category><![CDATA[object-tracking]]></category>
            <dc:creator><![CDATA[Vlademir José]]></dc:creator>
            <pubDate>Thu, 11 Jul 2024 18:18:55 GMT</pubDate>
            <atom:updated>2024-07-12T13:09:30.760Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*truAouB42_X7rnKa.png" /></figure><h3>Introduction</h3><ul><li><strong>Object Detection:</strong> Identifies and locates objects within images or videos, specifying their positions with bounding boxes. YOLO (You Only Look Once) is a popular single-stage object detection algorithm known for its speed and accuracy. Unlike two-stage detectors, YOLO processes the entire image in one pass, making real-time detection feasible. This approach has revolutionized applications like autonomous driving, surveillance, and robotics by providing efficient and reliable object detection capabilities.</li><li><strong>Object Tracking:</strong> Follows the identified objects across multiple frames in a video. The SORT (Simple Online and Realtime Tracking) algorithm is widely used for this purpose, as it efficiently tracks objects by predicting their movement and updating their positions in real-time. Combining YOLO for detection and SORT for tracking enables continuous monitoring and analysis of objects, ensuring accurate and consistent tracking throughout the video sequence.</li></ul><h3>Project</h3><p>We will count the number of cars that pass through a specific region in our video using object detection with YOLOv8m (medium version), OpenCV and SORT to ensure accuracy and efficiency.</p><h4>1. Choose a Video</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*2mxrnw81f-M9Po9vn8gaqA.gif" /></figure><h4>2. Create the Mask</h4><p>We just want to identify cars that are under the bridge. To achieve this, we will create a mask using a canvas. A mask is typically a binary image, where pixels are either black (0) or white (255). In an RGB image, this means that the mask uses only two values:</p><ul><li><strong>White (255, 255, 255)</strong> indicates the regions of interest, where the algorithm will perform processing.</li><li><strong>Black (0, 0, 0)</strong> indicates the regions to be ignored or excluded from processing.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fxYZ2hb22CdJlMvLkWm-YA.png" /></figure><p>Combining the mask with the video using a bitwise operation, we achieve the following result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FVtJxQONCzgxGoAzao73tQ.gif" /></figure><h4>3. Define a Region</h4><p>We are going to define two regions in our video: one to count the cars going down and another to count the cars going up on the road.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*S5V1JoQ8GG_p2AgiO9oNfg.png" /></figure><p>When a car is identified in the specified region, we will change the color of that region to green, indicating detection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*WEvval09yJPRNlr1FItAyQ.png" /></figure><h4>4. Build the Layout</h4><p>Let’s build the layout for the counters using cvzone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wD5xQNcPU-n2JwD0rqfDpQ.png" /></figure><h4>5. Time to Code</h4><ul><li><strong>cv2</strong>: perform image and video processing</li><li><strong>cvzone</strong>: works together with OpenCV</li><li><strong>numpy</strong>: deal with numerical operations</li><li><strong>YOLO</strong>: apply object detection</li><li><strong>sort</strong>: <a href="https://github.com/abewley/sort">SORT library</a> for tracking detected objects.</li></ul><pre>import cv2<br>import numpy as np<br>from ultralytics import YOLO<br>import cvzone<br>from sort import sort<br><br>class_names = [<br>  &#39;person&#39;, &#39;bicycle&#39;, &#39;car&#39;, &#39;motorcycle&#39;, &#39;airplane&#39;, &#39;bus&#39;, &#39;train&#39;, &#39;truck&#39;, &#39;boat&#39;, &#39;traffic light&#39;, &#39;fire hydrant&#39;, &#39;stop sign&#39;, &#39;parking meter&#39;, &#39;bench&#39;, <br>  &#39;bird&#39;, &#39;cat&#39;, &#39;dog&#39;, &#39;horse&#39;, &#39;sheep&#39;, &#39;cow&#39;, &#39;elephant&#39;, &#39;bear&#39;, &#39;zebra&#39;, &#39;giraffe&#39;, &#39;backpack&#39;, &#39;umbrella&#39;, &#39;handbag&#39;, &#39;tie&#39;, &#39;suitcase&#39;, &#39;frisbee&#39;, &#39;skis&#39;, <br>  &#39;snowboard&#39;, &#39;sports ball&#39;, &#39;kite&#39;, &#39;baseball bat&#39;, &#39;baseball glove&#39;, &#39;skateboard&#39;, &#39;surfboard&#39;, &#39;tennis racket&#39;, &#39;bottle&#39;, &#39;wine glass&#39;, &#39;cup&#39;, &#39;fork&#39;, &#39;knife&#39;, <br>  &#39;spoon&#39;, &#39;bowl&#39;, &#39;banana&#39;, &#39;apple&#39;, &#39;sandwich&#39;, &#39;orange&#39;, &#39;broccoli&#39;, &#39;carrot&#39;, &#39;hot dog&#39;, &#39;pizza&#39;, &#39;donut&#39;, &#39;cake&#39;, &#39;chair&#39;, &#39;couch&#39;, &#39;potted plant&#39;, &#39;bed&#39;, <br>  &#39;dining table&#39;, &#39;toilet&#39;, &#39;tv&#39;, &#39;laptop&#39;, &#39;mouse&#39;, &#39;remote&#39;, &#39;keyboard&#39;, &#39;cell phone&#39;, &#39;microwave&#39;, &#39;oven&#39;, &#39;toaster&#39;, &#39;sink&#39;, &#39;refrigerator&#39;, &#39;book&#39;, &#39;clock&#39;, <br>  &#39;vase&#39;, &#39;scissors&#39;, &#39;teddy bear&#39;, &#39;hair drier&#39;, &#39;toothbrush&#39;<br>]<br><br>class_names_goal = [&#39;car&#39;]<br><br>model = YOLO(&#39;yolov8m.pt&#39;)<br>tracker = sort.Sort(max_age=20) <br><br>mask = cv2.imread(&#39;mask.png&#39;) <br><br>video = cv2.VideoCapture(&#39;traffic.mp4&#39;)<br><br>width = 1280<br>height = 720<br><br>line_left_road_x1 = 256<br>line_left_road_x2 = 500<br>line_left_road_y = 472<br><br>line_right_road_x1 = 672<br>line_right_road_x2 = 904<br>line_right_road_y = 472<br><br>vehicle_left_road_id_count = []<br>vehicle_right_road_id_count = []<br><br>while True:<br>  success, frame = video.read()<br><br>  if not success:<br>    break<br><br>  frame = cv2.resize(frame, (width, height))<br><br>  image_region = cv2.bitwise_and(frame, mask) <br><br>  results = model(image_region, stream=True) <br><br>  detections = []<br>  <br>  cv2.line(frame, (line_left_road_x1, line_left_road_y) ,(line_left_road_x2, line_left_road_y), (0, 0, 255))<br>  cv2.line(frame, (line_right_road_x1, line_right_road_y) ,(line_right_road_x2, line_right_road_y), (0, 0, 255))<br><br>  for result in results:<br>    for box in result.boxes:<br>      class_name = class_names[int(box.cls[0])]<br><br>      if not class_name in class_names_goal:<br>        continue<br><br>      confidence = round(float(box.conf[0]) * 100, 2)<br><br>      if confidence &lt; 30:<br>        continue<br><br>      x1, y1, x2, y2 = box.xyxy[0]<br>      x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)<br><br>      detections.append([x1, y1, x2, y2, float(box.conf[0])])<br><br>    tracked_objects = tracker.update(np.array(detections))<br><br>    for obj in tracked_objects:<br>      x1, y1, x2, y2, obj_id = [int(i) for i in obj]<br><br>      confidence_pos_x1 = max(0, x1)<br>      confidence_pos_y1 = max(36, y1)<br><br>      cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 0, 255), 2)<br>      cvzone.putTextRect(frame, f&#39;ID: {obj_id}&#39;, (confidence_pos_x1, confidence_pos_y1), 1, 1)<br><br>      center_x = (x1 + x2) // 2<br>      center_y = (y1 + y2) // 2<br><br>      if  line_left_road_y - 10 &lt; center_y &lt; line_left_road_y + 10 and line_left_road_x1 &lt; center_x &lt; line_left_road_x2:<br>        if not obj_id in vehicle_left_road_id_count:<br>          vehicle_left_road_id_count.append(obj_id)<br><br>          cv2.line(frame, (line_left_road_x1, line_left_road_y) ,(line_left_road_x2, line_left_road_y), (0, 255, 0), 2)<br><br>      if  line_right_road_y - 10 &lt; center_y &lt; line_right_road_y + 10 and line_right_road_x1 &lt; center_x &lt; line_right_road_x2:<br>        if not obj_id in vehicle_right_road_id_count:<br>          vehicle_right_road_id_count.append(obj_id)<br><br>          cv2.line(frame, (line_right_road_x1, line_right_road_y) ,(line_right_road_x2, line_right_road_y), (0, 255, 0), 2)<br><br>  cvzone.putTextRect(frame, f&#39;Car Left Road Count: {len(vehicle_left_road_id_count)}&#39;, (50, 50), 2, 2, offset=20, border=2, colorR=(140, 57, 31), colorB=(140, 57, 31))<br>  cvzone.putTextRect(frame, f&#39;Car Right Road Count: {len(vehicle_right_road_id_count)}&#39;, (width - 460, 50), 2, 2, offset=20, border=2, colorR=(140, 57, 31), colorB=(140, 57, 31))<br><br>  cv2.imshow(&#39;Image&#39;, frame)<br><br>  if cv2.waitKey(1) &amp; 0xFF == ord(&#39;q&#39;):<br>    break<br><br>video.release()<br>cv2.destroyAllWindows()</pre><h4>6. Results</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*47emp2oH-4kLPIQUVXhijw.gif" /></figure><p><strong>Full example here</strong>: <a href="https://github.com/VladeMelo/car-counter">https://github.com/VladeMelo/collaborative-filtering</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e3f10cd1a83" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Collaborative Filtering for Recommendation System]]></title>
            <link>https://medium.com/@vlademirjos/building-collaborative-filtering-for-recommender-system-8c50628d0116?source=rss-30e2b60ce20d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c50628d0116</guid>
            <category><![CDATA[collaborative-filtering]]></category>
            <category><![CDATA[cosine-similarity]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[user-experience]]></category>
            <category><![CDATA[netflix]]></category>
            <dc:creator><![CDATA[Vlademir José]]></dc:creator>
            <pubDate>Wed, 10 Jul 2024 18:01:30 GMT</pubDate>
            <atom:updated>2024-07-11T15:10:47.582Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*K2wnhPxwI4mp7GnZ.jpg" /></figure><h3>What is Collaborative Filtering?</h3><p>Collaborative Filtering is a recommendation system technique widely used in marketing, e-commerce, and streaming services to personalize user experiences. It analyzes user preferences and behaviors to suggest items they might like. The fundamental principle is that people who agreed in the past will agree in the future. This method uses data like ratings, purchase history, or browsing habits to find patterns and make recommendations. Major companies like <strong>Netflix</strong>, <strong>Amazon</strong>, and <strong>Spotify </strong>use collaborative filtering to enhance user engagement and satisfaction.</p><p>There are two primary types of collaborative filtering:</p><ol><li><strong>User-Based Collaborative Filtering</strong>: This approach identifies users with similar preferences and recommends items that these similar users have liked. For instance, if User A and User B have similar movie-watching patterns, the system will recommend movies that User B liked to User A.</li><li><strong>Item-Based Collaborative Filtering</strong>: Instead of focusing on users, this method looks at items. It identifies items that are similar to each other based on user interactions. For example, if many users who bought Item X also bought Item Y, then Item Y will be recommended to users interested in Item X.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*pwTJcwxuRIH_l5JRHRoQlA.png" /></figure><h3>How to Compute the Similarity?</h3><p>A critical step in Collaborative Filtering is measuring similarity between users or items. Cosine Similarity is a popular metric for this purpose. It measures the cosine of the angle between two vectors, which represent users or items in a multi-dimensional space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fqd_VmBseHoK9xJj.jpg" /></figure><h4>Calculation</h4><ol><li><strong>Vectors Representation</strong>: Users or items are represented as vectors.</li><li><strong>Dot Product</strong>: Compute the dot product of the vectors.</li><li><strong>Magnitude</strong>: Calculate each vector’s magnitude.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6_A7jtTFrUMbBM2n.png" /></figure><h3>Handling Empty Values</h3><p>In collaborative filtering, using 0 for missing ratings can distort similarity calculations and lower recommendation quality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/0*QX7Vy5LVn9CZ-M-j.png" /></figure><p>Instead, we use mean normalization. This method adjusts ratings by subtracting the user’s average rating, which accounts for individual rating biases. It centers the data around zero, reducing the impact of missing values and improving the accuracy of recommendations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*jibZ-aR4tF7K4Nim.png" /></figure><h3>Implementing a Recommendation System</h3><p>We are going to use a movies dataset for this example: <a href="https://www.kaggle.com/competitions/predict-movie-ratings/data">Predict Movie Ratings</a></p><h4>1. Pivot DataFrame</h4><pre>import pandas as pd<br>import numpy as np<br><br>df = pd.read_csv(&#39;train_v2.csv&#39;)<br>df.drop(&#39;ID&#39;, axis=1, inplace=True)<br><br>df_user_based = df.pivot(&#39;user&#39;, &#39;movie&#39;, &#39;rating&#39;)</pre><h4>2. Apply Mean Normalization</h4><pre>def mean_normalization(row):<br>  mean = row.mean()<br><br>  return row - mean <br><br>df_user_based_normalized = df_user_based.apply(mean_normalization, axis=1)<br>df_user_based_normalized.fillna(0, inplace=True)</pre><h4>3. Define Cosine Similarity Function</h4><pre>def cosine_similarity(vector_a, vector_b):<br>  scalar_product = 0<br>  magnitude_a = 0<br>  magnitude_b  = 0<br><br>  for i in range(len(vector_a)):<br>    scalar_product += vector_a[i] * vector_b[i]<br><br>    magnitude_a += vector_a[i] ** 2<br>    magnitude_b += vector_b[i] ** 2<br><br>  magnitude_a = magnitude_a ** (1/2)<br>  magnitude_b = magnitude_b ** (1/2)<br><br>  if magnitude_a == 0 or magnitude_b == 0:<br>    return 0<br><br>  return scalar_product / (magnitude_a * magnitude_b)</pre><h4>4. Create a Triangular Similarity Matrix</h4><p>Instead of creating a full similarity matrix, we can use a triangular matrix. This approach requires less computational power because we only calculate and store the necessary half of the matrix, avoiding redundant computations.</p><pre>n_users = df_user_based_normalized.shape[0]<br><br>triangular_similarity_matrix = pd.DataFrame(np.nan, index=df_user_based_normalized.index, columns=df_user_based_normalized.index)<br><br>for current_user in range(n_users):<br>  vector_a = df_user_based_normalized.iloc[current_user, :].values<br><br>  for aux_user in range(current_user, n_users):<br>    vector_b = df_user_based_normalized.iloc[aux_user, :].values<br><br>    triangular_similarity_matrix.iloc[current_user, aux_user] = cosine_similarity(vector_a, vector_b)</pre><h4>5. Explore the Matrix</h4><p>Now that we have our similarity matrix ready, the next step is to explore it and analyze potential recommendations for each user.</p><h3>Conclusion</h3><p>Collaborative filtering is a simple and powerful method for creating personalized recommendation systems. By utilizing techniques like Cosine Similarity and handling missing values with mean normalization, we can significantly enhance recommendation accuracy. Using a triangular similarity matrix also improves efficiency. This approach increases user engagement and satisfaction by tailoring suggestions to individual preferences.</p><p><strong>Full example here</strong>: <a href="https://github.com/VladeMelo/collaborative-filtering">https://github.com/VladeMelo/collaborative-filtering</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c50628d0116" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>