diff --git a/rock_or_mine.py b/rock_or_mine.py new file mode 100644 index 0000000..826195e --- /dev/null +++ b/rock_or_mine.py @@ -0,0 +1,94 @@ +# -*- coding: utf-8 -*- +"""Project-1 + +Automatically generated by Colaboratory. + +Original file is located at + https://colab.research.google.com/drive/1uJlXbRnd1mLtAv8fp2wDPVeWG1QHKbUw + +Importing libraries +""" + +import numpy as np +import pandas as pd +from sklearn.model_selection import train_test_split +from sklearn.linear_model import LogisticRegression +from sklearn.metrics import accuracy_score + +"""Data collection + processing""" + +#loading the dataset to a panda df +sonar_data = pd.read_csv('/content/Copy of sonar data.csv' , header=None) + +sonar_data.head() + +# number of rows and column +sonar_data.shape + +sonar_data.describe() + +sonar_data[60].value_counts() + +"""M-->mine + +R-->rock +""" + +sonar_data.groupby(60).mean() + +#seperate 60th column +X=sonar_data.drop(columns=60,axis=1)##axis = 0 for rows +Y=sonar_data[60] + +print(X) +print(Y) + +"""Training and test data""" + +X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size = 0.1,stratify=Y,random_state=1) + +print(X.shape,X_train.shape,X_test.shape) + +print(X_train) +print(Y_train) + +"""Model training-->Logistic reg + +""" + +model = LogisticRegression() + +#training the Logistic Regression model with training data +model.fit(X_train, Y_train) + +"""MODEL evaluation + +""" + +#accuracy of training data +X_train_prediction = model.predict(X_train) +training_data_accuracy = accuracy_score(X_train_prediction, Y_train) + +print('Accuracy on training data : ', training_data_accuracy) + +#accuracy on test data +X_test_prediction = model.predict(X_test) +test_data_accuracy = accuracy_score(X_test_prediction, Y_test) + +print('Accuracy on test data : ', test_data_accuracy) + +input_data = (0.0307,0.0523,0.0653,0.0521,0.0611,0.0577,0.0665,0.0664,0.1460,0.2792,0.3877,0.4992,0.4981,0.4972,0.5607,0.7339,0.8230,0.9173,0.9975,0.9911,0.8240,0.6498,0.5980,0.4862,0.3150,0.1543,0.0989,0.0284,0.1008,0.2636,0.2694,0.2930,0.2925,0.3998,0.3660,0.3172,0.4609,0.4374,0.1820,0.3376,0.6202,0.4448,0.1863,0.1420,0.0589,0.0576,0.0672,0.0269,0.0245,0.0190,0.0063,0.0321,0.0189,0.0137,0.0277,0.0152,0.0052,0.0121,0.0124,0.0055) + +# changing the input_data to a numpy array +input_data_as_numpy_array = np.asarray(input_data) + +# reshape the np array as we are predicting for one instance +input_data_reshaped = input_data_as_numpy_array.reshape(1,-1) + +prediction = model.predict(input_data_reshaped) +print(prediction) + +if (prediction[0]=='R'): + print('The object is a Rock') +else: + print('The object is a mine') \ No newline at end of file