MachineLearning - Age prediction part 3

Bomin Seo·2022년 8월 23일
0

test -set

preprocessing

df2 = pd.read_csv("IXI_test.csv")
mant = df2[df2['Sex'].values == 1]
y_mant = mant.Age
X_mant = mant.drop(['ID', 'Age','Sex','ICV'], axis = 1)

womant = df2[df2['Sex'].values == 2]
y_womant = womant.Age
X_womant = womant.drop(['ID', 'Age','Sex','ICV'], axis = 1)
x_mant = std.fit_transform(X_mant)
x_womant = std.fit_transform(X_womant)

best model

regt = linear_model.Lasso(max_iter = 10000, random_state = 1, alpha = 0.33)
regt = regt.fit(x_man_train, y_man_train)
y_man_pred = regt.predict(x_mant)
y_man_pred

regt = GradientBoostingRegressor(random_state=0, n_estimators = 81).fit(x_woman_train,y_woman_train)
y_woman_pred = regt.predict(x_womant)
y_woman_pred

test = df2[df2['Sex'].values == 1].to_numpy()
test[:,2] = y_man_pred

test2 = df2[df2['Sex'].values == 2].to_numpy()
test2[:,2] = y_woman_pred

ID값을 남겨 EXCEL파일 오름차순 정렬

test3 = np.concatenate((test,test2),axis = 0)
test3 = test3[:,(0,2)]

test3 = pd.DataFrame(test3)
test3.to_csv("lXl_test3.csv", mode='w')

df3 = pd.read_csv("COBRE_test_scz.csv")
df3['ICV'] = df3['ICV'] / 1000
mant2 = df3[df3['Sex'].values == 1]
womant2 = df3[df3['Sex'].values == 2]

name = pd.read_excel("anatomical_regions.xlsx")
name = name.drop(['Index', 'Unnamed: 2'], axis = 1)
name = name.iloc[:68,:]

ATTRIBUTE NAME 수정

womant2 = womant2.reindex(columns=name['Region.1'].values)
i = 0
dic = {}
for i in range(68):
    dic[name['Region.1'][i]] = name['Region'][i]
    i += 1
womant2.rename(columns = dic)

mant2 = mant2.reindex(columns=name['Region.1'].values)
i = 0
dic = {}
for i in range(68):
    dic[name['Region.1'][i]] = name['Region'][i]
    i += 1
mant2.rename(columns = dic)

PREDICT

x_mant2 = std.fit_transform(mant2)
x_womant2 = std.fit_transform(womant2)

regt = linear_model.Lasso(max_iter = 10000, random_state = 1, alpha = 0.33).fit(x_man_train,y_man_train)
y_man_pred2 = regt.predict(x_mant2)
y_man_pred2

regt = GradientBoostingRegressor(random_state=0, n_estimators = 81).fit(x_woman_train,y_woman_train)
y_woman_pred2 = regt.predict(x_womant2)
y_woman_pred2

Cobre test set

cobre = df3[df3['Sex'].values == 1]
cobre = cobre.iloc[:,:2]
cobre = cobre.to_numpy()
cobre[:,1] = y_man_pred2

cobre2 = df3[df3['Sex'].values == 2]
cobre2 = cobre2.iloc[:,:2]
cobre2 = cobre2.to_numpy()
cobre2[:,1] = y_woman_pred2

cobre3 = np.concatenate((cobre,cobre2),axis = 0)
cobre3 = pd.DataFrame(cobre3)
cobre3

cobre3.to_csv("cobre_test0.csv", mode='w')
profile
KHU, SWCON

0개의 댓글