Assuming your original data is given in the form (initial columns have the values for inputs(x) and the last columns have the output(y) ).
Which is data[:,:-1] = Your x values
and
data[:,-1:] = Your y values
Solution in python.
#Part a of the answer
#Making dataTR and dataTS
dataTR = np.zeros((1000,5),'double')
dataTS = np.zeros((372,5),'double')
#Assigning Respective Values
dataTR[0:500,:] = data[0:500,:]
dataTR[500:1000,:] = data[872:1372,:]
dataTS[0:372,:] = data[500:872,:]
#Part b and c of the answer
#The questions wants you to split your newly created DataTR and
DataTS into
#x_tr and x_ts.
#Part b
#Making X_tr and X_ts
X_tr = np.zeros((1000,5),'double')
X_ts = np.zeros((372,5),'double')
#Initiallizing X_tr and X_ts
#You want the first column to be a ones and rest input x.
#You will notice the last column is not taken from the dataTR
because
# this column contains output values y.
X_tr[:,1:] = dataTR[:,:-1]
X_tr[:,0] = numpy.ones(1000,'double')
X_ts[:,1:] = dataTS[:,:-1]
X_ts[:,0] = numpy.ones(372,'double')
#Part c
#Making y_tr and y_ts
#This has 1-d array because the output has a single column.
y_tr = np.zeros((1000),'double')
y_ts = np.zeros((372),'double')
#Initiallizing y_tr and y_ts
#Here, the last column is taken into account because it has
outputs.
#Using notation of -1.
y_tr[:] = dataTR[:,-1]
y_ts[:] = dataTS[:,-1]
Screenshot of Solution:
![import numpy # Creating a random dataset just for the purpose of illustrating datanumpy.random.rand (1372, 5) #Part a of the answe #Making dataTR and dataTS dataTR np. zeros (( 1000,5), double) dataTSnp.zeros ( (372,5), double) #Assigning Respective Values dataTR[0:500,:] - data [0:500,:] dataTR [ 500: 1000,:] = data [872: 1372,:] dataTS [0:372,:] - data [500:872,:] #Part b and c of the answer #The questions wants you to split your newly created DataTR and DataTS into #x tr and xts - #Part b aking Xtr and X ts X trnp.zeros ((1000,5), double) X tsnp.zeros ( (372,5), double) #Initiallizing Xtr and X-ts #You want the first column to be a ones and rest input x #You will notice the last column is not taken from the dataTR because # this column contains output values y x tr[:,0]numpy.ones (1000, double) X ts [ : , 1: ] = dataTS [ : , :-1] xt s [ : , Э] -numpy . ones ( 372, double ) #Pa rt c #Making ytr and yts #This has 1-d array because the output has a single column y trnp.zeros ((1000),double y tsnp.zeros ( (372), double) #Initiallizing y_tr and y_ts #Here, the last column is taken into account because it has outputs #Using notation of -1](http://img.homeworklib.com/questions/a67d9500-86c3-11eb-a3ca-df6d6200499c.png?x-oss-process=image/resize,w_560)
Outputs:
Confirming X_ts is in correct shape.
I hope this satisfies
you.Thanks for using Chegg.
Need help completing code. (In python) Problem 2. Prepare the data for the lab In this...
Need help with MATLAB, what code should be added to
print the graph of the trapezoid rule code below?
%%Matlab code for Question 5. syms X y intlx exp(x),0,2); %integration of x*exp(x) fprintf("htlntegration of x"2*exp(x) for [O 3] is %2.5f.\n,y) %Integration using Trapizoidal rule nn [100 1000]; for ii 1:2 a:0; b-3; %Integration limit ns-1:nn(i) integral Values-zeros(size(ns)); ourFunction-@(x) x.*2.*exp(x); for n-ns val(n)-trapizoidal (ourFunction,a,b,nn(i); end fprintf nlntegration of x 2*exp(x) using Trapizoidal rule for [O 3]\n') fprintf('1tTrapizoidal integration value for n-%d...
C++ Can someone please help with this code... even when the players number isnt a winning number the program always says the player wins: #include <stdio.h> #include <time.h> //main function int main() { //seeding a random number srand(time(0)); //define the arrays for the wagered, winning amount, percent amount double amounts[7] = { 1, 5, 10, 20, 50, 100, 1000 }; double payoff[7] = { 100, 500, 1000, 2000, 5000, 10000, 100000 }; double percent[7] = { 0.01, 0.05, 1, 2,...
I need help in Python. This is a two step problem So I have the code down, but I am missing some requirements that I am stuck on. Also, I need help verifying the problem is correct.:) 7. Random Number File Writer Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 500. The application should let the user specify how many random numbers the file...
I need help with the following code... Instructions: This lab builds on the skills from Lab 2c, in which you read data values from a file and kept a count of the number of invalid values. In this lab, your program will be using the same code to read each data entry from the file, but you will also save each value in an array named allMags after each is read in. When all values in the file have been...
Python, given a code in class i just need help with the third
bullet point ; using a and n (defined in the second picture of
python code) find the first digit for k! for k =1,...,n. you dont
have to type in all this code just help me write the code in the
first picture where it says: def benford(a):
b = [0 for d in range(1,10)]
#Do everthything in here
return b
2.2 Generating data In this assignment...
I need help with this Java problem, please. Code must be written in Java Create an application that calculates batting statistics for baseball players. Console Welcome to the Batting Average Calculator Enter number of times at bat: 5 0 = out, 1 = single, 2 = double, 3 = triple, 4 = home run Result for at-bat 1: 0 Result for at-bat 2: 1 Result for at-bat 3: 0 Result for at-bat 4: 2 Result for at-bat 5: 3 Batting...
Hello, I want to check if my C++ code is correct and follows the
requeriments described thanks.
Requeriments:
Assignment Sorting
Benchmark each of the sorting methods listed below.
Insertion Sort
Bubble Sort
Selection Sort
Heap Sort.
Quick Sort.
Merge Sort.
Benchmark each of the above sorting methods for data sizes of
10000, 20000, 30000, 40000 and 50000. Display the results in a
table as shown below. The table should have rows and columns.
However, the rows and columns need not...
I need a python 3 help Question 2: Putting it all together. For this problem, you are going to be working with real data taken from the UCSD library system. You must Regex in this question in order to get credit. 1. Create a pattern to find all books that have a year of N. Note that years are displayed as either N or cN. If a book has both, count them as one occurrence of a book. def year_match(string,...
Input hello, I need help completing my assignment for java,Use the following test data for input and fill in missing code, and please screenshot output. 1, John Adam, 3, 93, 91, 100, Letter 2, Raymond Woo, 3, 65, 68, 63, Letter 3, Rick Smith, 3, 50, 58, 53, Letter 4, Ray Bartlett, 3, 62, 64, 69, Letter 5, Mary Russell, 3, 93, 90, 98, Letter 6, Andy Wong, 3, 89,88,84, Letter 7, Jay Russell, 3, 71,73,78, Letter 8, Jimmie Wong,...
Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...