Skip to content

Instantly share code, notes, and snippets.

View muhammadanas0716's full-sized avatar
👽
Alienating

Muhammad Anas muhammadanas0716

👽
Alienating
View GitHub Profile
@muhammadanas0716
muhammadanas0716 / Creating Captchas with Python.py
Created October 29, 2022 09:48
Creating Captchas with Python
from captcha.image import ImageCaptcha
# Set the image size
image = ImageCaptcha(width = 400, height = 200)
# Specify text for the Captcha
captcha_text = "Captcha_PYTHON"
# Generate the image with the given text
data = image.generate(captcha_text)
@muhammadanas0716
muhammadanas0716 / Displaying GridSearchCV results in a Pandas DataFrame.py
Created November 3, 2022 16:46
Displaying GridSearchCV results in a Pandas DataFrame
import pandas as pd
df = pd.read_csv('http://bit.ly/kaggletrain')
X = df[['Pclass', 'Sex']]
y = df['Survived']
from sklearn.preprocessing import OneHotEncoder
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.compose import make_column_transformer
@muhammadanas0716
muhammadanas0716 / Use ColumnTransformer to apply different preprocessing to different columns.py
Created November 4, 2022 14:43
Use ColumnTransformer to apply different preprocessing to different columns in ONE go.
import pandas as pd
df = pd.read_csv('http://bit.ly/kaggletrain', nrows=6)
cols = ['Fare', 'Embarked', 'Sex', 'Age']
X = df[cols]
from sklearn.preprocessing import OneHotEncoder
from sklearn.impute import SimpleImputer
from sklearn.compose import make_column_transformer
@muhammadanas0716
muhammadanas0716 / Using Pipelines.py
Created November 6, 2022 16:56
Using Pipelines
import pandas as pd
import numpy as np
from sklearn.impute import SimpleImputer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
train = pd.DataFrame({'feature1' : [10, 20, np.nan, 2], 'feature2': [25., 20, 5, 3], 'label':['A', 'A', 'B', 'B']})
test = pd.DataFrame({'feature1' : [30., 5, 15], 'feature2' :[ 12, 10, np.nan]})
@muhammadanas0716
muhammadanas0716 / scatterpots.py
Created January 9, 2023 16:06
Scatter Plot Code
# Import needed libraries
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
# Import dataset
midwest = pd.read_csv("https://raw.githubusercontent.com/selva86/datasets/master/midwest_filter.csv")
@muhammadanas0716
muhammadanas0716 / BubblePlot.py
Created January 10, 2023 15:57
Bubble plot with Encircling
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
# Specific imports
from matplotlib import patches
from scipy.spatial import ConvexHull
sns.set_style("white")
@muhammadanas0716
muhammadanas0716 / StripPlots.py
Created January 12, 2023 16:58
Jittering with stripplot
# Import Libararies
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
# Import Data
df = pd.read_csv("https://raw.githubusercontent.com/selva86/datasets/master/mpg_ggplot2.csv")
@muhammadanas0716
muhammadanas0716 / Count_Strip_Plots.py
Last active January 14, 2023 17:10
Another option to avoid the problem of points overlap is the increase the size of the dot depending on how many points lie in that spot. So, larger the size of the point more is the concentration of points around that.
# Imports
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
# Import Data
df = pd.read_csv("https://raw.githubusercontent.com/selva86/datasets/master/mpg_ggplot2.csv")
df_counts = df.groupby(['hwy', 'cty']).size().reset_index(name='counts')
@muhammadanas0716
muhammadanas0716 / Marginal Histograms
Created January 16, 2023 14:09
Marginal histograms have a histogram along the X and Y axis variables. This is used to visualize the relationship between the X and Y along with the univariate distribution of the X and the Y individually.
# Import Libararies
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
# Import Data
df = pd.read_csv("https://raw.githubusercontent.com/selva86/datasets/master/mpg_ggplot2.csv")
@muhammadanas0716
muhammadanas0716 / Marginal BoxPlots.py
Created January 19, 2023 10:12
Marginal boxplot helps to pinpoint the median, 25th, and 75th percentiles of the X and the Y.
# Import
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Import Data
df = pd.read_csv("https://raw.githubusercontent.com/selva86/datasets/master/mpg_ggplot2.csv")
# Create Fig and gridspec