Skip to content

Instantly share code, notes, and snippets.

View xoraus's full-sized avatar
🎯
Focusing

Sajjad Salaria xoraus

🎯
Focusing
View GitHub Profile
@xoraus
xoraus / get_twitter_user_following_list.js
Created March 14, 2023 13:35
This is a Node.js script that uses the Twitter API to retrieve a list of users that the authenticated user is following, and then writes the data to a CSV file.
const Twitter = require('twitter');
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
const fs = require('fs');
// set up Twitter API client
const client = new Twitter({
// consumer_key: 'your_consumer_key',
// consumer_secret: 'your_consumer_secret',
// access_token_key: 'your_access_token_key',
// access_token_secret: 'your_access_token_secret'
# Initialize and fit KMeans algorithm
kmeans = MiniBatchKMeans(n_clusters = 36)
kmeans.fit(X)
# record centroid values
centroids = kmeans.cluster_centers_
# reshape centroids into images
images = centroids.reshape(36, 28, 28)
images *= 255
def infer_cluster_labels(kmeans, actual_labels):
inferred_labels = {}
for i in range(kmeans.n_clusters):
# find index of points in cluster
labels = []
index = np.where(kmeans.labels_ == i)
# append actual labels for each point in cluster
from sklearn.cluster import MiniBatchKMeans
n_digits = len(np.unique(y_test))
print(n_digits)
# Initialize KMeans model
kmeans = MiniBatchKMeans(n_clusters = n_digits)
# Fit the model to the training data
# convert each image to 1 dimensional array
X = x_train.reshape(len(x_train),-1)
Y = y_train
# normalize the data to 0 - 1
X = X.astype(float) / 255.
print(X.shape)
from keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
print(‘Training Data: {}’.format(x_train.shape))
print(‘Training Labels: {}’.format(y_train.shape))
Training Data: (60000L, 28L, 28L)
Training Labels: (60000L,)
import sys
import sklearn
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
print(‘Python: {}’.format(sys.version))
print(‘Sklearn: {}’.format(sklearn.version))
print(‘Matplotlib: {}’.format(matplotlib.version))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@xoraus
xoraus / ML
Last active August 17, 2019 20:16
# check package versions
import sys
import keras
import cv2
import numpy
import matplotlib
import skimage
print('Python: {}'.format(sys.version))
print('Keras: {}'.format(keras.__version__))