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
To randomize a dataset: shuf=data.iloc[np.random.permutation(len(data))] | |
sh = shuf.reset_index(drop=true) | |
TO KNOW NULL | |
data.isnull().sum() | |
TO DELETE FROM DICT | |
del dna_counts['e'] | |
RAMDOM FOREST |
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 tensorflow as tf | |
from keras.backend.tensorflow_backend import set_session | |
config = tf.ConfigProto() | |
config.gpu_options.per_process_gpu_memory_fraction = 0.3 | |
set_session(tf.Session(config=config)) | |
By default system uses max GPU and that seems to return an error while training |
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
Threshold of 0.5 is used by default (for binary problems) to convert predicted probabilities into class predictions | |
Threshold can be adjusted to increase sensitivity or specificity | |
Sensitivity and specificity have an inverse relationship | |
Increasing one would always decrease the other | |
Adjusting the threshold should be one of the last step you do in the model-building process |
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
When you wanna sort | |
10 2 5 | |
7 1 0 | |
9 9 9 | |
1 23 12 | |
6 5 9 | |
with respect to element 1 (2,1,9,23,5) |
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
-------------------------------- | |
S = 'abcdef' | |
N = 3 | |
print(list(zip(*[iter(S)] * N))) | |
will Print: [('a','b','c'),('d','e','f')] | |
-------------------------------- | |
ROTATE AN LIST |
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
SALES WHERE SHOP_ID IS 26,27 OR 28 | |
sales = sales[sales['shop_id'].isin([26, 27, 28])] |
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
r'b[aeiou]{2}t' b followed by two vowels, followed by t | |
r'A\d{3,}' The letter A followed by 3 or more digits | |
r'[A-Z]{,5}' Zero to five capital letters | |
r'\w{3,7}' Three to seven “word” characters | |
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 psycopg2 | |
import random, string | |
hostname = 'localhost' | |
username = 'postgres' | |
password = '*****' | |
database = 'pgroute' | |
myConnection = psycopg2.connect(host=hostname, user=username, password=password, dbname=database ) | |
# Simple routine to run a query on a database and print the results: | |
def doQuery( conn, query ) : |
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 pandas as pd | |
import urllib.request | |
### GRAPHOPPER API ### | |
urlStart = 'http://localhost:8989/route/?' | |
point = 'point=' | |
urlEnd = '&type=gpx&instructions=false&vehicle=car' | |
separator = '%2C' | |
### SOURCE POINT ### |
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 yellowbrick.text import TSNEVisualizer,UMAPVisualizer | |
from sklearn.feature_extraction.text import TfidfVectorizer,CountVectorizer | |
def visualize(dim_reduction,encoding,corpus_data,corpus_target,labels = True,alpha=0.7,metric=None): | |
if 'tfidf' in encoding.lower(): | |
encode = TfidfVectorizer() | |
if 'count' in encoding.lower(): | |
encode = CountVectorizer() | |
docs = encode.fit_transform(corpus_data) | |
if labels is True: |
OlderNewer