[SOLVED] CS代考计算机代写 matlab import numpy as np

30 $

File Name: CS代考计算机代写_matlab_import_numpy_as_np.zip
File Size: 461.58 KB

SKU: 9697891572 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


import numpy as np
import math
import random

# this script is used to generate a set of random data points for classification problems.

def getDataSet():
“””
Returns X (250 X 2) and Y (250 X 1)
“””
# Step 1: Generate data by a module
n = 100# 1st class contains N objects
alpha = 1.5# 2st class contains alpha*N ones
sig2 = 1# assume 2nd class has the same variance as the 1st
dist2 = 4

# later we move this piece of code in a separate file
# [X, y] = loadModelData(N, alpha, sig2, dist2);
n2 = math.floor(alpha * n)# calculate the size of the 2nd class
cls1X = np.random.randn(n, 2)# generate random objects of the 1st class

# generate a random distance from the center of the 1st class to the center of the 2nd
# https://stackoverflow.com/questions/1721802/what-is-the-equivalent-of-matlabs-repmat-in-numpy
a = np.array([[math.sin(math.pi * random.random()), math.cos(math.pi * random.random())]])
a1 = a * dist2
shiftClass2 = np.kron(np.ones((n2, 1)), a1)

# generate random objects of the 2nd class
cls2X = sig2 * np.random.randn(n2, 2) + shiftClass2
# combine the objects
X = np.concatenate((cls1X, cls2X), axis=0)

# assign class labels: 0s and 1s
y = np.concatenate((np.zeros((cls1X.shape[0], 1)), np.ones((cls2X.shape[0], 1))), axis=0)
# end % of module.
return X, y

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS代考计算机代写 matlab import numpy as np
30 $