A sonar rock vs mine predictive system using logistic regression aims to classify sonar signals as either coming from rocks or mines (metal cylinders).
Creating a predictive system involves several steps, including data preprocessing, building the logistic regression model, training the model, evaluating its performance, and making predictions. Here's a detailed approach to building a sonar rock vs. mine predictive system using logistic regression:
- Obtain the dataset. For this example, we will use the "Sonar, Mines vs. Rocks" dataset from Kaggle.
-
Load the Data:
- Import the necessary libraries.
- Load the dataset into a Pandas DataFrame.
-
Normalize the Data:
- Normalize the features to bring them to a similar scale.
-
Label Encoding:
- Convert the categorical labels ('R' for rock, 'M' for mine) into binary numerical values (0 and 1).
- Use the
LogisticRegression
class from scikit-learn.
- Split the dataset into training and testing sets.
- Train the model using the training data.
- Evaluate the model's performance using metrics such as accuracy score.
-
Use the trained model to make predictions on new data.
-
While on Training data you will be get the accuracy of 83.42245989304813 %
-
And test data accuracy obtained is 76.19047619047619 %