Skip to content

Commit

Permalink
fixed issue #422 (#546)
Browse files Browse the repository at this point in the history
## Pull Request for PyVerse 💡

### Requesting to submit a pull request to the PyVerse repository.

---

#### Issue Title
**Please enter the title of the issue related to your pull request.**   
#422  SONAR Rock vs Mine Prediction with Machine learning 
- [x] I have provided the issue title.

---

#### Info about the Related Issue
**What's the goal of the project?**  

This project is a machine learning solution for classifying objects
detected by a SONAR signal as either a rock or a mine. SONAR (Sound
Navigation and Ranging) is often used in underwater detection systems,
and it can be challenging to accurately identify whether the detected
object is a harmless rock or a dangerous mine. This project aims to
build a machine learning model to predict the classification of the
object based on the characteristics of the SONAR signal.


- [x] I have described the aim of the project.

---

#### Name
**Please mention your name.**  
Shrishti Singh

- [x] I have provided my name.

---

#### GitHub ID
**Please mention your GitHub ID.**  
@ShrishtiSingh26

- [x] I have provided my GitHub ID.

---

#### Email ID
**Please mention your email ID for further communication.**  
[email protected]

- [x] I have provided my email ID.

---

#### Identify Yourself
**Mention in which program you are contributing (e.g., WoB, GSSOC, SSOC,
SWOC).**
contributor at GSSOC- Extd, Hacktoberfest
- [x] I have mentioned my participant role.

---

#### Closes
**Enter the issue number that will be closed through this PR.**  
Closes: #422 

- [x] I have provided the issue number.

---

#### Describe the Add-ons or Changes You've Made
**Give a clear description of what you have added or modified.**  
Added a machine learning model to predict SONAR Rock Vs. Mine


- [x] I have described my changes.

---

#### Type of Change
  
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Code style update (formatting, local variables)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

---

#### How Has This Been Tested?
The testing process for the model involved splitting the dataset into
training and testing sets, scaling the data, and training the model on
the training set. Predictions were made on the test data, and
performance was evaluated,

- [x] I have described my testing process.

---

#### Checklist
**Please confirm the following:**  
- [x] My code follows the guidelines of this project.
- [x] I have performed a self-review of my own code.
- [x] I have commented my code, particularly wherever it was hard to
understand.
- [x] I have made corresponding changes to the documentation.
- [x] My changes generate no new warnings.
- [x] I have added things that prove my fix is effective or that my
feature works.
- [x] Any dependent changes have been merged and published in downstream
modules.
  • Loading branch information
UTSAVS26 authored Oct 19, 2024
2 parents 31d0124 + c49b639 commit 9153dad
Show file tree
Hide file tree
Showing 2 changed files with 277 additions and 0 deletions.
69 changes: 69 additions & 0 deletions Machine_Learning/SONAR_Rock_ Mine_Prediction/sonar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# Load the dataset
data = pd.read_csv('sonar_data.csv')

# Display the shape of the dataset
print(data.shape())

# Display information about the dataset
data.info()

# Check for missing values in the dataset
print(data.isnull().sum())

# Get statistical summary of the dataset
print(data.describe())

# Display the columns of the dataset
print(data.columns)

# Plot the count of the target variable (assuming it is at index 60)
sns.countplot(data[60])
plt.show()

# Calculate the mean of each feature grouped by the target variable
data.groupby(60).mean()

# Separate features and target variable
x = data.drop(60, axis=1) # Features
y = data[60] # Target variable

# Split the dataset into training and testing sets (80% train, 20% test)
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.20, random_state=42)

# Logistic Regression model
from sklearn.linear_model import LogisticRegression
lr = LogisticRegression()
lr.fit(x_train, y_train) # Train the model
y_pred1 = lr.predict(x_test) # Make predictions
print("Logistic Regression Accuracy:", accuracy_score(y_test, y_pred1)) # Calculate accuracy

# K-Nearest Neighbors model
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier(n_neighbors=3)
knn.fit(x_train, y_train) # Train the model
y_pred2 = knn.predict(x_test) # Make predictions
print("KNN Accuracy:", accuracy_score(y_test, y_pred2)) # Calculate accuracy

# Random Forest model
from sklearn.ensemble import RandomForestClassifier
rf = RandomForestClassifier()
rf.fit(x_train, y_train) # Train the model
y_pred3 = rf.predict(x_test) # Make predictions
print("Random Forest Accuracy:", accuracy_score(y_test, y_pred3)) # Calculate accuracy

# Stochastic Gradient Descent model
from sklearn.linear_model import SGDClassifier
sgd = SGDClassifier()

# Train using partial_fit
for i in range(len(x_train)): # Corrected from 'ramge' to 'range'
sgd.partial_fit(x_train[i:i+1], y_train[i:i+1], classes=['R', 'M'])

# Calculate and print the score on the test set
score = sgd.score(x_test, y_test)
print("SGD Classifier Accuracy:", score)
Loading

0 comments on commit 9153dad

Please sign in to comment.