<jupyter_start><jupyter_text>Classification: Detect Pipe or Rock with Sonar DataClassification of Rock or Mine with [sonar data](https://archive.ics.uci.edu/ml/datasets/Connectionist+Bench+(Sonar,+Mines+vs.+Rocks)). Sonar (sound navigation and ranging) uses sound waves to detect objects, similar to how a bat uses echo-location to navigate, and detect objects. It is the same principle with seismic data for non-invasive underground exploration of geologic formations to locate oil or gas reserves.```pythonurl = 'http://apmonitor.com/pds/uploads/Main/sonar_detection.txt'```The data set of sonar is taken from different angles and locations to detect the rock or pipe. The data was collected in a laboratory under controlled conditions as a case study for detecting underground pipe. There are 111 labeled sets for the metal cyclinder (pipe) and 97 sonar patterns from rocks with similar conditions. Each sample is a set of 60 numbers between 0 and 1 that represents the integrated energy within a distinct frequency band and for a given time period.	[Pipe / Rock Sonar Case Study](https://apmonitor.com/pds/index.php/Main/SonarDetection) on [Machine Learning for Engineers](https://apmonitor.com/pds/index.php/Main/SonarDetection)Although this case study is specifc to detecting differences between metal pipe and rock, it is similar to detection of other underground features such as tunnels, mines, aquifers, and fluid-filled pipelines.  Import PackagesImport *pandas*, *matplotlib*, and other packages that you need for this exercise.  Read DataRead data as a Pandas dataframe with `data=pd.read_csv(url)`. Show 10 random rows with `data.sample(10)`.   Data Visualization<jupyter_code>data.plot(kind='box', subplots=True, layout=(6,10),\
             sharex=False, legend=False, fontsize=1, \
             figsize=(12,8))
plt.show()
data.groupby('Class').size()
data['Class'].value_counts().plot(kind='bar')
plt.show()
# correlation matrix
from matplotlib import cm
fig = plt.figure()
ax = fig.add_subplot(111)
cax = ax.matshow(data.corr(), vmin=-1, vmax=1, cmap=cm.Spectral_r, interpolation='none')
fig.colorbar(cax)
fig.set_size_inches(10,10)
plt.savefig('sonar_correlation.png')
plt.show()
data.plot(kind='density', subplots=True, layout=(6,10),\
             sharex=False, legend=False, fontsize=1, \
             figsize=(12,8))
plt.show()
data.hist(sharex=False, sharey=False, layout=(6,10),\
        xlabelsize=1, ylabelsize=1, figsize=(12,8))
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10772927513015619, 'fraction_numerical': 0.01762114537444934, 'mean_word_length': 5.152709359605911, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '661397', 'license': 'MIT', 'n_tokens_mistral': 778, 'n_tokens_neox': 723, 'n_words': 257, 'path': 'Sonar_Detection.ipynb', 'repo_name': 'APMonitor/pds', 'size': '2497'}