mittyone
@mittyone (... ...)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

random survival forest

解決したいこと

random survival forestを実装したい

発生している問題・エラー

ValueError Traceback (most recent call last)
in
4 n_jobs=-1,
5 random_state=random_state)
----> 6 rsf.fit(X_train, y_train)

2 frames
/usr/local/lib/python3.8/dist-packages/sksurv/util.py in check_y_survival(y_or_event, allow_all_censored, *args)
130
131 if not isinstance(y, np.ndarray) or y.dtype.fields is None or len(y.dtype.fields) != 2:
--> 132 raise ValueError('y must be a structured array with the first field'
133 ' being a binary class event indicator and the second field'
134 ' the time of the event/censoring')

ValueError: y must be a structured array with the first field being a binary class event indicator and the second field the time of the event/censoring

該当するソースコード

python

y = df.loc[:, ["rec0", "DFS"]]
Xt = df.drop(["rec0", "DFS"], axis=1)

rec0が 0 1のbinary class event
DFSが  5.4 3.4 などの年を表す値をが入っています
これを
random_state = 20

X_train, X_test, y_train, y_test = train_test_split(
Xt, y, test_size=0.25, random_state=random_state)

にして

rsf = RandomSurvivalForest(n_estimators=1000,
min_samples_split=10,
min_samples_leaf=15,
n_jobs=-1,
random_state=random_state)
rsf.fit(X_train, y_train)
とするとfitのところでエラーが出ます

y.head()で見ると

rec0 DFS
0 1 6.376454
1 0 7.066393
2 0 6.475017
のようにbinary class event, the time of event or censoring
になっているのですが

どこが悪いかわかりません

自分で試したこと

順序の確認や欠損値の有無など
欠損値はありません

0

1Answer

https://scikit-survival.readthedocs.io/en/stable/user_guide/00-introduction.html#Survival-Data
上記のサイトにデータの説明があり、データの例があるので変更したらうまくいくと思います。

Status and Survival_in_days need to be stored as a structured array with the first field indicating whether the actual survival time was observed or if was censored, and the second field denoting the observed survival time, which corresponds to the time of death.

array([( True, 72.), ( True, 411.), ( True, 228.), ( True, 126.),
( True, 118.), ( True, 10.), ( True, 82.), ( True, 110.),
( True, 314.), (False, 100.), ( True, 42.), ( True, 8.),])

0Like

Comments

  1. @mittyone

    Questioner

    有力情報ありがとうございます
    ndarrayから
    tuples
    Structured array
    に変えて実装できました

Your answer might help someone💌