如何在神经网络中进行预测

时间:2019-03-20 11:11:19

标签: python

import numpy
import pandas
from keras.models import Sequential
from keras.layers import Dense
from sklearn.model_selection import train_test_split
from keras.utils import to_categorical

seed = 7
numpy.random.seed(seed)

# load dataset
dataframe = pandas.read_csv("final3.csv", header=None)
dataset = dataframe.values
X = dataset[:,0:18].astype(float)
y = dataset[:,18]

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2)

y_train=to_categorical(y_train)

classifier = Sequential()

classifier.add(Dense(output_dim = 73, init = 'uniform', activation = 'relu', input_dim = 18))

# Adding the second hidden layer
classifier.add(Dense(output_dim = 73, init = 'uniform', activation = 'relu'))

# Adding the output layer
classifier.add(Dense(output_dim = 73, init = 'uniform', activation = 'softmax'))

classifier.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])
classifier.fit(X_train, y_train, batch_size = 10, nb_epoch = 100)

y_pred = classifier.predict(X_test)
for x in y_pred:
    print (x)

我是这个主题的初学者。我有一个具有19个属性的肺癌数据集。所以我想预测一个人的生存时间。我正在尝试将神经网络用于模型。 这是我的代码。

一个人的生存时间是0-72。如何获得该范围内的y_pred。  截至目前,我正在获得一些矩阵表示形式。

[8.1076198e-15 2.1752844e-07 1.2116939e-18 2.2164159e-22 2.1026603e-06
 1.1625484e-05 6.4985651e-17 2.7821238e-19 2.4724517e-20 6.0318651e-12
 1.2854917e-03 1.8061271e-06 6.9042238e-07 5.7772754e-06 6.3506137e-05
 3.4657905e-03 7.6215866e-07 2.7154427e-04 2.0109048e-06 1.3515872e-11
 2.7319905e-03 1.1659093e-05 1.1084479e-06 3.4230333e-04 3.5688649e-03
 2.2175759e-03 1.3357633e-05 3.7133626e-11 6.6150656e-05 1.9602858e-06
 1.1181506e-02 3.7597970e-04 4.9837556e-04 8.7732850e-03 2.5213100e-07
 8.7331986e-04 1.0708974e-03 7.4109353e-06 1.7505368e-04 3.9368188e-06
 3.6851268e-03 1.9282685e-11 2.3971820e-09 1.4750658e-06 9.2430230e-07
 1.4479089e-03 1.6479607e-04 6.5444959e-15 5.1561245e-18 4.0108759e-08
 1.2547714e-03 1.1421996e-03 6.0796126e-05 4.9373681e-23 9.5109266e-01
 8.8011773e-05 6.2360095e-10 5.9956907e-11 5.9003787e-07 7.4055649e-23
 2.4946805e-03 9.6322630e-11 6.3566491e-04 4.6133799e-09 2.5459423e-10
 1.6766739e-07 1.6400527e-06 3.5425226e-16 3.9261676e-32 1.6697645e-07
 5.6991610e-07 0.0000000e+00 9.0164162e-04]
[4.33608965e-12 3.16980426e-12 1.00267485e-11 1.68937234e-07
 3.18754769e-06 9.92572513e-09 1.20364333e-04 5.71365354e-06
 6.23308682e-10 4.95779423e-05 1.02923324e-04 9.98276050e-07
 9.60526377e-05 1.39693857e-05 1.99723872e-04 3.17964191e-03
 4.71031990e-06 4.05619014e-03 1.35156428e-04 6.98588614e-04
 1.18990764e-02 9.69259854e-05 1.46262479e-04 2.47652730e-04
 1.41658937e-04 6.53229235e-03 1.53404020e-04 1.27383410e-05
 5.59120905e-03 2.92025584e-06 2.05165315e-02 1.02565391e-04
 3.98925040e-04 6.48222021e-06 1.93790253e-02 1.50724631e-02
 3.16178496e-03 6.43418971e-05 6.45780843e-03 2.76276842e-04
 1.16771096e-02 2.78767984e-05 9.57166776e-04 9.55161977e-06
 4.02998598e-03 1.40831736e-03 1.16105150e-06 1.28482679e-05
 7.09281885e-05 5.14031683e-07 3.94947315e-03 9.18762700e-04
 2.31896853e-03 1.85194767e-05 8.58246803e-01 5.44271013e-03
 1.47769799e-06 5.26645104e-04 5.19547379e-04 4.31537842e-07
 8.64023343e-03 5.74496953e-05 8.08321056e-06 7.52666756e-06
 1.98339012e-06 3.75410891e-04 2.63909060e-05 5.08954516e-04
 4.92676190e-05 3.67355191e-09 1.24913652e-03 9.19174425e-09
 9.44355452e-06]
[9.73713332e-11 1.10860163e-14 1.94811314e-08 6.14299056e-09
 3.81643304e-06 7.71928577e-10 1.09355629e-03 1.06944317e-05
 1.05287950e-06 2.56946009e-06 4.58806957e-04 1.02869561e-03
 3.95106690e-05 1.14625627e-02 3.71160777e-03 6.90539693e-03
 1.49961736e-04 3.75008181e-04 2.40107579e-03 1.10256942e-02
 3.47818621e-02 3.37915285e-03 1.23079251e-02 2.54004239e-03
 1.61548948e-03 1.57298911e-02 4.62849252e-03 2.68345163e-03
 1.03959450e-02 4.30977391e-03 6.03347681e-02 2.02372298e-03
 8.67683161e-03 1.37493573e-02 6.29806751e-03 1.48504535e-02
 5.29492798e-04 8.92097689e-03 3.02122324e-03 1.09122215e-04
 3.96188274e-02 7.61246821e-03 1.18041141e-02 2.20895489e-03
 1.17744040e-02 1.63615849e-02 4.50621406e-03 2.07688613e-03
 2.17335229e-03 1.37577381e-03 6.80648312e-02 7.41731003e-03
 1.86443515e-02 1.64038930e-02 3.73085529e-01 1.07638007e-02
 1.12535944e-02 9.89635126e-04 2.00720076e-02 1.18810183e-03
 6.02990016e-02 2.57048011e-03 2.44568149e-03 1.96947344e-03
 1.45068234e-02 3.39133036e-03 2.42005428e-03 1.18055493e-02
 5.23605093e-04 1.22581363e-11 1.68011412e-02 2.49487930e-03
 3.82022583e-03]
[7.43797073e-37 1.08214048e-35 2.08062408e-12 4.25696925e-07
 2.58710777e-08 5.08816073e-24 7.01459385e-07 4.49194978e-12
 1.90777840e-07 3.31867445e-09 1.20925215e-05 4.78463760e-03
 3.41897930e-07 6.30243681e-03 3.12893116e-03 1.77688822e-02
 4.90818093e-06 3.16275691e-04 1.70838479e-02 5.57247840e-04
 7.82908350e-02 3.94550478e-03 3.54342256e-03 3.20168561e-03
 8.89747310e-03 7.76385963e-02 1.74675439e-03 3.59780081e-02
 4.14049253e-02 1.72326807e-03 5.40142283e-02 1.75323745e-03
 2.88114622e-02 1.71747990e-04 1.22198067e-03 1.03585295e-01
 1.09794863e-04 4.45282822e-05 1.72164198e-02 1.21010675e-11
 4.23548929e-02 1.00030775e-04 7.10245362e-03 2.74919032e-04
 3.77670790e-06 8.29059780e-02 2.23109993e-04 8.09290024e-10
 8.19333991e-07 5.28040061e-07 9.46221501e-03 1.02306933e-06
 3.88582416e-10 2.06080964e-03 2.66902715e-01 1.00854663e-02
 2.52366066e-02 8.96069978e-05 5.42581198e-04 1.18298658e-06
 2.46157981e-02 2.83151574e-04 1.08961343e-12 5.23443337e-11
 2.81378703e-07 3.21599795e-03 5.95564771e-08 1.07070423e-06
 3.19943670e-13 3.77134307e-26 1.12747606e-02 2.19513574e-11
 8.20148145e-08] 

或者我还应该在代码中更改

0 个答案:

没有答案