This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kenchi.outlier_detection.statistical import HBOS | |
hbos = HBOS(novelty=True).fit(X) | |
y_pred = hbos.predict(X) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
OlderNewer