Suppose there is a war between countries and we have assigned submarines to check whether there is rock or a mine inside water.
Mines are explosives that explode when some object come in contact with it.
And there can be rocks as well in the ocean.
What to build ?
→ Submarines have to predict whether it is crossing a mine or a rock. So, we have to build a system to predict whether the object beneath the submarine is mine or rock.
How it can be done ?
→ Submarine uses a sonar that sends sound signal and reviews switch back of the signal. So, this signal is then processed to detect whether the object is mine or just a rock in the ocean.
These sound waves can travel for hundreds of miles under water, and can retain an intensity of 140 decibels as far as 300 miles from their source.
Collect Sonar Data : Laboratory setup experiment can be done where sonar is used to send and receive signals. There is far difference between signals received from mines and rocks. Because mines will be made up of metal.
So, we collect this data which is nothing but the sonar data obtained from a rock and a metal cylinder.
And later, we use this sonar data and feed it to our machine learning model.
and our model will predict whether the object is made up of metal or it is just a rock.
This is the principle we are going to use in our prediction.
Data Preprocessing : We must process data for better results. In preprocessing, we do cleaning, filling missing values etc.
Train Test Split : After that, we will train our model with 80-90% of training-data and 10–20% will be used to test-data. And evaluate our model with the help of test-data.
Logistic Regression Model : Why Logistic Regression Model ? Because, this model works very well for Binary Classification Problem. It is a Binary Classification Problem (Rock or a Mine).
This is a Supervised Learning Algorithm.
# Importing Dependencies import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression from sklearn.metrics import accuracy_score # Dataset Reading sonar_data=pd.read_csv("sonardata.csv",header=None) # Check relation between classes sonar_data.groupby(60).mean() # Separating input-output columns X=sonar_data.drop(columns=60,axis=1) y=sonar_data # train_test_split X_train,X_test,Y_train,Y_test=train_test_split(X,y,test_size=0.1,stratify=y,random_state=1) # Model Building model=LogisticRegression() # Model Fitting model.fit(X_train,Y_train) # accuracy on training data X_train_pred=model.predict(X_train) training_data_accuracy=accuracy_score(X_train_pred,Y_train) # accuracy on test data X_test_pred=model.predict(X_test) test_data_accuracy=accuracy_score(X_test_pred,Y_test) # Check Github Link For Full Code And Dataset
Github Link : Click Here