Skip to content

Instantly share code, notes, and snippets.

Hello World

from sklearn.datasets import make_blobs
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
import numpy as np
from matplotlib import cm
from sklearn.metrics import silhouette_samples
import pandas as pd
from scipy.spatial.distance import pdist, squareform
from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
import utils
from sklearn.tree import DecisionTreeClassifier
from sklearn import tree
np.random.seed(0)
import numpy as np
from matplotlib import pyplot
# Some functions to plot our points and draw the lines
def plot_points(features, labels, fix_margins=True):
X = np.array(features)
y = np.array(labels)
spam = X[np.argwhere(y==1)]
ham = X[np.argwhere(y==0)]
if fix_margins:
description: Change BigQuery table permission
group: cli_gcp_qb
cmd: gsutil [table_name] [service_account]
import pandas as pd
import numpy as np
from matplotlib import pyplot
# Some functions to plot our points and draw the lines
def plot_points(features, labels):
X = np.array(features)
y = np.array(labels)
spam = X[np.argwhere(y==1)]
ham = X[np.argwhere(y==0)]
# Loading the one_circle dataset
# ploy_svm.csv: https://gist.github.com/sithu/1a3c2dfbca74540fb2ee5a1aca1c4a0f
circular_data = pd.read_csv('poly_svm.csv')
features = np.array(circular_data[['x_1', 'x_2']])
labels = np.array(circular_data['y'])
utils.plot_points(features, labels)
# TODO: Degree = 2 vs Degree = 4
# Which one gives better accuracy?
svm_degree_2 = SVC(kernel='poly', degree=2)
x_1 x_2 y
0 -0.759415996185977 2.7532400952557747 0
1 -1.8852779019387766 1.6295265391438516 0
2 2.46330243466849 -1.023868884412727 0
3 -1.9860041519965943 -0.8988097871506215 0
4 2.0108340318241424 -2.58011744859958 0
5 2.4101875198381917 2.370500867155556 0
6 1.5991400471635622 -0.8627316166103238 0
7 -1.109856441968584 -2.4696974604953335 0
8 2.447341902744885 2.8111799446840005 0
@sithu
sithu / svm.py
Last active April 6, 2022 00:56
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# https://gist.github.com/sithu/4722649d23c83440f2067ed429fa434b
import utils
from sklearn.svm import SVC
# Loading the linear dataset
# linear.csv: https://gist.github.com/sithu/701d1182d63b01e740bb244d8059ceb1
linear_data = pd.read_csv('linear.csv')
x_1 x_2 y
0 -2.9215421587612864 -2.9240927587498557 0
1 0.1367823452479766 0.5404018260196919 1
2 2.7472957442884027 1.547236841959032 1
3 -2.780707006283153 -2.673130701821511 0
4 2.0304211973846185 1.3294522550124075 1
5 -0.314170015192591 -2.591670461555064 0
6 -1.8962190518539415 -0.5169526296813127 0
7 1.4321480571961844 0.8410803230124659 1
8 0.8859891385888985 2.4247415377997505 1