Prettify-Error
error_string = """
{
"error": {
"error_code": 1002,
"error_message": "Unspecified Error",
"details": "Unexpected error: ['Traceback (most recent call last):', ' File \"/home/rajaraman/rprojects/ml-api-work/ml-api-raja/services/mlapi/app/main.py\", line 228, in post_predict_classic_joblib_api', ' result_obj = await label_generator.match_with_multi(', ' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^', ' File \"/home/rajaraman/rprojects/ml-api-work/ml-api-raja/services/mlapi/app/label_generator.py\", line 770, in match_with_multi', ' feature_scores …
Read More
Prettify-Xml
title: "Prettify XML"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
import xmltodict
import pprint
import json
import xml.dom.minidom
dom = xml.dom.minidom.parse('sample.xml') # or xml.dom.minidom.parseString(xml_string)
pretty_xml_as_string = dom.toprettyxml()
'<?xml version="1.0" ?>\n<note>\n\t\n …
Read More
Pretty Print Json
title: "Pretty Print Json"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
import json
import pprint
content = """{"system": {"commit": None, "python": "3.6.8.final.0", "python-bits": 64, "OS": "Darwin", "OS-release": "18.5.0", "machine": "x86_64", "processor": "i386", "byteorder": "little", "LC_ALL": "None", "LANG": "en_CA.UTF-8", "LOCALE": "en_CA …
Read More
Pretty Print Online Json
title: "Pretty Print Online JSON"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
import pprint
import json
from urllib.request import urlopen
r = urlopen("https://mdn.github.io/fetch-examples/fetch-json/products.json")
text = r.read()
pprint.pprint(json.loads(text))
{'products': [{'Location': 'Refrigerated foods',
'Name': 'Cheese',
'Price …
Read More
Print-Filenames
title: "Print Filenames"
author: "Rj"
date: 2019-04-21
description: "-"
type: technical_note
draft: false
from os import walk
from os import listdir
from os.path import isfile, join
onlyfiles = [f for f in listdir(path) if isfile(join(path, f))]
['.BBE72B41371180178E084EEAF106AED4F350939DB95D3516864A1CC62E7AE82F']
for fle in onlyfiles:
print(fle)
.BBE72B41371180178E084EEAF106AED4F350939DB95D3516864A1CC62E7AE82F
Score …
Read More
Print In Tensorflow
title: "Print in Tensorflow"
author: "Raja CSP Raman"
date: 2019-05-07
description: "-"
type: technical_note
draft: false
import tensorflow as tf
import os
# Just disables the warning, doesn't enable AVX/FMA
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
a = tf.Variable([[1, 2, 3]])
init = (tf.global_variables_initializer(), tf.local_variables_initializer())
Read More
Print Tensorflow
title: "Print in Tensorflow"
author: "Raja CSP Raman"
date: 2019-05-07
description: "-"
type: technical_note
draft: false
import tensorflow as tf
import os
# Just disables the warning, doesn't enable AVX/FMA
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
sess = tf.InteractiveSession()
<tensorflow.python.client.session.InteractiveSession at 0x12b796668>
Read More
Print Values
title: "Print Values"
author: "Raja CSP Raman"
date: 2019-05-07
description: "-"
type: technical_note
draft: false
import tensorflow as tf
import os
# Just disables the warning, doesn't enable AVX/FMA
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
normal_rv = tf.Variable(tf.truncated_normal([2, 3], stddev=0.1))
# Initialize the variables
init_op = tf.initialize_all_variables()
Read More
Product-Summary-Classification-Nb
title: "Text Classification - Naive Bayes - Product Summary"
author: "Rj"
date: 2019-04-21
description: "-"
type: technical_note
draft: false
# Disclaimer: some code copied form this https://towardsdatascience.com/multi-class-text-classification-model-comparison-and-selection-5eb066197568
import logging
import pandas as pd
import numpy as np
from numpy import random
import gensim
import nltk
from sklearn.model_selection import train_test_split
from …
Read More
Py-Ml-Tips-Rules
title: "Py ML Tips and Rules"
author: "Rj"
date: 2019-04-21
description: "-"
type: technical_note
draft: false
Numpy Indexing
Numpy indexing for one-dimensional arrays works similarly to Python lists using the square-bracket notation. For two-dimensional arrays, the first index refers to the row number, and the indexer to the column number.
Score …
Read More