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:
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...
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 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...
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,...
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...
Need C++ coding for this lab exercise given below :) 4. Lab Exercise — Templates Exercise 1 - Function Templating For this part of the lab make a template out of the myMax function and test it on different data types. Copy maxTemplate.cpp to your Hercules account space. Do that by: Entering the command:cp /net/data/ftp/pub/class/115/ftp/cpp/Templates/maxTemplate.cpp maxTemplate.cpp Compile and run the program to see how it works. Make a template out of myMax. Don't forget the return type. Modify the prototype appropriately. Test your myMax template on int, double,...
Assignment Predator / Prey Objectives Reading from and writing to text files Implementing mathematical formulas in C++ Implementing classes Using vectors Using command line arguments Modifying previously written code Tasks For this project, you will implement a simulation for predicting the future populations for a group of animals that we’ll call prey and their predators. Given the rate at which prey births exceed natural deaths, the rate of predation, the rate at which predator deaths exceeds births without a food...
Please!!! need help asap!!!! write a C++program to analyze a small subset of the data that has been collected. See file universities.txt .Use precisely seven parallel arrays: one for name of university, one for state, one for city, one for yearly tuition, one for enrollment, one for average freshman retention, and one for the percent of students who graduate with in six years. Note that the percentage of student accepted is not stored.An output file is opened in main() and...
i
need help making this program
the skeleton of the code is below:
//Include the following
#include <iostream>
#include <string>
#include <fstream> //you must include this library if you wish to do file i/o
using namespace std;
/*********************************************************
//Following is the declaration of a order record
**********************************************************/
class order_record
{
public:
string cell_number;
string item_number;
double quantity;
double price;
int processing_plant;
double tax_rate;
double order_tax;
double net_cost;
double total_cost;
};
//Prototypes for your functions: input, output, and process will go...
could you please help me with this problem, also I
need a little text so I can understand how you solved the
problem?
import java.io.File; import java.util.Scanner; /** *
This program lists the files in a directory specified by * the
user. The user is asked to type in a directory name. * If the name
entered by the user is not a directory, a * message is printed and
the program ends. */ public class DirectoryList { public static...