Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.84 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. import tensorflow as tf
  4. from keras.models import Model, Sequential
  5. from keras.layers import Input, Activation, Dense
  6. from keras.optimizers import SGD
  7. from keras.utils.np_utils import to_categorical
  8.  
  9.  
  10. # Pandas read CSV
  11. sf_train = pd.read_csv('3Power.csv')
  12.  
  13. # Correlation Matrix for target
  14. #corr_matrix = sf_train.corr()
  15. #print(corr_matrix['type'])
  16.  
  17. # Drop unnecessary columns
  18. #sf_train.drop(sf_train.columns[[5, 12, 14, 21, 22, 23]], axis=1, inplace=True)
  19. #print(sf_train.head())
  20.  
  21. # Pandas read Validation CSV
  22. #sf_val = pd.read_csv('p5_val_data.csv')
  23.  
  24. # Drop unnecessary columns
  25. #sf_val.drop(sf_val.columns[[5, 12, 14, 21, 22, 23]], axis=1, inplace=True)
  26.  
  27. # Get Pandas array value (Convert to NumPy array)
  28. train_data = sf_train.values
  29. #val_data = sf_val.values
  30.  
  31. # Use columns 2 to last as Input
  32. train_x = train_data[:,2:]
  33. #val_x = val_data[:,2:]
  34.  
  35. # Use columns 1 as Output/Target (One-Hot Encoding)
  36. train_y = to_categorical( train_data[:,1])
  37. #val_y = to_categorical( val_data[:,1] )
  38.  
  39. # Create Network
  40. inputs = Input(shape=(1001,))
  41. h_layer = Dense(10, activation='sigmoid')(inputs)
  42.  
  43. # Softmax Activation for Multiclass Classification
  44. outputs = Dense(3, activation='softmax')(h_layer)
  45.  
  46. model = Model(inputs=inputs, outputs=outputs)
  47.  
  48. # Optimizer / Update Rule
  49. sgd = SGD(lr=0.001)
  50.  
  51. # Compile the model with Cross Entropy Loss
  52. model.compile(optimizer=sgd, loss='categorical_crossentropy', metrics=['accuracy'])
  53.  
  54. # Train the model and use validation data
  55. model.fit(train_x, train_y, batch_size=1001, epochs=5000, verbose=1)#, validation_data=(val_x, val_y))
  56. model.save('weights_power.h5')
  57.  
  58. # Predict all Validation data
  59. predict = model.predict([214])
  60.  
  61. # Visualize Prediction
  62. df = pd.DataFrame(predict)
  63. df.columns = [ 'Light', 'Steamer', 'Steamer' ]
  64. #df.index = val_data[:,0]
  65. print(df)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement