Visualising Multidimensional Data and Measuring Correlation
Visualising Multidimensional Data and Measuring Correlation123456789import numpy as npimport pandas as pdbody = pd.read_csv("https://raw.githubusercontent.com/gagolews/" + "teaching-data/master/marek/nhanes_adult_female_bmx_2020.csv", comment="#")body = body.to_numpy() # data frames will be covered laterbody.shapebody[:6, :] # 6 first rows, all columns Scatterplots2D Data1234567891011import matplotlib.pyplot as pltimport seaborn as snsplt.style.use("...
Handling Categorical Data
Handling Categorical DataRepresenting Categorical DataTwo common ways to represent a categorical variable with k distinct levels is by storing it as: a vector of strings, a vector of integers between 0 (inclusive) and k (exclusive). 12345678import numpy as npcountries = np.loadtxt("https://raw.githubusercontent.com/gagolews/" + "teaching-data/master/marek/37_pzu_warsaw_marathon_country.txt", dtype="str")x = countries[:16]xnp.unique(x) Encoding and Decodin...
Inspecting the Distribution of Numberic Data
Inspecting the Distribution of Numberic Data12345import numpy as npheights = np.loadtxt("https://raw.githubusercontent.com/gagolews/" + "teaching-data/master/marek/nhanes_adult_female_height_2020.txt")np.random.choice(heights, 24, replace=False) Histograms1234567import matplotlib.pyplot as pltimport seaborn as snsplt.style.use("seaborn")sns.__version__ # FYIsns.histplot(heights, bins=11)plt.show() 1234income = np.loadtxt("https://raw.githubusercontent.co...
Descriptive Statistic for Continuous Data
Descriptive Statistic fopr Continuous DataHistograms are based on binned data and hence provide us with snapshots of how much probability mass is allocated in diferent parts of the data domain. 1234567import numpy as npincome = np.loadtxt("https://raw.githubusercontent.com/gagolews/" + "teaching-data/master/marek/uk_income_simulated_2020.txt")b = [0, 10000, 20000, 30000, 40000, 50000, 60000, 80000, np.inf] # bin boundsc = np.histogram(income, bins=b)[0] # countsfor i ...
Python - Basic Usage of Data Analysis
Basic Usage of Data AnalysisGetting Started with JupyterLabJupyterLab is a web-based development environment supporting numerous programming languages, including, of course, Python. jupyterlab Scalar Types in PythonBasic Operations on Data Framesdoc pre-requisite123import numpy as npimport pandas as pdpd.set_option("display.notebook_repr_html", False) # disable "rich" output Aggregating1234567891011121314151617181920np.random.seed(123)d = pd.DataFrame(dict( u = np.roun...
Hello Prisma
Connecting Prisma application to Supabase PostgresCreste a custom user fro Prismacreate a Prisma DB user with full privileges on the public schema123456789101112131415-- Create custom usercreate user "prisma" with password 'custom_password' bypassrls createdb;-- extend prisma's privileges to postgres (necessary to view changes in Dashboard)grant "prisma" to "postgres";-- Grant it necessary permissions over the relevant schemas (public)grant usage o...
Leetcode - 135. Candy
DescriptionThere are n children standing in a line. Each child is assigned a rating value given in the integer array ratings. You are giving candies to these children subjected to the following requirements: Each child must have at least one candy. Children with a higher rating get more candies than their neighbors. Return the minimum number of candies you need to have to distribute the candies to the children. 12345Example 1:Input: ratings = [1,0,2]Output: 5Explanation: You can allocate to...
Leetcode - 169. Majority Element
DescriptionGiven an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. Example 1:12Input: nums = [3,2,3]Output: 3 Example 2:12Input: nums = [2,2,1,1,1,2,2]Output: 2 Constraints:123n == nums.length1 <= n <= 5 * 104-109 <= nums[i] <= 109The input is generated such that a majority element will exist in the array. Approach123456789101112class S...
Leetcode - 205. Isomorphic Strings
DescriptionGiven two strings s and t, determine if they are isomorphic. Two strings s and t are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself. Approach12345678910111213141516class Solution: def isIsomorphic(self, s: str, t: str) -> bool: char_index_s = {} c...
Leetcode - 392. Is Subsequence
DescriptionGiven two strings s and t, return true if s is a subsequence of t, or false otherwise.A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., “ace” is a subsequence of “abcde” while “aec” is not). Example 1: 12Input: s = "abc", t = "ahbgdc"Output: true Example 2: 12Input: s = "axc", t = "ahbgdc&qu...






