我有一个皮肤病学数据库,其标准化已经完成。这是一个CSV文件。我需要打开文件并输入一个numpy数组。我的数据库有34列,大约350行。我的神经网络有3个隐藏层。这是我目前神经网络的python代码。有人可以帮助我在numpy数组/矩阵中输入吗? 谢谢
这是我的代码:
import numpy as np
#input x
X = np.array([ ])
#input y
y = np.array([]).T
syn0 = 2*np.random.random((34,26)) - 1
syn1 = 2*np.random.random((26,18)) - 1
syn2 = 2*np.random.random((18,11)) - 1
syn3 = 2*np.random.random((11,6)) - 1
for j in xrange(350):
l1 = 1/(1+np.exp(-(np.dot(X,syn0))))
l2 = 1/(1+np.exp(-(np.dot(l1,syn1))))
l3 = 1/(1+np.exp(-(np.dot(l2,syn2))))
l4 = 1/(1+np.exp(-(np.dot(l3,syn3))))
l4_delta = (y - l4)*(l4*(1-l4))
l3_delta = l4_delta.dot(syn3.T) * (l3 * (1-l3))
l2_delta = l3_delta.dot(syn2.T) * (l2 * (1-l2))
l1_delta = l2_delta.dot(syn1.T) * (l1 * (1-l1))
syn3 += l1.T.dot(l4_delta)
syn2 += l1.T.dot(l3_delta)
syn1 += l1.T.dot(l2_delta)
syn0 += X.T.dot(l1_delta)
答案 0 :(得分:0)
假设标签位于最后一列,
angular.module('monopolyApp')
.controller('MainCtrl', function ($scope, $window, $timeout, localStorageService) {
我认为你不需要转换X = np.array([[float(cell) for cell in row[:-1]] for row in csv.reader(open(csv_filename))])
Y = np.array([float(row[-1]) for row in csv.reader(open(csv_filename))])
,假设它是一维的。
答案 1 :(得分:0)
我这样做了:
my_5_input_numbers.csv
0.3,0.5,0.6,0.7,1
0.4,0.6,0.7,0.8,0
0.5,0.7,0.8,0.9,1
使用numpy:
data_common=np.genfromtxt('my_5_input_numbers.csv',delimiter=',')
"""
data_common=array([[ 0.3, 0.5, 0.6, 0.7, 1. ],
[ 0.4, 0.6, 0.7, 0.8, 0. ],
[ 0.5, 0.7, 0.8, 0.9, 1. ]])
data_common.shape=(3,5)
"""
X_train=data_common[:,-1]#X_train.shape=(3,4)
y_train=data_common[0:4,-1]#y_train.shape=(3,)
y_train=y_train.reshape(3,1)