Skip to content

Instantly share code, notes, and snippets.

View KhyatiMahendru's full-sized avatar
👀
Look out, working on exciting things :)

Khyati Mahendru KhyatiMahendru

👀
Look out, working on exciting things :)
View GitHub Profile
from sklearn.metrics import silhouette_score
sil = []
kmax = 10
# dissimilarity would not be defined for a single cluster, thus, minimum number of clusters should be 2
for k in range(2, kmax+1):
kmeans = KMeans(n_clusters = k).fit(x)
labels = kmeans.labels_
sil.append(silhouette_score(x, labels, metric = 'euclidean'))
from sklearn.tree import DecisionTreeClassifier
clf_gini = DecisionTreeClassifier(criterion = 'gini', random_state = 33)
clf_gini.fit(X, Y)
from sklearn.tree import DecisionTreeClassifier
clf_entropy = DecisionTreeClassifier(criterion = 'entropy', random_state = 33)
clf_entropy.fit(X, Y)
from sklearn.datasets import make_regression
X, y = make_regression(n_samples = 20, n_features = 6, random_state = 2, noise = 0.5)
import statsmodels.api as sm
model = sm.OLS(y, X[:, 4]).fit()
model.summary()
# import dataset
import pandas as pd
data = pd.read_csv('mtcars.csv')
# remove string and categorical variables
cat_var = ['model', 'cyl', 'vs', 'am', 'gear', 'carb']
data = data.drop(cat_var, axis = 1)
# scale the variables to prevent coefficients from becoming too large or too small
from sklearn.preprocessing import MinMaxScaler
@KhyatiMahendru
KhyatiMahendru / creditcardfrauddetection.ipynb
Last active February 21, 2022 16:37
CreditCardFraudDetection.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from sklearn.decomposition import PCA
// say you want to reduce to 2 features
pca = PCA(n_components = 2)
// obtain transformed data
data_transformed = pca.fit_transform(data)
# import required libraries
import numpy as np
import matplotlib.pyplot as plt
import cv2
from skimage.color import rgb2gray
from scipy import ndimage
# read the image
img = cv2.imread('1.jpeg')
from sklearn.decomposition import TruncatedSVD
// say you want to reduce to 2 features
svd = TruncatedSVD(n_features = 2)
//obtain the transformed data
data_transformed = svd.fit_transform(data)