CoxModel

Struct CoxModel 

Source
pub struct CoxModel { /* private fields */ }
Expand description

cox model w/ elastic net regularization

Implementations§

Source§

impl CoxModel

Source

pub fn new() -> Self

new cox model w/ defaults

Source

pub fn with_l1_penalty(self, penalty: f64) -> Self

add lasso penalty (L1) - encourages sparsity

Source

pub fn with_l2_penalty(self, penalty: f64) -> Self

add ridge penalty (L2) - shrinks coefficients

Source

pub fn with_elastic_net(self, alpha: f64, penalty: f64) -> Self

elastic net mixing: alpha=0 -> pure ridge, alpha=1 -> pure lasso

Source

pub fn with_max_iterations(self, max_iter: usize) -> Self

max iterations before giving up

Source

pub fn with_tolerance(self, tol: f64) -> Self

how close is close enough for convergence

Source

pub fn with_feature_names(self, names: Vec<String>) -> Self

give names to your features for nicer output

Source

pub fn with_optimizer(self, optimizer: OptimizerType) -> Self

choose which optimizer to use

Source

pub fn with_learning_rate(self, lr: f64) -> Self

set learning rate for Adam/RMSprop optimizers

Source

pub fn with_adam_params(self, beta1: f64, beta2: f64) -> Self

set Adam/RMSprop parameters (beta1 for Adam momentum, beta2 for decay rate)

Source

pub fn with_epsilon(self, eps: f64) -> Self

set Adam/RMSprop numerical stability parameter

Source

pub fn fit(&mut self, data: &SurvivalData) -> Result<&mut Self>

fit the model to data - this does the actual work

Source

pub fn coefficients(&self) -> Result<ArrayView1<'_, f64>>

get the fitted coefficients (betas)

Source

pub fn predict(&self, covariates: ArrayView2<'_, f64>) -> Result<Array1<f64>>

predict risk scores for new patients

Source

pub fn predict_hazard_ratios( &self, covariates: ArrayView2<'_, f64>, ) -> Result<Array1<f64>>

predict hazard ratios (exp of risk scores)

Source

pub fn predict_survival( &self, covariates: ArrayView2<'_, f64>, times: ArrayView1<'_, f64>, ) -> Result<Array2<f64>>

predict survival probs at specific time points

Source

pub fn feature_importance(&self) -> Result<Array1<f64>>

feature importance = abs value of coefficients

Source

pub fn summary(&self) -> Result<CoxModelSummary>

get a nice summary of the fitted model

Source

pub fn is_fitted(&self) -> bool

has this model been fit to data yet?

Source

pub fn regularization_params(&self) -> (f64, f64)

what regularization penalties are we using?

Trait Implementations§

Source§

impl Clone for CoxModel

Source§

fn clone(&self) -> CoxModel

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CoxModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CoxModel

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.