Skip to content

Instantly share code, notes, and snippets.

View threecifanggen's full-sized avatar
😮‍💨
Go Go!

Huang Baochen threecifanggen

😮‍💨
Go Go!
  • StateStreet (Hanzhou, China)
  • Hangzhou, China
  • 15:57 (UTC +08:00)
View GitHub Profile
@threecifanggen
threecifanggen / bland.altman.plot.r
Created October 18, 2022 09:54
[Bland-Altman 一致性检验曲线] 基于R和ggplot实现的Bland-Altman曲线绘制 #bland-altman #r #ggplot2 #medical-analysis #stat
plot.ggbland <- function(df, alpha = 0.05) {
z_score = qnorm(1 - alpha/2)
temp_df <- df %>%
mutate(diff = `mEDV` - `sEDV`) %>%
mutate(avg = (`mEDV`+ `sEDV`)/ 2)
mean_diff <- mean(temp_df$diff)
lower <- mean_diff - z_score * sd(temp_df$diff)
upper <- mean_diff + z_score * sd(temp_df$diff)
ggplot(temp_df, aes(x = avg, y = diff)) +
geom_point(size=2) +
@threecifanggen
threecifanggen / wilcoxon_test_example.py
Last active October 12, 2022 06:24
[单样本Wilcoxon检验] 用`Python`实现的Wilcoxon检验 #wilcoxon #python #one-sample-test
"""
### 例子
正常男性尿检中位数$M_0$为$0.33\mu mol/L$,抽取工厂血铅含量如下,求是否符合正常。
"""
import statsmodels.stats as sts
M_0 = 0.33
M = [0.29, 0.31, 0.34, 0.37, 0.38, 0.41, 0.47, 0.52, 0.69, 0.72, 0.73, 0.77, 0.78, 0.80, 0.83, 0.92, 0.95, 0.97]
sts.descriptivestats.sign_test(M, M_0) # (7.0, 0.001312255859375) 有显著差异
@threecifanggen
threecifanggen / t_one_sample.py
Created October 12, 2022 06:11
[单样本t检验] 用`Python`实现的单样本t检验 #t-test #python #stats
import numpy as np
import scipy.stats as st
from statsmodels import api
ALPHA = 0.05
x = [1.29, 1.30, 1.32, 1.33, 1.34, 1.37, 1.40, 1.43, 1.45, 1.49, 1.53, 1.58, 1.63]
t_x = (np.mean(x) - 1.48) / (np.std(x) / np.sqrt(len(x)))
standard_t = st.t.ppf(1 - ALPHA/2, len(x) - 1)
@threecifanggen
threecifanggen / LibraryInter.scala
Created March 16, 2022 10:31
计算去图书馆时段的交集
/*
如学生去图书馆,他一天内什么时候都可以去,另一个人也是,求他俩同时在图书馆的时间段
*/
def libraryInterTime(a: List[(Int, Int)], b: List[(Int, Int)]): List[(Int, Int)] = {
def helper(a: List[Tuple2[Int, Int]], b: List[Tuple2[Int, Int]], res: List[(Int, Int)]): List[(Int, Int)] = {
if (a.length == 0 ||b.length == 0) {return res} // 如果有一个为空就停止计算
else {
val (setA, setB) = (a.head, b.head)
if (setA._2 <= setB._1) {
return helper(a.tail, b, res) // 如果setA整个在setB前面
@threecifanggen
threecifanggen / markdown.json
Last active January 21, 2022 03:41
[MyST的Snippet] 我的VSCODE中的MyST MD的Code Snippet #markdown #myst-markdown #vscode #code-snippet
{
// Place your snippets for markdown here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
@threecifanggen
threecifanggen / sympy_bugs.md
Last active October 12, 2022 06:39
[一些sympy的坑]一些sympy的坑 #python #sympy

1. Float相关

  1. Float无法转成Decimal类型,这个在一些数据很大,需要做图的地方可能会成为问题。
  2. Float没有找到提取指数的地方

2. integer参数

可以用下面方法设定符号为整数:

@threecifanggen
threecifanggen / streamlit_image.md
Created December 27, 2021 04:04
[Streamlit使用图片] `streamlit`使用图片使用方法 #streamlit #python

streamlit无法直接使用image的地址来读取,要使用PIL读取数据后展示:

from PIL import Image

fire_dir = "/dir/to/image"
image = Image.open(fire_dir)
st.image(image)
@threecifanggen
threecifanggen / split_int.py
Created December 24, 2021 05:59
[Python 拆分整数] 用python拆分整数的函数 #python
from typing import List
from math import log10, ceil
def split_int(a: int) -> List[int]:
retrurn [a // 10 ** i % 10 for i in range(ceil(log10(a))-1, -1, -1)]
@threecifanggen
threecifanggen / celeba_gane.md
Last active December 24, 2021 05:56
[pytorch celebA全连接GAN] CelebA使用`pytorch`实现全连接的GAN #pytorch #python #GAN #CelebA
from typing import NoReturn
import torch.nn as nn
import torch
import plotly.express as px
import pandas as pd

class View(nn.Module):
    def __init__(self, *shape):
        super().__init__()