Understanding the plot from coxph and comparing it with Surv in R - survival-analysis

I am trying to understand what I am seeing from the output of coxph in R.
In the following replicatiable code:
`library(survival)
library(ggfortify)
#Kaplan-Meier
kmfit = survfit(Surv(time, status)~sex, data=lung)
autoplot(kmfit, conf.int = F) #two lines, one for each gender
`
enter image description here
`#coxph
coxfit = survfit(coxph(Surv(time, status)~sex, data=lung))
autoplot(coxfit)
`
enter image description here
Why do I only see 1 line? Should I be seeing two lines? How can I get 2 lines?

Related

How to get the highest dominant color from google cloud vision api in python?

I have a list of .jpg images and i am trying to extract the dominant color from google cloud vision API -
https://cloud.google.com/vision/docs/drag-and-drop
The below piece of function sometimes extracts the correct RGB values but sometimes it extracts incorrect RGB values as well. What should i change in the below code so that it always picks the dominant color with highest RGB percentage. i.e the first RGB value from the left.
def dominat_color(image):
response = client.image_properties(image=image)
props = response.image_properties_annotation
max_frac=0.0
#print('Properties:', props.dominant_colors.colors[0].red,",",props.dominant_colors.colors[0].green,",",props.dominant_colors.colors[0].blue,",",dominant_colors.colors[0].pixel_fraction)
for color in props.dominant_colors.colors:
var1=float(color.pixel_fraction)*100
#var1=float(color.percent)
if (var1 > max_frac):
max_frac=var1
var2=int(color.color.red)
var3=int(color.color.green)
var4=int(color.color.blue)
#print("\nRGB: ", var2,",",var3,",",var4,",", (var1))
if response.error.message:
raise Exception(
'{}\nFor more info on error messages, check: '
'https://cloud.google.com/apis/design/errors'.format(
response.error.message))
return var2,var3,var4
creds = service_account.Credentials.from_service_account_file(r'xxxx.json') #credentials
client = vision.ImageAnnotatorClient(credentials=creds,)
Sample Output:
Image_name Red Green Blue
k1.jpg 240 125 16
The red,green and blue values should be the left most RGB values
in gcp --> https://cloud.google.com/vision/docs/drag-and-drop
under properties tab i am just trying to extract the first RGB values from the left.
For your requirement, you can use a list in python to store the values and find the dominant value from the left. You can check the below sample code which you can use for your use case.
Code :
def dominat_color(image):
from google.cloud import vision
import io
client = vision.ImageAnnotatorClient()
image_uri = image
image = vision.Image() # Py2+3 if hasattr(vision, 'Image') else vision.types.Image()
image.source.image_uri = image_uri
response = client.image_properties(image=image)
props = response.image_properties_annotation
#print('Properties:', props.dominant_colors.colors[0].red,",",props.dominant_colors.colors[0].green,",",props.dominant_colors.colors[0].blue,",",dominant_colors.colors[0].pixel_fraction)
max_frac=0.0
lst = []
for color in props.dominant_colors.colors:
var1=float(color.pixel_fraction)*100
if (var1 > max_frac):
max_frac = var1
var2=int(color.color.red)
lst.append(var2)
var3=int(color.color.green)
lst.append(var3)
var4=int(color.color.blue)
lst.append(var4)
rmax = max(lst)
index = lst.index(rmax)
print(lst[index],lst[index+1],lst[index+2])
if response.error.message:
raise Exception(
'{}\nFor more info on error messages, check: '
'https://cloud.google.com/apis/design/errors'.format(
response.error.message))
dominat_color(image_path)
Output :

pytorch-kaldi timit tutorial error shared_list[0] IndexError: list index out of range

# ***** Reading the Data********
if processed_first:
#Reading all the features and labels for this chunk
shared_list = []
p = threading.Thread(target=read_lab_fea, args=(cfg_file, is_production, shared_list, output_folder))
p.start()
p.join()
data_name = shared_list[0]
data_end_index = shared_list[1]
fea_dict = shared_list[2]
lab_dict = shared_list[3]
arch_dict = shared_list[4]
data_set = shared_list[5]
enter image description here
First I did run kaldi's run.sh file
When I did that, I corrected cmd.sh's contents.
Original --> call queue.pl
to --> call run.pl
Because I met bug when i run original source
Reference : https://www.google.com/url?q=https://groups.google.com/g/kaldi-help/c/tokwXTLdGFY?pli%3D1&sa=D&source=editors&ust=1631002151871000&usg=AOvVaw1FYQHJEmI-kkAAeAB2tcKt
enter image description here
I found that fea_dict and lab_dict in data_io.py has no shared element. How can I progress the TIMIT tutorial experiments?
I'm doing experiment using cfg/TIMIT_baselines/TIMIT_MLP_mfcc_basic.cfg file. Just correcting absolute directory of linux.
I refered https://github.com/mravanelli/pytorch-kaldi/issues/185
run copy-feats.
I saw--> kaldierror::KaldiFatalError

Define number of decimal places that appears in the cbar with seaborn.kdeplot

From the following code:
penguins = sns.load_dataset("penguins")
g = sns.PairGrid(penguins)
g.map_upper(sns.histplot,)
g.map_lower(sns.kdeplot, fill=True,cbar=True)
g.map_diag(sns.histplot, kde=True, cbar=True)
the legend bar has between 3 and 5 decimal places and I would like it to only have 2. I have tried using the following code but it keeps giving me errors.
g.cbar.ax.yaxis.set_major_formatter(tick.FormatStrFormatter('%.2f'))
The error that occurs is: 'PairGrid' object has no attribute 'cbar'
You may try this:
g.map_lower(sns.kdeplot, fill=True,cbar=True,cbar_kws = dict(format = '%.2f'))
g.map_diag(sns.histplot, kde=True, cbar=True,cbar_kws = dict(format = '%.2f'))

Add comma after volume when no issue number biblatex

For the bibliography of my thesis I want to add a comma after the volume number when a journal article has no issue number present.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xpatch}
\usepackage[backend=biber, citestyle=nejm, sorting=none, natbib=true, isbn=false, url=false, doi=true, eprint = false, giveninits]{biblatex}
% remove pp
\DeclareFieldFormat{pages}{#1}
% No dot before number of articles
\xpatchbibmacro{volume+number+eid}{%
\setunit*{\adddot}%
}{%
}{}{}
% Number of articles in parentheses
\DeclareFieldFormat[article]{number}{\mkbibparens{#1}\addcomma}
% Comma before date; date not in parentheses
\renewbibmacro*{issue+date}{%
\setunit*{\addcomma\space}%
\iffieldundef{issue}
{\usebibmacro{date}}
{\printfield{issue}%
\setunit*{\addspace}%
\usebibmacro{date}}%
\newunit}
% comma after journal
\renewbibmacro*{journal+issuetitle}{%
\usebibmacro{journal}%
\setunit*{\addcomma\space}%
\iffieldundef{series}
{}
{\newunit
\printfield{series}%
\setunit{\addspace}}%
\usebibmacro{volume+number+eid}%
\setunit{\addspace}%
\usebibmacro{issue+date}%
\setunit{\addcolon\space}%
\usebibmacro{issue}%
\newunit}
\usepackage{filecontents}
\begin{filecontents}{sample.bib}
#article{einstein,
author = {Albert Einstein},
title = {On the electrodynamics of moving bodies},
journal = {Annalen der Physik},
volume = {322},
number = {10},
pages = {891--921},
year = {1905},
DOI = {http://dx.doi.org/10.1002/andp.19053221004}
}
#article{test,
author = {Example, Author},
journal = {Journal},
pages = {2},
title = {{Test paper}},
volume = {5},
year = {2018}
}
\end{filecontents}
\addbibresource{sample.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}
Currently the code output looks like this:
I have attempted to adapt the code from this question asking about changing separator when no volume number is present (https://tex.stackexchange.com/questions/199301/change-separator-for-articles-in-journals-without-volume-number-biblatex), for issue number:
\renewcommand*{\bibpagespunct}{%
\ifentrytype{article}{%
\iffieldundef{number}
{\addcomma\space}}
{\space}}
However this removes the space and comma from between the year and page range, when there is an issue number present, not what I intended at all. Please can someone help to show me where I'm going wrong.
I dealt with this issue by inserting the code below in \DeclareBibliographyDriver.
\iffieldundef{number}
{\addcomma\space}
{\printfield{number}\addcomma\space}
Here's my code chunk.
\DeclareBibliographyDriver{article}{%
\printnames{author}%
\printfield{year}%
\printfield{title}%
\usebibmacro{journal}%
% \usebibmacro{volume+number+eid}%
\printfield{volume}%
\iffieldundef{number}
{\addcomma\space}
{\printfield{number}\adddot\space}%
\iffieldundef{pages}
{}
{\printfield{pages}\adddot}%
Though the reference format could be different, you may get the main idea that I try to deliver here.

get the name of a png image using glob and rsplit

l have a set of images as follow :
1234_hello_BV56.png
1256_how_5t.png
l want to store in variable
labels only the names between '_'
to get hello , how
rest_left 1234 1256
rest right BV56 5t
to sum up.
for input like :
1234_hello_BV56.png
l want to get the following :
label=hello
rest_left=1234
rest_right=BV56
to do so l tried the following
import os
import glob
os.chdir(path)
images_name = glob.glob("*.png")
first try
set_img = set([x.rsplit('.', 1)[0] for x in images_name])
it only separte the whole world from png extenxion.
second try
label,sep,rest = img.partition('_')
It returns the first sequence before the firts '_'
UPDATE:
In [304]: left,labels,right = list(zip(*[os.path.splitext(x)[0].split('_')
for x in images_name]))
In [305]: left
Out[305]: ('1234', '1256')
In [306]: labels
Out[306]: ('hello', 'how')
In [307]: right
Out[307]: ('BV56', '5t')
Is that what you want?
In [266]: [os.path.splitext(x)[0].split('_') for x in images_name]
Out[266]: [['1234', 'hello', 'BV56'], ['1256', 'how', '5t']]

Resources