Question

This is my code: import numpy as np import pandas as pd import sys from keras.models...

This is my code:

import numpy as np
import pandas as pd
import sys
from keras.models import Sequential
from keras.layers import Dense
from sklearn.preprocessing import StandardScaler
from keras.layers.normalization import BatchNormalization
from keras.layers import Dropout

file_full=pd.read_csv("/Users/anwer/Desktop/copy/FULL.csv")
file_bottom=pd.read_csv("/Users/anwer/Desktop/copy/bottom.csv")
train=[]
train_targets=[]
test=[]
test_targets=[]
p=[]
q=[]


  
# We will generate train data using 50% of full data and 50% of bottom data.
#is train target for labeling ? yes for train data
train_df = file_full[:len(file_full)//2]

labels=[ 0 for i in range(len(file_full)//2)]

train_df=train_df.append(file_bottom[:len(file_bottom)//2])

for i in range(len(file_bottom)//2):

labels.append(1)

train_df['label']=labels

train = train_df.drop('label',axis=1)

train_label= train_df['label']
  
  
test_df = file_full[len(file_full)//2:len(file_full)]

labels2=[ 0 for i in range(len(file_full)//2)]

test_df=test_df.append(file_bottom[len(file_bottom)//2:len(file_bottom)])

for i in range(len(file_bottom)//2):

labels2.append(1)

test_df['label']=labels2

test = test_df.drop('label',axis=1)

test_label= test_df['label']
# Training Model

#can you comment those lines? I want to know what they do?
#train = np.array(train).reshape(-1,1)
scaler = StandardScaler().fit(train)

train=scaler.transform(train)
test=scaler.transform(test)

# Creating Deep Model


model = Sequential()

# Add an input layer
model.add(Dense(12, activation='relu', input_shape=(211,)))

# Add one hidden layer
model.add(Dense(8, activation='relu'))

# Add an output layer
model.add(Dense(1, activation='sigmoid'))

#add improvements
model.add(BatchNormalization())
model.add(Dropout(0.5))
#Train the model

model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])

model.fit(train,train_targets,epochs=20, batch_size=1, verbose=1)

#TEst the model

y_pred = model.predict(test)


# Evaluate the model


score = model.evaluate(test, test_targets,verbose=1)

print(score)

ERROR:

I am getting error at this line:

model.fit(train,train_targets,epochs=20, batch_size=1, verbose=1)

the error is :


File "C:\Users\bob\Anaconda3\lib\site-packages\keras\engine\training_utils.py", line 80, in standardize_input_data
if isinstance(data[0], list):

IndexError: list index out of range.

what is caussing this error and how can I fix it?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

in file : C:\Users\bob\Anaconda3\lib\site-packages\keras\engine\training_utils.py

list is one kind of array type so that we can not use it as a list only. it should be something like list[i]. or else.

in isinstance, we should provide int in the second argument. so that there should be integer not list.

try : if isinstance(data[0], list[0]).

Add a comment
Know the answer?
Add Answer to:
This is my code: import numpy as np import pandas as pd import sys from keras.models...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PYTHON import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.linear_model import...

    PYTHON import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression from sklearn.linear_model import LogisticRegression from sklearn.model_selection import train_test_split Our goal is to create a linear regression model to estimate values of ln_price using ln_carat as the only feature. We will now prepare the feature and label arrays. "carat"   "cut" "color"   "clarity"   "depth"   "table"   "price"   "x"   "y"   "z" "1" 0.23   "Ideal" "E" "SI2" 61.5 55 326   3.95   3.98   2.43 "2" 0.21   "Premium" "E" "SI1"...

  • Can someone please just run this on their system and post the screenshot so I can...

    Can someone please just run this on their system and post the screenshot so I can know it works. The .csv file and program are given below, please just run it and provide the screenshot. Also, I am using 3.6 Python in Pycharm. Thanks! Bank_Predictions.csv use a portion of the dataset Bank_Predictions which I have provided below (it is only 10 lines because the actual file has over 1000 lines so here is a small snippet); Number Customer_ID Last_Name Cr_Score...

  • Python...I don't know what is wrong with my code: import numpy as np from mpi4py import...

    Python...I don't know what is wrong with my code: import numpy as np from mpi4py import MPI array= [14,175, 15,055, 16,616, 17,495, 18,072, 19,390] array1,array2= array[ : :2], array[1: :2] print (array1) print (array2) /////it should print array1 = [1,4175, 16,616,18,072] array2= [15,055, 17,495, 19,390]

  • I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label;...

    I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label; import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Fall_2017 {    public TextArea courseInput;    public Label textAreaLabel;    public JButton addData;    public Dialog confirmDialog;    HashMap<Integer, ArrayList<String>> students;    public Fall_2017(){    courseInput = new TextArea(20, 40);    textAreaLabel = new Label("Student's data:");    addData = new JButton("Add...

  • PYTHON QUESTION... Building a Binary Tree with extended Binary Search Tree and AVL tree. Create a...

    PYTHON QUESTION... Building a Binary Tree with extended Binary Search Tree and AVL tree. Create a class called MyTree with the methods __init__(x), getLeft(), getRight(), getData(), insert(x) and getHeight(). Each child should itself be a MyTree object. The height of a leaf node should be zero. The insert(x) method should return the node that occupies the original node's position in the tree. Create a class called MyBST that extends MyTree. Override the method insert(x) to meet the definitions of a...

  • Using a sort method and my previous code (put inside of addHours method if possible), how...

    Using a sort method and my previous code (put inside of addHours method if possible), how would I get the list of each employee's total hours to display in order of least amount of hours to greatest. An explanation for each step would also be great. import random #Create function addHours def addHours(lst): #Display added hours of employees print("\nEmployee# Weekly Hours") print("----------------------------") print(" 1 ",sum(lst[0])) print(" 2 ",sum(lst[1])) print(" 3 ",sum(lst[2])) #Create main function def main(): #Create first empty list...

  • I need help finding the error in my code for my Fill in the Blank (Making a Player Class) in C++. Everything looks good...

    I need help finding the error in my code for my Fill in the Blank (Making a Player Class) in C++. Everything looks good to me but it will not run. Please help... due in 24 hr. Problem As you write in your code, be sure to use appropriate comments to describe your work. After you have finished, test the code by compiling it and running the program, then turn in your finished source code. Currently, there is a test...

  • Solve the code below: CODE: """ Code for handling sessions in our web application """ from bottle import request, response import uuid import json import model import dbsche...

    Solve the code below: CODE: """ Code for handling sessions in our web application """ from bottle import request, response import uuid import json import model import dbschema COOKIE_NAME = 'session' def get_or_create_session(db): """Get the current sessionid either from a cookie in the current request or by creating a new session if none are present. If a new session is created, a cookie is set in the response. Returns the session key (string) """ def add_to_cart(db, itemid, quantity): """Add an...

  • this is my code to predict a housing price based on data but i get a...

    this is my code to predict a housing price based on data but i get a lot errors, how do i resolve all these errors 9]: import seaborn as sns from sklearn.linear model import LinearRegression 20]: import numpy as np import matplotlib.pyplot as plt %matplotlib inline import pandas as pd data- pd.read_csv('C:\\Users \\Downloads \\house-prices -advanced-regression-techniques\\test.csv) I data 20]: ScreenPorch PoolArea PoolQC Fence Id MSSubClass MSZoning LotFrontage LotArea Street Alley LotShape LandContour Utilities NaN MnPry 120 Lvl AlPub Pave NaN Reg...

  • Use the csv file on spotify from any date Code from lab2 import java.io.File; import java.io.FileNotFoundException;...

    Use the csv file on spotify from any date Code from lab2 import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class SongsReport {    public static void main(String[] args) {               //loading name of file        File file = new File("songs.csv"); //reading data from this file        //scanner to read java file        Scanner reader;        //line to get current line from the file        String line="";       ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT