<jupyter_start><jupyter_text>Machine Learning in Python    DBScan    <NAME>  Topics:- [ ] What is DBScan- [ ] DBScan step by step- [ ] DBScan vs K-means- [ ] DBScan in Code  What is DBScan?  DBSCAN (Density-Based Spatial Clustering of Applications with Noise) Finds core samples of high density and expands clusters from them. ... This is not a maximum bound on the distances of points within a cluster. This is the most important DBSCAN parameter to choose appropriately for your data set and distance function.Density-Based Clustering refers to unsupervised learning methods that identify distinctive groups/clusters in the data, based on the idea that a cluster in data space is a contiguous region of high point density, separated from other such clusters by contiguous regions of low point density.Density-Based Spatial Clustering of Applications with Noise (DBSCAN) is a base algorithm for density-based clustering. It can discover clusters of different shapes and sizes from a large amount of data, which is containing noise and outliers.  DBScan (Step by Step)   Usually 2 parameters for DBSCAN to Optimize * Epsilon * Minimum PointsEpsilon $(\epsilon)$  determines how much close the points should be to be considered a part of a cluster and Minimum Points _(MinPts)_  determines how many number of samples (points) need to be considered around a point within the radius $\epsilon$ to be considered as a _Core Point_. _MinPts_ include the point in consideration itself.   We start with loading the Canada Weather Data-Set. We will __cluster weather stations that show similar weather conditions__. Selection of features and applications on clustering will be shown. Since the data domain is not so well understood, it is always best to play around with $\epsilon$ and _MinPts_ parameter in Scikit learn.  * Core — This is a point that has at least m points within distance n from itself.* Border — This is a point that has at least one Core point at a distance n.* Noise — This is a point that is neither a Core nor a Border. And it has less than m points within distance n from itself.          DBScan vs K-means?   DBScan Animation   Importing the libraries<jupyter_code>%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import sklearn<jupyter_output><empty_output><jupyter_text>Importing the dataset<jupyter_code>weather_df = pd.read_csv('weather-stations.csv')
print ("Shape of the DataFrame: ", weather_df.shape)
weather_df.head(3) 
weather_df.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 1341 entries, 0 to 1340
Data columns (total 25 columns):
 #   Column    Non-Null Count  Dtype  
---  ------    --------------  -----  
 0   Stn_Name  1341 non-null   object 
 1   Lat       1341 non-null   float64
 2   Long      1341 non-null   float64
 3   Prov      1341 non-null   object 
 4   Tm        1256 non-null   float64
 5   DwTm      1256 non-null   float64
 6   D         357 non-null    float64
 7   Tx        1260 non-null   float64
 8   DwTx      1260 non-null   float64
 9   Tn        1260 non-null   float64
 10  DwTn      1260 non-null   float64
 11  S         586 non-null    float64
 12  DwS       586 non-null    float64
 13  S%N       198 non-null    float64
 14  P         1227 non-null   float64
 15  DwP       1227 non-null   float64
 16  P%N       209 non-null    float64
 17  S_G       798 non-null    float64
 18  Pd        1227 non-null   float64
 19  BS        0 non-null      float64
 20  DwBS      0 non-null      floa[...]<jupyter_text>So there are 25 columns and now we need to learn more about the Columns, The names that are difficult to guess * Stn_Name === Station Name* Prov     === Province* Tm       === Mean Temperature (°C)* Tn       === Lowest Monthly Minimum Temperature * Tx       === Highest Monthly Maximum Temperature * DwTm     === Days Without Valid Mean Temperature* DwTx     === Days Without Valid Maximum Temperature* DwTn     === Days Without Valid Minimum Temperature* D        === Mean Temperature Difference from Normal* S        === Snowfall (cm)* DwS      === Days Without Snowfall* S%N      === Percent of Normal Snowfall* P        === Total Precipitation (mm)* DwP      === Days Without Valid Precipitation* P%N      === Percent of Normal Precipitation* Pd       === No. of days with precipitation 1mm or More * BS       === Bright Sunshine days* DwBS     === Days Without valid Bright Sunshine* BS%      === Percent of Normal Bright Sunshine* HDD      === Degree Days Below $18^{\circ}$C * CDD      === Degree Days Above $18^{\circ}$C* Stn_No   === Station Number; Climate Station Identifier (1st 3 Digits==Indicate drainage basin, Last 4 Digits Sorting Alphabetically)<jupyter_code># check the nan values in the dataframe 
weather_df.isna().sum()
weather_df.dropna(subset=['Tm', 'Tx', 'Tn'], inplace=True)
print ("After Dropping Rows that contains NaN on Mean, Max, Min Temperature Column: ", weather_df.shape)<jupyter_output>After Dropping Rows that contains NaN on Mean, Max, Min Temperature Column:  (1255, 25)
{'fraction_non_alphanumeric': 0.06865259420003945, 'fraction_numerical': 0.033339909252318015, 'mean_word_length': 3.1866226259289845, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '333441', 'license': 'MIT', 'n_tokens_mistral': 1558, 'n_tokens_neox': 1372, 'n_words': 669, 'path': 'DBScan/DBScan.ipynb', 'repo_name': 'SMSajadi99/Machine-Learning', 'size': '5084'}