Dataype Downcasting

Fri 14 November 2025

title: "Datatype Downcasting" author: "Rj" date: 2019-04-24 description: "-" type: technical_note draft: false


import numpy as np
import pandas as pd
ds = pd.Series([1, np.nan, 3, 4, 5])
ds
0    1.0
1    NaN
2    3.0
3    4.0
4    5.0
dtype: float64
# ds = ds.astype('int …

Category: data-wrangling

Read More

Date-Maker-1

Fri 14 November 2025
import pyutil as pyu
pyu.get_local_pyinfo()
'conda env: ml312-2024; pyv: 3.12.7 | packaged by Anaconda, Inc. | (main, Oct  4 2024, 13:27:36) [GCC 11.2.0]'
# will be used in MyWalks
# https://docs.google.com/spreadsheets/d/1WZOx71Pg7Id_dd6wLRDQbmS8ZDaRdkMQIwltM6vFTX8/edit?gid=0#gid=0
from datetime import datetime …

Category: basics

Read More

Date-Util

Fri 14 November 2025

title: "Date Util" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


import datetime
now = datetime.datetime.now()
print(now.year)
2019
print (now.strftime("%y"))
19
print (now.strftime("%d"))
21
print (now.strftime("%m"))
04
print(datetime.datetime.today())
2019-04-21 18:34:57.280555
cur_date = datetime …

Category: basics

Read More

Decision-Tree-Graph

Fri 14 November 2025

title: "Decision Tree Graph" author: "Rj" date: 2019-04-21 description: "-" type: technical_note draft: false


import pydotplus
from sklearn.datasets import load_iris
from sklearn import tree
import collections
# Data Collection
#heigh, length of hair, voice pitch
X = [ [180, 15,0],     
      [177, 42,0],
      [136, 35,1],
      [174, 65,0],
      [141, 28,1 …

Category: sklearn

Read More

Decision-Tree-Prediction

Fri 14 November 2025

title: "Decision Tree Prediction" author: "Raja CSP Raman" date: 2019-04-20 description: "-" type: technical_note draft: false


from sklearn import tree
X = [[0, 0], [2, 2]]
y = [0.5, 2.5]
clf = tree.DecisionTreeRegressor()
clf = clf.fit(X, y)
predicted = clf.predict([[1, 1]])
print(predicted)
[0.5]


Score: 5

Category: basics

Read More

Decision-Tree-Regression

Fri 14 November 2025

title: "Decision Tree Regression" author: "Raja CSP Raman" date: 2019-04-20 description: "-" type: technical_note draft: false


import numpy as np
from sklearn.tree import DecisionTreeRegressor
import matplotlib.pyplot as plt
# Create a random dataset
rng = np.random.RandomState(1)
X = np.sort(5 * rng.rand(80, 1), axis=0)
y = np …

Category: basics

Read More

Decorator

Fri 14 November 2025

title: "Decorator" author: "Raja CSP Raman" date: 2019-04-20 description: "-" type: technical_note draft: false


def rangetest(*argchecks):                  # validate positional arg ranges
    def onDecorator(func):
        def onCall(*args):
            print('argchecks : '+str(argchecks))
            for (ix, low, high) in argchecks:
                print('ix : '+str(ix))
                if args[ix] < low or args[ix] > high:
                    errmsg = 'Argument …

Category: basics

Read More

Decorator-Sample-2

Fri 14 November 2025

title: "Decorator Sample 2" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


class my_decorator(object):

    def __init__(self, f):
        print("inside my_decorator.__init__()")
        f() # Prove that function definition has completed

    def __call__(self):
        print("inside my_decorator.__call__()")
@my_decorator
def aFunction():
    print("inside aFunction()")
inside my_decorator.__init__()
inside aFunction()
print …

Category: basics

Read More

Deeptranslate-1

Fri 14 November 2025

import pyutil as pyu
pyu.get_local_pyinfo()
'conda env: ml311; pyv: 3.11.10 (main, Oct  3 2024, 07:29:13) [GCC 11.2.0]'
# !pip install deep-translator
print(pyu.ps2("deep-translator faker"))
deep-translator==1.11.4
faker==33.1.0

from deep_translator import GoogleTranslator

# Your contents
contents = [
    "Hello, how are …

Category: mythraki

Read More

Default-Dict

Fri 14 November 2025

title: "Default Dict" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false source: https://www.accelebrate.com/blog/using-defaultdict-python/


from collections import defaultdict
user = defaultdict(lambda: 'Kevin')
user
defaultdict(<function __main__.<lambda>>, {})
type(user)
collections.defaultdict
user['abc']
'Kevin'
user['country']
'Kevin'
user['name'] = 'Peter'
user['age'] = 21 …

Category: basics

Read More
Page 97 of 146

« Prev Next »