Skip to content

Instantly share code, notes, and snippets.

@sithu
sithu / UdpServer.kt
Created November 29, 2017 09:29 — forked from codingtim/UdpServer.kt
Simple udp server with netty 4.1 and kotlin
import io.netty.bootstrap.Bootstrap
import io.netty.channel.ChannelHandlerContext
import io.netty.channel.SimpleChannelInboundHandler
import io.netty.channel.nio.NioEventLoopGroup
import io.netty.channel.socket.nio.NioDatagramChannel
import io.netty.util.CharsetUtil
import io.netty.util.concurrent.DefaultThreadFactory
import kotlinx.coroutines.experimental.async
import kotlinx.coroutines.experimental.newFixedThreadPoolContext

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]
@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')
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