<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: adaranijo mayowa</title>
    <description>The latest articles on DEV Community by adaranijo mayowa (@adaranijo_mayowa_b2aded01).</description>
    <link>https://dev.to/adaranijo_mayowa_b2aded01</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2758033%2Fe02f3546-8d6f-4a5b-a8ac-766ff10fceba.jpeg</url>
      <title>DEV Community: adaranijo mayowa</title>
      <link>https://dev.to/adaranijo_mayowa_b2aded01</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adaranijo_mayowa_b2aded01"/>
    <language>en</language>
    <item>
      <title>Mastering k-Nearest Neighbors (k-NN) with a Practical Python Example</title>
      <dc:creator>adaranijo mayowa</dc:creator>
      <pubDate>Tue, 04 Feb 2025 07:55:17 +0000</pubDate>
      <link>https://dev.to/adaranijo_mayowa_b2aded01/mastering-k-nearest-neighbors-k-nn-with-a-practical-python-example-1kjm</link>
      <guid>https://dev.to/adaranijo_mayowa_b2aded01/mastering-k-nearest-neighbors-k-nn-with-a-practical-python-example-1kjm</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
Imagine you've just moved to a new city and are looking for a good restaurant. You don’t know much about the area, so you ask three locals for recommendations.&lt;br&gt;
• Two suggest Restaurant A.&lt;br&gt;
• One suggests Restaurant B.&lt;br&gt;
Since the majority vote favors Restaurant A, you decide to eat there.&lt;br&gt;
This simple decision-making process mirrors how the k-Nearest Neighbors (k-NN) algorithm works in machine learning! In this post, we’ll dive deep into k-NN, understand its working mechanism, and implement it in Python with a practical example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvqlgwdh8h2sdnpx6dglz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvqlgwdh8h2sdnpx6dglz.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is k-Nearest Neighbors (k-NN)?&lt;/strong&gt;&lt;br&gt;
k-NN is a supervised machine learning algorithm used for both classification and regression. It classifies a data point based on the majority vote of its nearest neighbors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How k-NN Works:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Choose the number of neighbors (k).&lt;/li&gt;
&lt;li&gt; Compute the distance between the new data point and all others in the dataset.&lt;/li&gt;
&lt;li&gt; Select the k nearest points.&lt;/li&gt;
&lt;li&gt; Perform a majority vote to determine the class of the new data point.
Consider it as finding similar cases in a dataset and making predictions based on those similarities.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Implementing k-NN in Python&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s walk through a step-by-step implementation using a dataset where we predict whether a person will purchase a product based on Age and Estimated Salary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Import Necessary Libraries&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Create a Sample Dataset&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data = {
    'Age': [22, 25, 47, 52, 46, 56, 55, 60, 62, 61, 18, 24, 33, 40, 35],
    'EstimatedSalary': [15000, 29000, 43000, 76000, 50000, 83000, 78000, 97000, 104000, 98000, 12000, 27000, 37000, 58000, 41000],
    'Purchased': [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0]  # 1: Purchased, 0: Not Purchased
}
df = pd.DataFrame(data)
print(df.head())
Step 3: Data Preprocessing
X = df[['Age', 'EstimatedSalary']]
y = df['Purchased']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;# Splitting into training and test sets&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;# Feature Scaling (Normalization)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
Step 4: Train the k-NN Model
k = 3
knn = KNeighborsClassifier(n_neighbors=k)
knn.fit(X_train, y_train)
Step 5: Make Predictions and Evaluate the Model
y_pred = knn.predict(X_test)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;# Evaluating Performance&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;accuracy = accuracy_score(y_test, y_pred)
conf_matrix = confusion_matrix(y_test, y_pred)
report = classification_report(y_test, y_pred)

print(f"Accuracy: {accuracy:.2f}")
print("Confusion Matrix:\n", conf_matrix)
print("Classification Report:\n", report)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key Insights&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;1.    Choosing the Right k Value:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;- Small k (e.g., 1 or 3) makes the model sensitive to noise.&lt;/li&gt;
&lt;li&gt;- Large k (e.g., 10 or 15) smooths out noise but may miss patterns.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use cross-validation to determine the best k.&lt;br&gt;
&lt;strong&gt;2.    Importance of Feature Scaling:&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;k-NN relies on distance calculations, so normalizing the features ensures they contribute equally.&lt;br&gt;
&lt;strong&gt;3.    Best for Small Datasets:&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;k-NN is great for datasets with fewer features but computationally expensive for large datasets.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;br&gt;
k-Nearest Neighbors (k-NN) is a powerful yet simple algorithm that can be applied to various classification problems. While it performs well on smaller datasets, it’s important to consider computational costs when scaling up.&lt;br&gt;
Would you like to explore how k-NN works on image classification or time-series forecasting? Let me know in the comments! &lt;/p&gt;

</description>
      <category>python</category>
      <category>discuss</category>
      <category>machinelearning</category>
      <category>learning</category>
    </item>
    <item>
      <title>The Role of NLP in Cybersecurity: Predicting Password Strength</title>
      <dc:creator>adaranijo mayowa</dc:creator>
      <pubDate>Thu, 30 Jan 2025 07:20:28 +0000</pubDate>
      <link>https://dev.to/adaranijo_mayowa_b2aded01/the-role-of-nlp-in-cybersecurity-predicting-password-strength-19o3</link>
      <guid>https://dev.to/adaranijo_mayowa_b2aded01/the-role-of-nlp-in-cybersecurity-predicting-password-strength-19o3</guid>
      <description>&lt;p&gt;In an era where cyber threats are increasing at an alarming rate, the importance of strong passwords cannot be overstated. According to Anderson (2020), weak passwords account for over 80% of hacking-related breaches. With cybercriminals becoming more sophisticated, the need for advanced security measures has never been greater. Natural Language Processing (NLP), a subset of artificial intelligence, is proving to be a powerful tool in enhancing cybersecurity, particularly in predicting password strength and preventing security breaches.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjce1ptmbpg9lin288ppv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjce1ptmbpg9lin288ppv.png" alt="Natural Language Processing" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding NLP as a Machine Learning Algorithm&lt;/strong&gt;&lt;br&gt;
Natural Language Processing (NLP) enables machines to understand, interpret, and generate human language. It is a crucial component of machine learning (ML), where algorithms analyze vast amounts of text data to extract meaningful patterns. NLP combines statistical and deep learning techniques to process textual information efficiently. As Jurafsky &amp;amp; Martin (2021) highlight, NLP models rely on fundamental ML algorithms, including:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Supervised Learning Models&lt;/strong&gt; – Algorithms such as Support Vector Machines (SVM) and Decision Trees are trained on labeled datasets to classify passwords as weak or strong.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Unsupervised Learning Models&lt;/strong&gt; – Clustering techniques like k-means group passwords based on similarities and structure.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Deep Learning Models&lt;/strong&gt; – Neural networks, such as transformers and recurrent neural networks (RNNs), power modern NLP applications for detecting password weaknesses.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;How NLP Predicts Password Strength&lt;/strong&gt;&lt;br&gt;
NLP models evaluate passwords based on linguistic patterns, common words, and predictability. Here’s how it works:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Tokenization &amp;amp; Vectorization:&lt;/strong&gt; Passwords are broken down into smaller units (tokens) and converted into numerical representations that NLP models can analyze (Manning et al., 2008).&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Pattern Recognition:&lt;/strong&gt; NLP-based classifiers detect whether a password follows common phrases, dictionary words, or predictable sequences (Goodfellow et al., 2016).&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Deep Learning &amp;amp; Neural Networks:&lt;/strong&gt; Using LSTM (Long Short-Term Memory) networks, models can identify complex password structures and their resistance to brute-force attacks (Hinton et al., 2012).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Real-Life Application: Predicting Weak Passwords&lt;/strong&gt;&lt;br&gt;
A practical example of NLP in cybersecurity is the development of a password strength prediction model. Researchers have trained models on large datasets of real-world passwords, enabling systems to flag weak passwords in real-time. For instance, an NLP-based system can immediately identify "password123" as weak due to its high predictability and suggest a more secure alternative, such as "G7f#kL2x@".&lt;br&gt;
To demonstrate this concept in code, consider the following example using Python and the Scikit-learn library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.ensemble import RandomForestClassifier

# Sample dataset
passwords = pd.DataFrame({
    'password': ['password123', 'admin', 'G7f#kL2x@', 'qwerty', 'secureP@ss99'],
    'strength': [0, 0, 1, 0, 1]  # 0 = Weak, 1 = Strong
})

# Vectorizing passwords
vectorizer = TfidfVectorizer(analyzer='char', ngram_range=(1,3))
X = vectorizer.fit_transform(passwords['password'])
y = passwords['strength']

# Training model
model = RandomForestClassifier()
model.fit(X, y)

# Predicting password strength
new_passwords = vectorizer.transform(['hello123', 'Str0ngP@ss!'])
predictions = model.predict(new_passwords)
print(predictions)  # Output: [0, 1]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The Future of NLP in Cybersecurity&lt;/strong&gt;&lt;br&gt;
As cyber threats evolve, so must our defenses. NLP will play an even greater role in cybersecurity by:&lt;br&gt;
• Enhancing phishing detection through email and text analysis.&lt;br&gt;
• Automating threat intelligence by scanning and interpreting security reports.&lt;br&gt;
• Strengthening authentication systems by integrating behavioral analysis.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
NLP is transforming cybersecurity by enabling intelligent, automated password strength prediction. With researchers like Anderson (2020) and Jurafsky &amp;amp; Martin (2021) paving the way, organizations can leverage NLP to create safer digital environments. As technology advances, integrating NLP into cybersecurity strategies will be crucial in safeguarding sensitive data against modern cyber threats.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>python</category>
      <category>career</category>
      <category>machinelearning</category>
    </item>
  </channel>
</rss>
