Mermaid

I was told by a JD Long at a recent conference where I brought up Code2Flow that Mermaid could be used just like Code2Flow within R/Github/etc to draw flowcharts, but it also has other functions that makes it a more generally useful program. Thanks James! Mermaid is also accessible within R Studio so I can try it here. Mermaid Live Editor at https://mermaid.live/edit# Simple Mermaid diagram In R Studio, DiagrammeR would be the package to install for producing Mermaid graphics. [Read More]

ChatGPT Shiny R app

This is a simple integration of ChatGPT into shiny R. At first I wanted to do this in Python but it was easier to do a web app in R Shiny. I used code from this site to get started: https://www.listendata.com/2023/05/chatgpt-in-r.html#steps_to_run_chatgpt_in_r The app is hosted at: https://twong.shinyapps.io/chat_bot/ The R code for this shiny app is below. library(shiny) library(httr) ui <- fluidPage( titlePanel("ChatGPT Shiny App"), textInput("user_input", "Enter your message:"), actionButton("submit_btn", "Submit"), p(""), textOutput("chat_output"), p(""), p("Code for this page is at https://codelooper. [Read More]

ChatGPT python code for distribution fitting

I asked ChatGPT for some python code to do distribution fitting and this is what it provided. I think I needed to edit it to fix some errors but it’s a nice solution. First, I wanted to put in some R code that will allow me to display the results in blogdown, which is what I’m using to post to this site. library(knitr) library(reticulate) knitr::knit_engines$set(python = reticulate::eng_python) The following python code was used for distribution fitting. [Read More]

Coursera Guided Project - Predicting Diabetes

Most people have better things to do on a Saturday night after the kids are asleep. Well, this is my idea of a fun evening… Signing up for the guided project in predicting diabetes by using random forests. Here we go… Course Objectives In this course, we are going to focus on four learning objectives: Complete a random Training and Test set from one Data source using both an R function and using Base R. [Read More]

Completed the Deeplearning.ai Tensorflow for AI course

I took Andrew Ng’s ML course on Coursera in 2015, but the landscape has changed since then. The 2015 course had us build a neural network from scratch using matrix multiplication using Octave (open-source Matlab). Now in 2022 it’s taught using python, tensorflow, and Keras API rather than using matrix multiplication. This course is better if you just want to apply machine learning or learn what’s involved. This course allows you to do more in less time, but you come away with a fuzzier idea of what’s happening in the neural network. [Read More]

Coursera - introduction to tensorflow

Week 1 Assignment: Housing Prices In this exercise you’ll try to build a neural network that predicts the price of a house according to a simple formula. Imagine that house pricing is as easy as: A house has a base cost of 50k, and every additional bedroom adds a cost of 50k. This will make a 1 bedroom house cost 100k, a 2 bedroom house cost 150k etc. How would you create a neural network that learns this relationship so that it would predict a 7 bedroom house as costing close to 400k etc. [Read More]

Python - Handling Exceptions

From: LinkedIn course ‘Python Essential Training’ by Ryan Mitchell https://www.linkedin.com/learning/python-essential-training-14898805 Try, except, finally import time as time def causeError(): start = time.time() #set start timer try: #delay run by 0.5 secs time.sleep(0.5) return 1/0 except Exception: print('There was some sort of error!') finally: print(f'Function took {time.time() - start} seconds to execute') causeError() ## There was some sort of error! ## Function took 0.5048558712005615 seconds to execute Custom Decorators *args **kwargs are multiple arguments or string arguments. [Read More]
Python 

Python - Multithreading/Multiprocessing

From: LinkedIn course ‘Python Essential Training’ by Ryan Mitchell https://www.linkedin.com/learning/python-essential-training-14898805 import threading import time Threads def longSquare(num): time.sleep(1) return num**2 [longSquare(n) for n in range(0, 5)] ## [0, 1, 4, 9, 16] t1 = threading.Thread(target=longSquare, args=(1,)) #args is tuple t2 = threading.Thread(target=longSquare, args=(2,)) t1.start() t2.start() t1.join() t2.join() def longSquare(num, results): time.sleep(1) results[num] = num**2 results = {} t1 = threading.Thread(target=longSquare, args=(1, results)) #args are tuples t2 = threading.Thread(target=longSquare, args=(2, results)) t1. [Read More]
Python 

Python - opening reading writing files

From: LinkedIn course ‘Python Essential Training’ by Ryan Mitchell https://www.linkedin.com/learning/python-essential-training-14898805 reading files f = open('some_file.txt','r') print(f) #gets file type, need to read the file f.readline() f.readlines() #puts lines into list of strings for line in f.readlines(): print(line.strip()) # strips leading and trailing spaces writing files f = open('somefiles.txt','w') # creates a file f.write('Line 1\n') f.write('Line 2\n') f.close() # python doesn't write until you close or run out of buffer and will overwrite existing text appending files [Read More]
Python