Skip to content

Instantly share code, notes, and snippets.

View jetnew's full-sized avatar
♟️

Jet New jetnew

♟️
View GitHub Profile
@jetnew
jetnew / checkrighttriangle.c
Last active April 30, 2017 14:40
To check for right angled triangle
#include <stdio.h>
#include <cs50.h>
int main(void)
{
//declare function to check validity of right angled triangle
bool valid_righttriangle(float x, float y, float z)
{
//to check using Pythagoras' Theorem
if (x*x + y*y = z*z) || (x*x + z*z = y*y) || (y*y + z*z = x*x)
# Import library to use the function 'random.randint()'.
import random
# User-defined function to print list details.
def list_details(l_length, l_bound, u_bound):
# Create an empty list to load values in.
v_list = []
# Use a for-loop to append random integers into the list.
for i in range(l_length):
@jetnew
jetnew / main.py
Created April 19, 2018 12:43
Jet_New_Python_Project_2 created by GitHJet - https://repl.it/@GitHJet/JetNewPythonProject2
# Open the file "word_list.txt" as "word_file" for reading.
word_file = open("word_list.txt", "r")
# Use the read() function to store the contents of the file to word_list.
word_list = word_file.read()
# word_list is currently a string of all characters inside word_list.txt.
# We need to separate the characters into individual words and store it in an array.
# Because each word is separated by a newline character '\n', we use the split() function.
# Now, individual words can be accessed from the array 'word_array'.
@jetnew
jetnew / holt-winters-additive.py
Created June 1, 2019 16:32
Holt Winters additive using statsmodels
from statsmodels.tsa.holtwinters import ExponentialSmoothing
fit = ExponentialSmoothing(data, seasonal_periods=periodicity, trend='add', seasonal='add').fit(use_boxcox=True)
fit.fittedvalues.plot(color='blue')
fit.forecast(5).plot(color='green')
plt.show()
@jetnew
jetnew / arima.py
Last active June 1, 2019 17:41
ARIMA using statsmodels
from statsmodels.tsa.arima_model import ARIMA
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
p = 5 # lag
d = 1 # difference order
q = 0 # size of moving average window
train, test = train_test_split(X, test_size=0.20, shuffle=False)
history = train.tolist()
@jetnew
jetnew / k-means.py
Created June 1, 2019 18:16
K-Means using scikit-learn
from sklearn.cluster import KMeans
clusters = 3
y_pred = KMeans(n_clusters=clusters).fit_predict(X)
plt.scatter(X[:,0], X[:,1], c=y_pred)
plt.show()
@jetnew
jetnew / decision-tree.py
Last active June 1, 2019 18:30
Decision Tree using scikit-learn
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, shuffle=True)
clf = DecisionTreeClassifier()
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
@jetnew
jetnew / svm.py
Created June 1, 2019 18:33
SVM using scikit-learn
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, shuffle=True)
clf = SVC(gamma='auto')
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
@jetnew
jetnew / hbos.py
Created June 2, 2019 01:58
HBOS using kenchi
from kenchi.outlier_detection.statistical import HBOS
hbos = HBOS(novelty=True).fit(X)
y_pred = hbos.predict(X)
@jetnew
jetnew / hierarchical-clustering.py
Last active June 2, 2019 02:25
Hierarchical Clustering using scikit-learn and scipy
from sklearn.cluster import AgglomerativeClustering
clusters = 3
y_pred = AgglomerativeClustering(n_clusters=clusters).fit_predict(X)
from scipy.cluster.hierarchy import linkage, fcluster, dendrogram
clusters=5
cls = linkage(X, method='ward')